Skip to content

raultejada24/cryptography-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cryptography Algorithms

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.

Overview

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.

1. Caesar Cipher (caesar_cipher.py)

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.

2. Base64 Encoding (base64_cipher.py)

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 base64 library. It handles utf-8 encoding/decoding and properly processes padding characters (=).

3. Vigenère Cipher (vigenere_cipher.py)

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.

4. XOR Cipher (xor_cipher.py)

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() and chr() functions.

5. Advanced Encryption Standard / AES (aes_cipher.py)

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 pycryptodome library. It includes proper PKCS7 padding implementation to handle arbitrary text lengths and processes inputs/outputs in hexadecimal format for safe transport.

Prerequisites

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 pycryptodome

Usage

Each 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.py

Disclaimer

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

About

A collection of fundamental cryptographic algorithms (Caesar, Base64, Vigenère, XOR, and AES-128) implemented in Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages