cryptopals

Matasano's cryptopals challenges (cryptopals.com).
Log | Files | Refs | README | LICENSE

commit c609e27d8281fe502f7a4d8f394c501daa962944
parent 78ad2edf30c64255edf84e3f8ac6d08cc00b1c6c
Author: Jared Tobin <jared@jtobin.ca>
Date:   Tue,  9 May 2017 23:11:29 +1200

Add 2.1.

Diffstat:
MREADME.md | 10++++++++++
Alib/pkcs/PKCS.hs | 30++++++++++++++++++++++++++++++
Dout.txt | 1-
Dtest.out | 0
Dtest.txt | 1-
5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -177,3 +177,13 @@ ECB means electronic codebook, the simplest block cipher encryption mode. One divides a message into 16-byte chunks and then encrypts each chunk separately. The same 16 bytes will thus encrypt to the same output. +### Set 2 + +#### 2.1 + + $ echo -n 'YELLOW SUBMARINE' | ./bin/pkcs 20 | xxd + 00000000: 5945 4c4c 4f57 2053 5542 4d41 5249 4e45 YELLOW SUBMARINE + 00000010: 0404 0404 0a ..... + + + diff --git a/lib/pkcs/PKCS.hs b/lib/pkcs/PKCS.hs @@ -0,0 +1,30 @@ + +import Control.Error (readMay) +import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as B8 +import GHC.Word +import System.Environment +import System.IO + +main :: IO () +main = do + args <- getArgs + + case args of + (narg:_) -> case readMay narg :: Maybe Int of + Nothing -> hPutStrLn stderr "pkcs: invalid length" + Just padto -> do + bytes <- B.getContents + let len = B.length bytes + npad :: Word8 + npad = fromIntegral $ + if padto < len + then 0 + else padto - len + + padded = B.append bytes (B.replicate (fromIntegral npad) npad) + B8.putStrLn padded + + _ -> putStrLn "USAGE: echo STRING | ./pkcs LENGTH" + + diff --git a/out.txt b/out.txt @@ -1 +0,0 @@ -U2FsdGVkX1/IXdQ+LU0I8umZTye2KKljyOEWcxAjjUf7vUEq9dlBIUZPAwgziT7C diff --git a/test.out b/test.out Binary files differ. diff --git a/test.txt b/test.txt @@ -1 +0,0 @@ -here's some stuff