A collection of Python scripts demonstrating fundamental cryptographic concepts, ranging from classic historical ciphers to modern encryption standards. This repository was built for educational purposes to understand the mathematical foundations and logical implementations of data security algorithms.
This toolkit includes standalone Python scripts for five different cryptographic algorithms. Most implementations are built from scratch without external libraries to showcase the raw logic behind the ciphers, with the exception of the modern AES standard.
One of the oldest and simplest encryption techniques. It is a substitution cipher where each letter in the plaintext is shifted a certain number of places down the alphabet.
- Mechanism: Monoalphabetic substitution using a modulo 26 mathematical operation.
- Implementation Details: Preserves original capitalization and ignores non-alphabetic characters (numbers and symbols). The script includes a built-in brute-force function to print all 26 possible rotations.
While technically an encoding scheme rather than an encryption cipher, Base64 is heavily used in cryptography to safely transmit binary data across text-based protocols.
- Mechanism: Translates binary data into 64 printable characters.
- Implementation Details: Utilizes Python's native
base64library. It handlesutf-8encoding/decoding and properly processes padding characters (=).
A method of encrypting alphabetic text by using a series of interwoven Caesar ciphers based on the letters of a keyword.
- Mechanism: Polyalphabetic substitution.
- Implementation Details: Built entirely from scratch using a strict 52-character alphabet (lowercase and uppercase English letters). The script handles the cyclic repetition of the keyword to match the length of the plaintext automatically.
An additive cipher based on the exclusive disjunction (XOR) logical operation. It is a fundamental building block for many modern symmetric ciphers.
- Mechanism: Bitwise XOR operation (
^) between the plaintext characters and a repeating key. - Implementation Details: Symmetric by nature—the exact same function is used to both encrypt and decrypt the data. It operates at the byte level using Python's
ord()andchr()functions.
A modern, symmetric-key block cipher established as an encryption standard by the U.S. National Institute of Standards and Technology (NIST).
- Mechanism: AES-128 algorithm operating in Cipher Block Chaining (CBC) mode.
- Implementation Details: Uses the
pycryptodomelibrary. It includes proper PKCS7 padding implementation to handle arbitrary text lengths and processes inputs/outputs in hexadecimal format for safe transport.
For the classic ciphers (Caesar, Base64, Vigenère, XOR), no external dependencies are required. You only need a standard Python 3.x installation.
For the AES Cipher, you need to install the pycryptodome package:
pip install pycryptodomeEach script is designed to be completely standalone. You can run them directly from your terminal to see the encoding and decoding examples in action:
python caesar_cipher.py
python base64_cipher.py
python vigenere_cipher.py
python xor_cipher.py
python aes_cipher.pyThese scripts are designed for learning and academic purposes. While the AES implementation uses a secure library, hardcoding keys and Initialization Vectors (IVs) inside the source code (as done in these examples for simplicity) is strictly against security best practices in production environments.