4-Classical Ciphers
Caesar Cipher
In Caesar Cipher, characters are substituted according to the key. If key is 1 A will be substituded with B, B will be subsituted with C, … Z will be subsituded with A. If key is 10 A will be substituted with K. The substitutions are done using the formula c = (a + k) mod 26 where a is original character that is substituted with c, k is key.
Caesar Cipher can be quite easily broken by a bruteforce attack since number of possibilies of keys is only 26.
Monoalphabetic Substitution Cipher
Caesar Cipher is a special case of Monoalphabetic subsitution cipher. In Monoalphabetic substitution cipher, a random one-to-one mapping is made for alphabets. Each alphabet can only be mapped to one alphabet and vice versa.
There can be 26! possibilities of one-to-one mappings.
Vigenere Cipher
Vigenere Cipher improves on Caesar and Monoalphabetic Cipher In Vigenere Cipher, one character can have mappings to more than one character
How it works: Consider plaintext: helloworld and key: BGC
- Assign Numeric Values A = 0, B = 1, C = 2, … Z = 25 Plaintext: HELLOWORLD
- H(7), E(4), L(11), L(11), O(14), W(22), O(14), R(17), L(11), D(3)
Key: BGC → B(1), G(6), C(2) (repeated to match length 10): BGCBGCBGCB
- 1, 6, 2, 1, 6, 2, 1, 6, 2, 1
- Now we substitue every character using the formula c = (a + k) mod 26, where a is the character , k is the number of key character below it and c is the corresponding cypher character
After subsituting every character, we get the following cyphertext
i k n m u y p x n e
Notice how the plaintext letters are mapped to more than one cyphertext letters.
Consider the plaintext hello, if they key is unknown, there can be 5 possible key lengths.
If the key length is 5, the key can have 26 * 26 * 26 * 26 * 26 possibilities
If the key length is 4, the key can have 26 * 26 * 26 * 26 possibilities
and so on.
If we have to bruteforce it, the total possibilities of key are -> $26^5 + 26^4 + 26^3 + 26^2 + 26^1$
Railfence Cipher
In Railfence Cipher, plaintext is written down as a sequence of diagonals and then read off as a sequence of rows.
To encrypt the message ilikecs with a depth of 3, we write it as
i__e_
l_k__c
i_____s\
ielkcis
The railfence is not strong, the number of practical keys is small enough that a cryptanalyst can try them all by hand.\
Columnar Transposition Cipher
In this cipher, message is written in a grid row by row and read off column by column
The order in which it is read from rows is defined by the key\
message: THIS IS TOP SECRET
key: 3241\
3 2 4 1
T H I S
I S T O
P S E C
R E T
Ciphertext: SOC HSSE TIPR ITET\
Different variations exist, write in rows/columns, read from rows/columns. read from ascending/descending order It is recommended to put _ in place of spaces so original message can be decrypted without any confusions
One Time Pad - OTP
This is a theoretically unbreakable encryption cipher that uses a truly random, secret key for every message.
Two copies of OTP are made, one for sender and one for receiver
The key length has to be atleast as long as the message itself
Sender combines key with plaintext to generate ciphertext. Sender then destroys the key
Receiver uses his OTP to decrypt the ciphertext and then Receiver destroys the key.
When used correctly, OTP provides a truly unrbeakable cipher
- The OTP should consist of truly random characters.
- The OTP (key) should have the same length as the plaintext (or longer).
- Only two copies of OTP should exist.
- The OTP should be used only once.
- Both copies of OTP should be destroyed immediately after use.
In practice, it is extremely challenging to generate truly random numbers and securely distribute the keys.
Practicality of OTP, consider Alice wants to send Bob a 100MB file, First they need to share the 100MB key and then they can securely exchange file, for every new message they need to generate and share a random key again. For every transaction, the bandwidth requirement is doubled.