It's a process that turns one piece of text (plaintext) into a jumbled up piece of text (ciphertext) that is difficult* to undo.
The simplest cipher is a Caesar Cipher. How 2 Caesar?
k from 0 to 25k after it in the alphabet, wrapping around
after 26k)ciphertext and -kn, so are much less vunerablen into vector of numbersn×n transformation matrixWe start with a text key:
For a Hill 2-cipher, we need to turn this into a 2x2 matrix. Take the first 4 letters and convert them to letters based on their position in the alphabet using this table
| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
[placeholder]. Notice:
Loading...
Note that unlike a Caesar Cipher, not all possible keys are valid. We'll get to why in step 3.
This is the easiest step!
Loading.... Like earlier, we omit all non-alphabetic characters to simplify the vectors*Loading... Loading...
TL;DR: we want to guarantee our numbers are back in range, so mod them by 26 to get in-range vectors.
The longer explanation...
into .
All we've really done so far is:
A from our key stringP from our plaintextAP mod 26 into text as ciphertext
If it weren't for the mod, step 3 would be obvious: find A-1 and multiply AP by it.
Turns out, number theory is actually really nice here: via some fancy math*, we can find our decryption matrix, B.
This is where the key restrictions come in: we calculate B as B = (A-1 * modinv(det A) * det(A)) mod 26, which requires A to be invertible AND its determinant to have a modular inverse. Your key is valid, so:
All the hard work is done! B in mod 26 behaves exactly like you'd expect A-1 to behave regularly, so we can just:
Loading... into Loading...B and mod them to get Loading...Loading... (our original text was Loading...)And two of them (enciphering and deciphering) are practically the same. Somehow, that's all we need to package up a secret for sharing.
The Hill Cipher was developed mainly as an educational tool and a proof-of-concept for linear algebra-based block ciphers.
And it's really good at that! The key ideas are the same as encryption algorithms that computers actually use (e.g. aes, rsa), and it's a great intro to cryptography.
BUT we don't use it irl because:
That leaves a LOT of space for improvement! One easy change is to increase matrix size from 2x2. This lets us "jumble" more letters at once, so get a more secure* message.
Play around with it on the next page!
A to do the enciphering! Go back to step 1, fix your matrix, then come back.