cryptopals

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

commit 78ad2edf30c64255edf84e3f8ac6d08cc00b1c6c
parent 9867f7afe672e61231cc105469e38c63fbffecea
Author: Jared Tobin <jared@jtobin.ca>
Date:   Mon,  8 May 2017 10:29:31 +1200

Polish off set 1.

Diffstat:
MREADME.md | 17++++++++++++++++-
Mlib/chunks/Chunks.hs | 9++++++---
2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -153,7 +153,7 @@ Shift by 32 for readability: #### 1.7 -I use openssl less than I code, heck the rules: +I like openssl, heck the rules: $ KEY=$(echo -n 'YELLOW SUBMARINE' | xxd -p) $ openssl enc -aes-128-ecb \ @@ -162,3 +162,18 @@ I use openssl less than I code, heck the rules: I'm back and I'm ringin' the bell A rockin' on the mike while the fly girls yell +#### 1.8 + + $ cat data/s1/q8_input.txt | parallel \ + 'echo -n {} | ./bin/chunks 8 | printf "%.10s %u\n" {} \ + $(datamash countunique 1)' | awk '{ if ($2 < 20) { print }; }' + d880619740 14 + +So, the line starting with 'd880619740' - line 133. + +**Background**: + +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. + diff --git a/lib/chunks/Chunks.hs b/lib/chunks/Chunks.hs @@ -5,6 +5,7 @@ import Control.Error (readMay) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as B8 +import qualified Data.ByteString.Base16 as B16 import System.Environment import System.IO @@ -24,8 +25,10 @@ main = do (narg:_) -> case readMay narg :: Maybe Int of Nothing -> hPutStrLn stderr "chunks: invalid keysize" Just size -> do - bs <- B8.getContents - let chunked = chunks size (B8.filter (/= '\n') bs) - mapM_ B8.putStrLn chunked + hex <- B.getContents + let (bs, _) = B16.decode hex + chunked = chunks size bs + rehexed = fmap B16.encode chunked + mapM_ B8.putStrLn rehexed _ -> putStrLn "USAGE: echo FOO | ./chunks KEYSIZE"