Skip to content

Commit

Permalink
Perspective for all toy cipher exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
mpg committed Dec 26, 2024
1 parent 1c5e077 commit 1e3e9f5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
14 changes: 14 additions & 0 deletions exercises/affine-cipher/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ Finding MMI for `a = 15`:

[mmi]: https://en.wikipedia.org/wiki/Modular_multiplicative_inverse
[coprime-integers]: https://en.wikipedia.org/wiki/Coprime_integers

## Perspective

While stronger than the atbash cipher, the affine cipher is still weak because the number of possible keys is way too small: 12 possible values for `a` (needs to be coprime to 26), 26 for `b`, so only 312 different keys. Given a ciphertext, you can write a program that prints all 312 possible plaintexts, one per line, and look at the list to quickly identify the line that looks like English. (This could even be automated using a dictionary.)

The affine cipher is an example of a [substitution cipher][sc]; other examples can be found in exercises "simple-cipher", "atbash-cipher", and "rotational-cipher".

You can find examples of ciphers based on an different principle, known as [transposition ciphers][tc], in exercises "crypto-square" and "rail-fence-cipher".

All of these ciphers are considered toy ciphers by current standards. However, substitution and transposition (also called permutation) are two building blocks of modern ciphers like [AES][aes].

[sc]: https://en.wikipedia.org/wiki/Substitution_cipher
[tc]: https://en.wikipedia.org/wiki/Transposition_cipher
[aes]: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
14 changes: 14 additions & 0 deletions exercises/atbash-cipher/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ All text will be encoded as lowercase letters.
- Encoding `x123 yes` gives `c123b vh`
- Decoding `gvhg` gives `test`
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`

## Perspective

The atbash cipher is weak because there is no secret key: as soon as you know (or guess) that the text has been encrypted with the atbash cipher, you can immediately decrypt it.

The atbash cipher is an example of a [substitution cipher][sc]; other examples can be found in exercises "rotational-cipher", "simple-cipher" and "affine-cipher".

You can find examples of ciphers based on an different principle, known as [transposition ciphers][tc], in exercises "crypto-square" and "rail-fence-cipher".

All of these ciphers are considered toy ciphers by current standards. However, substitution and transposition (also called permutation) are two building blocks of modern ciphers like [AES][aes].

[sc]: https://en.wikipedia.org/wiki/Substitution_cipher
[tc]: https://en.wikipedia.org/wiki/Transposition_cipher
[aes]: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
12 changes: 12 additions & 0 deletions exercises/crypto-square/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ Notice that were we to stack these, we could visually decode the ciphertext back
"aohghn "
"sseoau "
```

## Perspective

This cipher is weak because there is no secret key: as soon as you know (or guess) that the text has been encrypted with this cipher, you can immediately decrypt it.

It is an example of a [transposition cipher][tc], like the exercise "rail-fence-cipher". Other exercises, like "rotational-cipher", "simple-cipher", "atbash-cipher" and "affine-cipher", are examples of [substitution ciphers][sc].

Substitution and transposition (also called permutation) are two building blocks of modern ciphers such as [AES][aes].

[tc]: https://en.wikipedia.org/wiki/Transposition_cipher
[sc]: https://en.wikipedia.org/wiki/Substitution_cipher
[aes]: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
12 changes: 12 additions & 0 deletions exercises/rail-fence-cipher/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ W . . . E . . . C . . . R . . . L . . . T . . . E
```

If you now read along the zig-zag shape you can read the original message.

## Perspective

This cipher is weak because set the of possible values for the secret key (the number of rails) is very small (no more than the length of the message). Given a message encrypted with the rail fence cipher, you can write a program that tries all possible numbers of rails and prints out all possible plaintexts, one per line. It is then easy to look at the output and identify the line that looks like English. (This could even be automated, for example using a dictionary.)

The rail fence cipher is an example of a [transposition cipher][tc], like the exercise "crypto-square". Other exercises, like "rotational-cipher", "simple-cipher", "atbash-cipher" and "affine-cipher", are examples of [substitution ciphers][sc].

All of these ciphers are considered toy ciphers by current standards. However, substitution and transposition (also called permutation) are two building blocks of modern ciphers like [AES][aes].

[tc]: https://en.wikipedia.org/wiki/Transposition_cipher
[sc]: https://en.wikipedia.org/wiki/Substitution_cipher
[aes]: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
14 changes: 14 additions & 0 deletions exercises/rotational-cipher/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ Ciphertext is written out in the same formatting as the input including spaces a
- ROT26 `Cool` gives `Cool`
- ROT13 `The quick brown fox jumps over the lazy dog.` gives `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.`
- ROT13 `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` gives `The quick brown fox jumps over the lazy dog.`

## Perspective

The rotational cipher is very weak because the number of possible keys is way too small. Given a message encrypted with this cipher, you can write a program that prints all 26 possible plaintexts and look at the list to quickly identify the one that looks like English. (This could even be automated, for example using a dictionary.)

You can find an improvement over this rotational cipher (also called shift cipher) in the exercise "simple-cipher". Other examples of [substitution ciphers][sc] can be found in exercises "atbash-cipher" and "affine-cipher".

You can find examples of ciphers based on an different principle, known as [transposition ciphers][tc], in exercises "crypto-square" and "rail-fence-cipher".

All of these ciphers are considered toy ciphers by current standards. However, substitution and transposition (also called permutation) are two building blocks of modern ciphers like [AES][aes].

[sc]: https://en.wikipedia.org/wiki/Substitution_cipher
[tc]: https://en.wikipedia.org/wiki/Transposition_cipher
[aes]: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
18 changes: 12 additions & 6 deletions exercises/simple-cipher/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ Let's make your substitution cipher a little more fault tolerant by providing a

If someone doesn't submit a key at all, generate a truly random key of at least 100 lowercase characters in length.

## Extensions
## Perspective

Shift ciphers work by making the text slightly odd, but are vulnerable to frequency analysis.
Substitution ciphers help that, but are still very vulnerable, especially when the key is short or if spaces are preserved.
Later on you'll see one an improvement in the exercise "crypto-square".
Shift ciphers work by making the text slightly odd, but are very weak because
the number of possible keys is way too small. Given a message encrypted with this cipher, you can write a program that prints all 26 possible plaintexts and look at the list to quickly identify the one that looks like English. This could even be automated, for example using a dictionary, or frequency analysis.

However, all of these ciphers are considered toy ciphers by current standards. Modern alternatives include [AES][aes] and [Chacha][chacha].
Substitution ciphers help that, but are still vulnerable to frequency analysis, especially when the key is short or if spaces are preserved. (Note: the Vigenère Cipher is only one example of a [substitution cipher][sc]; others can be found in exercises "atbash-cipher" and "affine-cipher".)

You can find examples of ciphers based on an different principle, known as [transposition ciphers][tc], in exercises "crypto-square" and "rail-fence-cipher".

All of these ciphers are considered toy ciphers by current standards. However, substitution and transposition (also called permutation) are two building blocks of modern ciphers like [AES][aes].

If you want to go farther in this field, the questions begin to be about how we can exchange keys in a secure way.
Take a look at [Diffie-Hellman on Wikipedia][dh] for one of the first implementations of this scheme.
Expand All @@ -82,7 +85,10 @@ For a solid foundation in modern cryptography, you can check out the [Crypto 101
[cc]: https://en.wikipedia.org/wiki/Caesar_cipher
[img-caesar-cipher]: https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Caesar_cipher_left_shift_of_3.svg/320px-Caesar_cipher_left_shift_of_3.svg.png
[vc]: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher

[sc]: https://en.wikipedia.org/wiki/Substitution_cipher
[tc]: https://en.wikipedia.org/wiki/Transposition_cipher
[aes]: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
[chacha]: https://en.wikipedia.org/wiki/Salsa20#ChaCha_variant

[dh]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
[c101]: https://cryptography101.ca/crypto101-building-blocks/

0 comments on commit 1e3e9f5

Please sign in to comment.