CLASSICAL CRYPTOGRAPHY PROJECT
Implementation, Encryption, Decryption & Cipher Analysis
Project Documentation
Python-based implementation of classical encryption techniques
1. Project Overview
The project is a classical cryptography demonstration system implemented in Python. It provides encryption and decryption functions for multiple historical ciphers and allows the same plaintext to be processed through different algorithms for comparison. The implementation also measures characteristics of the resulting ciphertext, including execution time, chi-squared score, index of coincidence, Shannon entropy, and an estimated key-space size.
The code is organized as reusable functions and an Enigma class. Input validation is included for important parameters such as cipher keys, offsets, rotor settings, and Hill cipher matrices.
2. Ciphers Implemented
3. Caesar Cipher and ROT13
Caesar Cipher
The Caesar implementation applies a fixed shift to each alphabetic character. Uppercase and lowercase letters are preserved, while non-alphabetic characters remain unchanged. Decryption uses the same transformation with the negative of the encryption shift.
The project also includes a brute-force function that tries all 26 possible Caesar shifts.
ROT13
ROT13 is implemented as a Caesar transformation with a fixed shift of 13. Because shifting by 13 twice returns to the original letter, the same ROT13 operation can be used in both directions.
4. Vigenere Cipher
The Vigenere cipher uses a repeating alphabetic key. For each alphabetic character, the corresponding key character determines the shift. The key index advances only when an alphabetic character is processed, while spaces and other non-alphabetic characters are preserved.
For decryption, the key shift is subtracted instead of added. The implementation validates that the key is non-empty and contains only alphabetic characters.
5. One-Time Pad (OTP)
The OTP implementation applies a different key character to each alphabetic character of the plaintext. The key must be at least as long as the number of alphabetic characters in the message; otherwise the program raises an error. The implementation also provides a random key-generation helper.
The generated random key is intended for the class demonstration in this project; the source code itself notes that a cryptographic secrets source would be preferred for real security.
6. Playfair Cipher
The Playfair implementation builds a 5×5 key matrix. The letter J is merged with I, producing a 25-letter square. The keyword is placed first without duplicates, followed by the remaining alphabet letters.
Before encryption, the plaintext is converted to uppercase letters, J is changed to I, and the message is divided into pairs. If a pair contains duplicate letters, an X is inserted between them. An X is also added if the final letter has no partner.
For each pair, the code applies the standard Playfair rules: letters in the same row move right, letters in the same column move down, and letters forming a rectangle exchange columns. Decryption reverses the row and column movements.
7. Hill Cipher
The Hill cipher implementation converts a four-letter key into a 2×2 numerical matrix using A=0 through Z=25. Plaintext is processed in pairs and multiplied by the matrix modulo 26.
A key is valid only when the matrix is invertible modulo 26. The implementation checks the determinant and requires the determinant to be relatively prime to 26. Decryption uses the modular inverse of the key matrix.
If the number of alphabetic characters is odd, the implementation pads the message with X before processing.
8. Enigma Cipher
The Enigma implementation is represented by an Enigma class. It uses three selectable rotors, each with a fixed wiring, and a reflector. The supported rotor wirings in the project are Rotor I, Rotor II and Rotor III.
The machine is initialized with a rotor order and three starting positions. Before every alphabetic character is processed, the rotors step. The right rotor advances for each letter, and notch conditions control when the middle and left rotors advance.
During encryption, the character travels from the right rotor to the middle rotor and then the left rotor, enters the reflector, and then travels backward through the left, middle and right rotors. The rotor-position adjustment is included in both the forward and backward transformations.
Enigma is reciprocal in this implementation. Therefore, a fresh machine with the same rotor order and starting positions can process the ciphertext again to recover the original plaintext.
9. Wheel / Jefferson Disk Cipher
The Wheel cipher implementation uses multiple shuffled alphabet disks. Six disks are used by default. The disks are generated from a keyword; the keyword and disk number are used to initialize the random generator, so the same keyword recreates the same disk arrangement.
During encryption, the program selects disks cyclically. For each alphabetic character, it finds the character's position on the selected disk, adds the specified offset modulo 26, and outputs the character at the new position.
Decryption regenerates the same disks using the keyword and subtracts the same offset. Non-alphabetic characters are preserved.
10. Ciphertext Analysis
Letter Frequency
The project counts occurrences of A–Z characters in a case-insensitive manner. This frequency information is used by the statistical analysis functions.
Chi-Squared Score
The chi-squared score compares observed letter frequencies with standard English frequencies. The implementation uses a lower score to indicate a ciphertext distribution that resembles natural English more closely.
Index of Coincidence
The Index of Coincidence measures how frequently pairs of letters are likely to match. The source documentation notes that values around 0.067 resemble natural English while lower values can indicate a more uniform distribution.
Shannon Entropy
Shannon entropy is calculated in bits per character using the A–Z distribution. The maximum possible entropy for a 26-letter alphabet is approximately log2(26), or 4.70 bits per character. Higher entropy represents greater unpredictability in the observed distribution.
Execution Time and Key Space
The project measures execution time using a high-resolution performance timer. It also records an estimated key-space size in bits for the implemented ciphers. For example, Caesar has 26 possible shifts, while the Wheel configuration uses six permutations of a 26-letter alphabet.
11. Common Comparison Function
The compare_all function processes the same plaintext through the selected ciphers and creates a common result row for each cipher. Each row contains the cipher name, ciphertext, execution time, chi-squared score, index of coincidence, entropy, and key-space information.
This makes it possible to compare different classical techniques using consistent measurements rather than looking only at the encrypted text.
12. Testing and Validation
The project includes a main test section that encrypts a sample message with every implemented cipher and then decrypts it. For the reversible cases, assertions are used to verify that the original plaintext is recovered.
The source test section ends with a message indicating that all round-trip tests passed when the expected results are obtained.
13. Program Structure
14. Conclusion
This project demonstrates how different classical cryptographic techniques transform plaintext into ciphertext using different mathematical and mechanical ideas. The project covers simple substitution, polyalphabetic encryption, pair-based methods, matrix-based encryption, rotor-based encryption, and disk-based encryption.
Beyond encryption and decryption, the project provides a practical comparison layer using execution time, statistical characteristics, entropy, and key-space estimates. The included round-trip tests provide a basic functional validation of the implementations.
The project is intended as an educational demonstration of classical cryptography and comparative cipher analysis rather than as a replacement for modern cryptographic standards.

[TABLE 1]
Project Area | Details
Programming Language | Python
Main Objective | Implement and compare classical cryptographic ciphers
Encryption Modes | Caesar, ROT13, Vigenere, OTP, Playfair, Hill, Enigma, Wheel/Jefferson Disk
Analysis | Chi-squared score, Index of Coincidence, Shannon entropy, timing and key-space comparison
Validation | Round-trip encryption/decryption tests

[TABLE 2]
Cipher | Basic Principle | Key / Setting
Caesar | Shifts alphabetic characters by a fixed amount. | Integer shift
ROT13 | Special Caesar transformation using a fixed 13-position shift. | No variable key
Vigenere | Uses repeating key letters to apply changing Caesar shifts. | Alphabetic key
One-Time Pad (OTP) | Applies a key-dependent shift to each alphabetic character. | Key at least as long as message letters
Playfair | Encrypts pairs of letters using a 5×5 key square. | Alphabetic keyword
Hill | Encrypts pairs using a 2×2 matrix modulo 26. | Exactly four letters; matrix must be invertible
Enigma | Uses three rotors, a reflector, and changing rotor positions. | Rotor order + starting positions
Wheel / Jefferson Disk | Uses shuffled alphabet disks and a position offset. | Keyword + offset

[TABLE 3]
Tested Component | Validation
Caesar | Encrypt then decrypt and compare with original sample
ROT13 | Apply ROT13 twice and compare with original
Vigenere | Encrypt and decrypt using the same key
OTP | Encrypt and decrypt using the generated key
Playfair | Encrypt and decrypt using the same keyword
Hill | Generate a valid key, encrypt, decrypt, and inspect the result
Enigma | Process ciphertext again using the same rotor settings
Wheel | Encrypt and decrypt using the same keyword and offset

[TABLE 4]
Component | Responsibility
Cipher functions | Provide independent encryption/decryption implementations.
Enigma class | Maintains rotor wiring, positions, stepping, and character processing.
Statistical analysis | Calculates frequency, chi-squared, coincidence, and entropy metrics.
Timing helper | Measures execution time of a cipher operation.
Comparison function | Runs selected ciphers on the same plaintext and collects common metrics.
Validation / errors | Checks keys, lengths, types, and valid Hill matrices.
Main test section | Runs sample round-trip tests for the implemented algorithms.
