This repository contains implementations of classical cryptography algorithms written in C. Currently, it includes:
- 🥇 Caesar Cipher
- 🥈 Vigenère Cipher
- 🥉 Hill Cipher
These algorithms demonstrate how traditional encryption techniques work using basic mathematical logic. Future updates will include more ciphers like Playfair and Rail Fence.
Before the rise of modern cryptography, classical ciphers were widely used to secure communication. They rely on substitution (replacing letters) or transposition (rearranging letters).
| Cipher Name | Cipher Type | Technique | Security Level |
|---|---|---|---|
| Caesar Cipher | Substitution Cipher | Single alphabet shift | 🔓 Basic |
| Vigenère Cipher | Polyalphabetic Substitution | Keyword-based shifting | 🔒 Moderate |
| Hill Cipher | Polyalphabetic Substitution | Matrix-based encryption | 🔒 Stronger |
Type: Substitution Cipher
Key: Integer (e.g., 3, 4, etc.)
Each alphabet letter is shifted by the key value within the alphabet. When the alphabet’s end is reached, it wraps around to the beginning.
E(x) = (x + key) mod 26
Plaintext : HELLO
Key : 3
Ciphertext: KHOOR
caesar_cipher.c
Type: Polyalphabetic Substitution Cipher
Key: Word or keyword (e.g., "LOKI")
Each letter of the plaintext is shifted based on the corresponding character of the key. The key repeats itself until it matches the length of the plaintext.
E(x) = (P + K) mod 26
Plaintext : LOKESWAR REDDY
Keyword : LOKI
Ciphertext: WZOYWAMU BSOHS
vigenere_cipher.c
Type: Matrix-based Polyalphabetic Cipher Key: 2×2 or 3×3 matrix (numeric values)
Each pair (or triplet) of letters is treated as a vector and multiplied by the key matrix. The result is taken modulo 26 to obtain the ciphertext letters.
C = (K × P) mod 26
where
- K = key matrix
- P = plaintext vector
- C = ciphertext vector
Plaintext : LOKI
Key Matrix:
1 2
3 4
Ciphertext: NLAK
hill_cipher.c
gcc caesar_cipher.c -o caesar
./caesargcc vigenere_cipher.c -o vigenere
./vigeneregcc hill_cipher.c -o hill
./hillEnter plain text: Lokeswar Reddy
Enter the key value: 4
Cipher Text: Psogiwa Vihhc
Enter plain text: Lokeswar Reddy
Enter key: loki
Cipher Text: Wzoywamu Bsohs
Enter plain text: LOKI
Enter key matrix (2x2):
1 2
3 4
Encrypted Text: NLAK
Classical-Ciphers/
│
├── caesar_cipher.c # Caesar Cipher implementation
├── vigenere_cipher.c # Vigenère Cipher implementation
├── hill_cipher.c # Hill Cipher implementation
├── README.md # Project documentation
└── (more ciphers coming soon...)
| Cipher Name | Type | Status |
|---|---|---|
| Playfair Cipher | Digraph substitution | ⏳ Planned |
| Rail Fence Cipher | Transposition cipher | ⏳ Planned |
| Autokey Cipher | Keyword-based | ⏳ Planned |
| Columnar Transposition | Rearrangement cipher | ⏳ Planned |
Each will include both encryption and decryption implementations.
- Non-alphabetic characters remain unchanged.
- Case (uppercase/lowercase) is preserved.
- For decryption, subtract the key or use matrix inverse (for Hill).
- Increase the
SIZEconstant to handle longer messages. - Works on all major C compilers.
Lokeswar Reddy 🎓 Engineering Student 💻 Interests: Cryptography, Computer Security, and Programming
“Learning classical ciphers is the first step to understanding the logic behind modern encryption.”
#C #Cryptography #ClassicalCiphers #Encryption #CaesarCipher #VigenereCipher #HillCipher
This project is open-source and free to use for educational purposes.
💡 Understanding classical cryptography builds the foundation for securing the future.