Skip to content

Lokeswar72/classical_cipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🔐 Classical Ciphers in C

Language Status License Category


📘 Overview

This repository contains implementations of classical cryptography algorithms written in C. Currently, it includes:

  1. 🥇 Caesar Cipher
  2. 🥈 Vigenère Cipher
  3. 🥉 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.


💡 About Classical Ciphers

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

🧩 Implemented Ciphers

🥇 Caesar Cipher

Type: Substitution Cipher Key: Integer (e.g., 3, 4, etc.)

🔹 Logic

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.

🔹 Formula

E(x) = (x + key) mod 26

🔹 Example

Plaintext : HELLO
Key       : 3
Ciphertext: KHOOR

🔹 File

caesar_cipher.c


🥈 Vigenère Cipher

Type: Polyalphabetic Substitution Cipher Key: Word or keyword (e.g., "LOKI")

🔹 Logic

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.

🔹 Formula

E(x) = (P + K) mod 26

🔹 Example

Plaintext : LOKESWAR REDDY
Keyword   : LOKI
Ciphertext: WZOYWAMU BSOHS

🔹 File

vigenere_cipher.c


🥉 Hill Cipher

Type: Matrix-based Polyalphabetic Cipher Key: 2×2 or 3×3 matrix (numeric values)

🔹 Logic

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.

🔹 Formula

C = (K × P) mod 26

where

  • K = key matrix
  • P = plaintext vector
  • C = ciphertext vector

🔹 Example (2×2)

Plaintext : LOKI
Key Matrix:
1 2
3 4
Ciphertext: NLAK

🔹 File

hill_cipher.c


⚙️ How to Compile and Run

✅ Using GCC

gcc caesar_cipher.c -o caesar
./caesar
gcc vigenere_cipher.c -o vigenere
./vigenere
gcc hill_cipher.c -o hill
./hill

🧑‍💻 Example Runs

▶️ Caesar Cipher

Enter plain text: Lokeswar Reddy
Enter the key value: 4
Cipher Text: Psogiwa Vihhc

▶️ Vigenère Cipher

Enter plain text: Lokeswar Reddy
Enter key: loki
Cipher Text: Wzoywamu Bsohs

▶️ Hill Cipher

Enter plain text: LOKI
Enter key matrix (2x2):
1 2
3 4
Encrypted Text: NLAK

📁 Project Structure

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...)

🚀 Upcoming Additions

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.


🧾 Notes

  • Non-alphabetic characters remain unchanged.
  • Case (uppercase/lowercase) is preserved.
  • For decryption, subtract the key or use matrix inverse (for Hill).
  • Increase the SIZE constant to handle longer messages.
  • Works on all major C compilers.

👨‍💻 Author

Lokeswar Reddy 🎓 Engineering Student 💻 Interests: Cryptography, Computer Security, and Programming

“Learning classical ciphers is the first step to understanding the logic behind modern encryption.”


🏷️ Repository Tags

#C #Cryptography #ClassicalCiphers #Encryption #CaesarCipher #VigenereCipher #HillCipher


📜 License

This project is open-source and free to use for educational purposes.


💡 Understanding classical cryptography builds the foundation for securing the future.

About

This repository contains implementations of classical cryptography algorithms written in C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages