This repository is for all the work done on Cryptography as part of the Cambridge Programmer's Study Group.
- US Army Field Manual 34-40-2: Basic Cryptanalysis
- Classical Cryptography (Wikipedia)
- Cryptanalysis of ADFGVX cipher
- Practical Cryptography
- Block ciphers modes of operation
- The notes in the Libtomcrypt library contain test vectors, and many practical implementation guidelines. The Libtomcrypt code also seems to be beginner friendly.
- Clear explanation of the Padding Oracle Attack with examples
- Cryptopals challenges
- Thorough speed test of common crypto libraries Note well, this excludes the more recent NaCl and NSS.
The OpenSSL library will have all the functionality we might need during the challenges, especially if you're working in C/C++. The documentation is really poor though. Here are a couple of examples to get you started:
- Good example of use in a stackoverflow question. (note the code has an issue, but it's easily fixed.)
- Usage example from the official docs at the bottom of the page. Note that the cipher
EVP_aes_128_ecb()
is not documented but is available.
Using xxd
to convert a string to Hexadecimal. Note how we use echo
's -n
option to not print a newline at the end.
➤ echo -n "Hello" | xxd -p
48656c6c6f
Converting hex back to string (which will not include a newline):
➤ echo -n "48656c6c6f" | xxd -p -r
Hello
Same idea, but for base 64:
➤ echo -n "Hello" | base64
SGVsbG8=
➤ echo -n "SGVsbG8=" | base64 --decode
Hello
Let's set up our key and plaintext
➤ PLAINTEXT="YELLOWFIN TUNAS." # Exactly 16 characters (128 bits)
➤ KEY="YELLOW SUBMARINE" # Exactly 16 characters (128 bits)
➤ HEX_KEY=$(echo $KEY | xxd -p)
Then we can encrypt and decrypt using openssl. We'll need to tell openssl to not add a salt and to not pad our plaintext using the -nopad
and -nosalt
option. We'll use -aes-128-ecb
as a simple test.
➤ CIPHERTEXT=$(echo -n ${PLAINTEXT} | openssl enc -aes-128-ecb -nopad -nosalt -K ${HEX_KEY} )
➤ echo -n ${CIPHERTEXT} | openssl enc -d -aes-128-ecb -nopad -nosalt -K ${HEX_KEY}
YELLOWFIN TUNAS.
Using a file is just as easy:
➤ base64 --decode < secret-lyrics.txt | openssl enc -d -aes-128-ecb -nopad -nosalt -K $(echo -n "YELLOW SUBMARINE" | xxd -p)
I'm back and I'm ringin' the bell
[...many more lines...]
Play that funky music