Skip to content

Charbelto/Cipher-Web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cipher-Web: Classical Cryptography & Encryption Suite

Cipher-Web is an interactive Flask web application that serves as a demonstration and execution suite for classical cryptography algorithms. Users can encrypt and decrypt plaintext inputs using several historical ciphers, compute mathematical properties (like modular inverses using the Extended Euclidean Algorithm), and interact with a visual web interface.


📋 Table of Contents

  1. Supported Ciphers
  2. Tech Stack
  3. Mathematical Principles
  4. Project Structure
  5. Installation & Setup

🔒 Supported Ciphers

  • Vigenère Cipher: Polyalphabetic substitution cipher that encrypts letters by shifting them based on a repeating keyword.
  • Hill Cipher: Polygraphic substitution cipher based on linear algebra:
    • Supports both 2x2 and 3x3 key matrices.
    • Performs matrix multiplication and matrix inversion modulo 26 using SymPy.
  • Monoalphabetic Cipher: Simple substitution cipher mapping the alphabet to a user-defined key alphabet.
  • Affine Cipher: Monoalphabetic shift cipher using modular arithmetic:
    • Formula: $E(x) = (ax + b) \pmod{26}$.
    • Tuned with post-hoc frequency analysis fallback options for decryption.
  • Playfair Cipher: Encrypts pairs of letters (digraphs) using a dynamically generated $5 \times 5$ matrix key.
  • Extended Euclidean Solver: Programmatic calculator for modular multiplicative inverses.

💻 Tech Stack

  • Frontend: Bootstrap, HTML5, CSS3, Google Fonts
  • Backend: Flask (Python)
  • Math Engine: NumPy (matrix operations) & SymPy (symbolic mathematics and modular inversion)

📐 Mathematical Principles

1. Affine Cipher Modular Arithmetic

To encrypt: $$C \equiv (aP + b) \pmod{26}$$ To decrypt: $$P \equiv a^{-1}(C - b) \pmod{26}$$ where $a^{-1}$ is the modular multiplicative inverse of $a$ modulo 26, satisfying $a \cdot a^{-1} \equiv 1 \pmod{26}$.

2. Hill Cipher Matrix Operations

A block of plaintext letters represented as a vector $\mathbf{P}$ is encrypted using a key matrix $\mathbf{K}$: $$\mathbf{C} \equiv \mathbf{K} \cdot \mathbf{P} \pmod{26}$$ Decryption requires finding the inverse key matrix modulo 26: $$\mathbf{P} \equiv \mathbf{K}^{-1} \cdot \mathbf{C} \pmod{26}$$


📂 Project Structure

Cipher-Web/
├── templates/               # HTML template panels (index, vigenere, hill, affine, etc.)
├── static/                  # Stylesheets and visual assets
├── app.py                   # Flask routing and cipher algorithm logic
├── requirements.txt         # Package dependencies
└── README.md                # Documentation

🚀 Installation & Setup

Prerequisites

  • Python 3.8+

1. Setup Environment

cd github_repos/Cipher-Web

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Run Application

python app.py

The app will run on http://127.0.0.1:5000/. Select a cipher from the navbar menu, input your text and keys, and click Encrypt/Decrypt to verify.

About

Flask-based web application implementing classical cryptographic ciphers (Affine, Playfair, Hill, Vigenere).

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors