cryptopals

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

commit 0d1dcef0700764e8143ac6c8f7bd5eb0bd68d976
parent d0743de8b8cac73cc4a977b2d3a9b44a33caf37a
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat, 17 Nov 2018 22:47:13 +1300

Update docs.

Diffstat:
Mdocs/s1.md | 36+++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/docs/s1.md b/docs/s1.md @@ -5,12 +5,12 @@ We want to go from hex (i.e., base 16) to base64 (i.e., base.. uh, 64). So we'll change from the representation: - .. + a2 * 16^2 + a1 * 16^1 + a0 * 16^0 + .. + a2 * 16^2 + a1 * 16^1 + a0 * 16^0 for some (decimal-equivalent) coefficients {a0, a1, .. } in the alphabet 0-9a-f, to the representation: - .. + b2 * 64^2 + b1 * 64^1 + b0 * 64^0 + .. + b2 * 64^2 + b1 * 64^1 + b0 * 64^0 for other coefficients {b0, b1, .. } in the alphabet A-Za-z0-9\+/. @@ -27,40 +27,42 @@ equality: #### 1.2 - $ SOLUTION=$(./bin/fixed_xor $(< data/s1/q2_input.txt) $(< data/s1/q2_against.txt)) - 746865206b696420646f6e277420706c6179 - -ASCII-encoded output is fun: - - $ echo $SOLUTION | xxd -r -p - the kid don't play - -**Background**: - Fixed-xor just encrypts by XOR'ing every bit with some corresponding bit. -Example: +An example, using `xxd` to output bits this time: - echo -n 'FAB' | xxd -b && echo -n 'ICE' | xxd -b + $ parallel -k 'echo -n {} | xxd -b' ::: FAB ICE 00000000: 01000110 01000001 01000010 FAB 00000000: 01001001 01000011 01000101 ICE -So XOR-ing 'FAB' with 'ICE' can be done manually: +So XOR-ing 'FAB' with 'ICE' can be done manually -- one just computes the +bitwise XOR: 0100 0110 0100 0001 0100 0010 0100 1001 0100 0011 0100 0101 0000 1111 0000 0010 0000 0111 -So in hex that's '0f0207': +In hex that's '0f0207'; we can use `bc` to calculate it; note it's not +zero-padded: $ echo 'obase=16; ibase=2; 000011110000001000000111' | bc F0207 -You can play things back like so to confirm: +The `fixed_xor` binary in `./bin` will perform the reverse task here: $ ./bin/fixed_xor '0f0207' $(echo -n ICE | xxd -p) | xxd -r -p FAB +Running `fixed_xor` on the question input: + + $ SOLUTION=$(./bin/fixed_xor $(< data/s1/q2_input.txt) $(< data/s1/q2_against.txt)) + 746865206b696420646f6e277420706c6179 + +Note that the ASCII-encoded output is fun: + + $ echo $SOLUTION | xxd -r -p + the kid don't play + #### 1.3 Fun fact: it's easy to memorize the (approximate) ranking of the most commonly