Mission ideas: cryptography
Hi! I'd like to make a series of missions based on classical pen and paper cryptography.
1. Atbash cipher (difficulty - Elementary)
Exactly what it says on the tin. Encrypt a string using the Atbash cipher, keeping caps and punctuation:
assert atbash('Hello, world!') == 'Svool, dliow!'
2. Scytale cipher (Elementary)
You are given encrypted message and a crib (a short substring that is expected to be in the deciphered message). You need to decipher the message (by trying all possible keys) or return None if the crib is not in the message:
assert scytale_decipher('aaaatctwtkdn', 'dawn') == 'attackatdawn' assert scytale_decipher('aaaatctwtkdn', 'dusk') == None
3. Affine cipher (Elementary)
You have an encrypted message, a crib and altered crib. Decipher the message (by bruteforcing all possible keys), replace the crib with altered crib, and re-encrypt it using the same key. It's kinda similar to Scytale, but has some interesting modular arithmetic (and also can be made harder by changing the size of the alphabet). In the example below the encrypted message was "cryptography is boring", we altered it to "cryptography is pretty cool":
assert affine_decipher('xibkgltizksbrhylirmt', 'boring', 'prettycool') == 'xibkgltizksbrhkivggbxllo'
4. Turning grille (video) (Simple)
Encrypt a message using a turning cardan grille. The grille is represented as a 8x8 table with spaces where there are holes.
assert cardano_enc('Quick brown fox jumps over the lazy dog and \ jackdaws loves my sphinx of quartz', [' XXXX X', 'XXXXXX X', 'XXXXXX X', 'X X XX ', 'XXXXX X ', ' X X XXX', 'XX XXXXX', 'XXXXXX X']) == 'qapmyuissphioncnxvedojkacbkrrfowdatqwnsfolxhjuaelourazydtveogzms'
5. Playfair cipher (Simple+)
Encrypt a message using the Playfair cipher with given key (you'll need to generate key table first):
assert playfair('hellodearworld', 'aquarium') == 'lchzgtemqiqwikcy'
6. Turning grille key (Moderate)
Now on to harder ones. You are given plaintext and ciphertext, and need to find the key (the grille used to encrypt the plaintext):
assert cardano_key('quickbrownfoxjumpsoverthelazydogandjackdawslovesmysphinxofquartz', 'qapmyuissphioncnxvedojkacbkrrfowdatqwnsfolxhjuaelourazydtveogzms') == [' XXXX X', 'XXXXXX X', 'XXXXXX X', 'X X XX ', 'XXXXX X ', ' X X XXX', 'XX XXXXX', 'XXXXXX X']
7. Playfair key (Challenging)
You are given plaintext and ciphertext of a message encrypted with Playfair cipher, you need to find the key and encrypt given word using that key:
assert playfair_cracker('weareallfromxanthcubesaidquicklyjustvisitingphaze', 'fmhvmxpanmyceaqlrxwhxkixdchndomgvopcvzdisvolulqbtk', 'helloworld') == 'xwpanifcvusb'
The difficulties are of course my estimations. What do you think?