CSCI 663 - Introduction to Cryptography Group B - Final Project
A comprehensive web application demonstrating both RSA (asymmetric) and AES (symmetric) cryptographic algorithms with a clean, educational interface. Built entirely in Python with a React frontend.
This project implements RSA and AES cryptographic algorithms from scratch in pure Python, providing both a REST API and an interactive web interface for encryption, decryption, and digital signatures.
Complete RSA Implementation
- Asymmetric encryption/decryption
- Digital signatures with SHA-256 hashing and verification
- Signature authentication and non-repudiation
- Key sizes: 256, 512, 1024, 2048-bit
- Pure Python implementation (no external crypto libraries)
- Key import/export functionality
- Flexible input parsing (decimal/hexadecimal)
- Miller-Rabin primality testing (k=5 rounds)
- Extended Euclidean Algorithm for modular inverse
Complete AES Implementation
- Symmetric encryption/decryption
- Supports AES-128, AES-192, AES-256
- ECB mode with PKCS#7 padding
- Pure Python implementation
- Custom S-box, ShiftRows, MixColumns
Unified REST API
- Single Flask server handles both RSA and AES
- CORS-enabled for frontend integration
- Session management for RSA keys
- JSON-based request/response
Interactive Web Interface
- React-based UI with Tailwind CSS
- Real-time encryption/decryption
- Algorithm switching (RSA ↔ AES)
- Key generation buttons
- Copy-to-clipboard functionality
Measured on Apple Silicon (M-series) / Intel Mac
| Key Size | Generation Time | Encryption | Decryption |
|---|---|---|---|
| 256-bit | ~30ms | 0.01ms | 0.5ms |
| 512-bit | ~80ms | 0.02ms | 2ms |
| 1024-bit | ~500ms | 0.03ms | 5ms |
| 2048-bit | ~800ms | 0.1ms | 20ms |
| Key Size | Encryption | Decryption |
|---|---|---|
| 128-bit | ~0.5ms | ~0.5ms |
| 192-bit | ~0.6ms | ~0.6ms |
| 256-bit | ~0.7ms | ~0.7ms |
Note: Pure Python implementation is 5-10x slower than C-based libraries (OpenSSL), but excellent for educational purposes.
CSCI663-GroupB-CryptographyProject/
│
├── api/ # Unified Backend Server
│ ├── app.py # ⭐ Main Flask server (RSA + AES)
│ ├── requirements.txt # Python dependencies
│ └── test_flask_api.py # API integration tests (26 tests)
│
├── rsa/ # RSA Implementation
│ ├── __init__.py # Package exports
│ ├── rsa.py # Simplified API wrapper
│ ├── rsa_system.py # Core RSA algorithms
│ ├── test_rsa.py # Unit tests (46 tests)
│ ├── flask_rsa.py # Legacy standalone server
│ ├── benchmark_rsa.py # Text-based performance benchmarks
│ ├── benchmark_with_graph.py # Visual benchmarking with matplotlib
│ └── README.md # RSA-specific documentation
│
├── aes/ # AES Implementation
│ ├── __init__.py # Package exports
│ ├── aes.py # AES algorithm implementation
│ ├── test_aes.py # Unit tests
│ └── flask_aes.py # (Standalone server - optional)
│
├── src/ # React Frontend
│ ├── App.jsx # Main React component
│ ├── main.jsx # Entry point
│ └── index.css # Tailwind CSS
│
├── venv/ # Python Virtual Environment
│ └── ... # Flask, Flask-CORS, matplotlib, etc.
│
├── Startup Scripts
│ ├── start_all.sh # 🎯 Run both backend + frontend
│ ├── run.sh # Alternative startup
│ └── start_server.sh # Backend only
│
├── Documentation
│ ├── README.md # This file
│ ├── QUICK_START.md # Quick reference
│ ├── START_PROJECT.md # Complete startup guide
│ ├── PROJECT_STRUCTURE.md # Architecture details
│ ├── RUN_BENCHMARK.md # Performance testing guide
│ ├── FLASK_SERVER_GUIDE.md # Server troubleshooting
│ ├── NAK_PRESENTATION_SLIDES.md # Presentation content
│ └── PERFORMANCE_SLIDES.md # Performance analysis
│
├── Configuration
│ ├── package.json # Node.js dependencies
│ ├── vite.config.js # Vite configuration
│ ├── tailwind.config.js # Tailwind CSS config
│ └── .gitignore # Git ignore rules
│
└── Startup Scripts
└── start_all.sh # 🎯 Run both backend + frontend (executable)
- Python 3.13+ (with venv)
- Node.js 18+ (with npm)
- macOS, Linux, or Windows
# 1. Clone/navigate to project directory
cd CSCI663-GroupB-CryptographyProject
# 2. Create Python virtual environment (if not exists)
python3 -m venv venv
# 3. Activate virtual environment
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windows
# 4. Install Python dependencies
pip install flask flask-cors matplotlib numpy
# 5. Install Node.js dependencies
npm installEasiest Way (Recommended):
# Make the script executable (first time only)
chmod +x start_all.sh
# Run everything
./start_all.shManual Way (Two Terminals):
Terminal 1 - Backend:
source venv/bin/activate
python3 api/app.pyTerminal 2 - Frontend:
npm run devThen open: http://localhost:5173
- Open http://localhost:5173
- Select RSA tab
- Click Generate Keys (choose 512 or 1024-bit for demos)
- Enter a message in the text box
- Click Encrypt → See ciphertext
- Click Decrypt → Original message restored
What are Digital Signatures? Digital signatures provide:
- Authentication: Proves the message came from the claimed sender
- Non-repudiation: Signer cannot deny signing the message
- Integrity: Detects if the message was tampered with
How It Works:
- Message is hashed using SHA-256 (collision-resistant cryptographic hash)
- Hash is encrypted with the private key to create signature
- Anyone can verify using the public key
Using the Interface:
- Generate RSA keys (if not already done)
- Enter a message in the text box
- Click Sign Message → Creates signature using SHA-256 hash
- Signature is displayed (can be copied)
- Click Verify Signature → Shows "Valid ✓" or "Invalid ✗"
- Try modifying the message → Signature verification fails (integrity check)
Security Properties:
- Uses SHA-256 for collision resistance
- Private key required for signing (only you can sign)
- Public key used for verification (anyone can verify)
- Computationally infeasible to forge signatures
- Select AES tab
- Click Generate Key (128, 192, or 256-bit)
- Enter plaintext message
- Click Encrypt → See hex ciphertext
- Click Decrypt → Original message restored
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/health |
Health check |
POST |
/api/generate-keys |
Generate RSA keypair |
POST |
/api/encrypt |
Encrypt message with RSA |
POST |
/api/decrypt |
Decrypt ciphertext with RSA |
POST |
/api/sign |
Create digital signature |
POST |
/api/verify |
Verify signature |
POST |
/api/import-keys |
Import external keys |
POST |
/api/get-keys |
Retrieve session keys |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/aes/health |
Health check |
POST |
/api/aes/generate-key |
Generate AES key |
POST |
/api/aes/encrypt |
Encrypt with AES |
POST |
/api/aes/decrypt |
Decrypt with AES |
Generate RSA Keys:
curl -X POST http://localhost:8080/api/generate-keys \
-H "Content-Type: application/json" \
-d '{"size": 512, "session_id": "demo"}'Encrypt with RSA:
curl -X POST http://localhost:8080/api/encrypt \
-H "Content-Type: application/json" \
-d '{"message": "Hello World", "session_id": "demo"}'Sign Message (Digital Signature):
curl -X POST http://localhost:8080/api/sign \
-H "Content-Type: application/json" \
-d '{"message": "Important Document", "session_id": "demo"}'Verify Signature:
curl -X POST http://localhost:8080/api/verify \
-H "Content-Type: application/json" \
-d '{
"message": "Important Document",
"signature": "123456789...",
"message_hash": "abcdef...",
"session_id": "demo"
}'Generate AES Key:
curl -X POST http://localhost:8080/api/aes/generate-key \
-H "Content-Type: application/json" \
-d '{"size": 128}'# RSA unit tests (46 tests)
python3 -m pytest rsa/test_rsa.py -v
# AES unit tests
python3 -m pytest aes/test_aes.py -v
# API integration tests (26 tests)
python3 -m pytest api/test_flask_api.py -v- RSA Module: 46 unit tests across 8 test classes
- Mathematical operations: GCD, Extended GCD, Modular inverse
- Prime generation: Miller-Rabin (18+ known primes, 15+ composites tested)
- Encryption/decryption workflows: Multiple test variations
- Digital signatures: Sign/verify operations, SHA-256 hashing, wrong key detection
- Edge cases: Message = 0, 1, n-1, message > n error handling
- Text conversion: Unicode support, emoji, special characters
- Security invariants: p ≠ q, gcd(e, φ(n)) = 1, e×d ≡ 1 (mod φ(n))
- AES Module: Comprehensive unit tests
- Key expansion
- SubBytes, ShiftRows, MixColumns
- Encryption/decryption
- API Integration: 26 endpoint tests
- RSA and AES endpoints
- Session management
- Error handling
- Total: 72+ tests (46 RSA + 26 API)
Text Output:
python3 rsa/benchmark_rsa.pyWith Visual Graphs:
python3 rsa/benchmark_with_graph.pyThis generates matplotlib graphs showing performance metrics across different key sizes.
See RUN_BENCHMARK.md for detailed instructions.
RSA:
- ✅ Prime number generation (Miller-Rabin primality test, k=5 rounds, ≈0.1% error)
⚠️ Randomness: Usesrandommodule (NOT cryptographically secure)- ✅ Modular arithmetic (Extended Euclidean Algorithm for modular inverse)
- ✅ Public/Private key generation (e=65537, d computed via mod inverse)
- ✅ Encryption with public key (c = m^e mod n)
- ✅ Decryption with private key (m = c^d mod n)
- ✅ Digital signatures
- SHA-256 cryptographic hashing
- Sign: s = hash(m)^d mod n
- Verify: hash(m) == s^e mod n
- Authentication and non-repudiation
- ✅ Signature verification (detects tampering and wrong keys)
- ✅ Flexible input parsing (hex/decimal support)
- ✅ Comprehensive validation (message < n, p ≠ q, coprimality checks)
AES:
- ✅ Key expansion
- ✅ SubBytes (S-box substitution)
- ✅ ShiftRows transformation
- ✅ MixColumns (Galois Field multiplication)
- ✅ AddRoundKey (XOR operation)
- ✅ PKCS#7 padding
- ✅ Variable rounds (10/12/14 based on key size)
Educational Implementation - NOT for Production:
- ❌ No OAEP padding (RSA uses textbook encryption)
- ❌ No PSS padding (digital signatures)
- ❌ ECB mode only (AES - no CBC/CTR/GCM)
- ❌ No initialization vector (IV)
- ❌ Vulnerable to timing attacks
- ❌ No constant-time operations
- ❌ Single-threaded (no parallelization)
- ❌ No Chinese Remainder Theorem optimization
For Production Use:
- Use
cryptographylibrary (Python) - Use OpenSSL or libsodium
- Implement proper key management
- Use authenticated encryption (GCM)
- Add proper error handling
Key Components:
-
Prime Generation (Lines 84-186)
- Miller-Rabin primality test
- Configurable bit length
- Random prime generation
-
Modular Arithmetic (Lines 32-82)
- Extended Euclidean Algorithm
- Modular inverse calculation
- GCD computation
-
Key Generation (Lines 208-272)
- Generate two large primes (p, q)
- Compute n = p × q
- Choose e = 65537 (public exponent)
- Calculate d = e⁻¹ mod φ(n) (private exponent)
-
Encryption/Decryption (Lines 274-308)
- Encryption: c = m^e mod n
- Decryption: m = c^d mod n
- Modular exponentiation
-
Digital Signatures (Lines 310-385)
- SHA-256 hashing: Cryptographically secure hash function
- Signing process:
- Compute hash: h = SHA256(message)
- Sign: s = h^d mod n (using private key)
- Verification process:
- Compute hash: h = SHA256(message)
- Decrypt signature: h' = s^e mod n (using public key)
- Verify: h == h' (authentic if match)
- Security properties:
- Collision resistance (SHA-256)
- Pre-image resistance
- Unforgeable without private key
Key Components:
-
S-Box Substitution (Lines 26-82)
- Pre-computed S-box table
- Inverse S-box for decryption
-
Key Expansion (Lines 140-176)
- Expands key to round keys
- Uses Rcon (round constants)
- SubWord transformation
-
Core Transformations (Lines 75-124)
- SubBytes: Byte substitution
- ShiftRows: Row permutation
- MixColumns: Galois Field operations
- AddRoundKey: XOR with round key
-
Encryption/Decryption (Lines 178-288)
- Variable rounds (10/12/14)
- PKCS#7 padding/unpadding
- ECB mode operation
✅ Understand Cryptographic Principles:
- Asymmetric vs Symmetric encryption
- Public-key cryptography concepts
- Key generation and management
- Digital signatures and verification
✅ Mathematical Foundations:
- Modular arithmetic
- Prime number generation
- Galois Field operations
- Euler's totient function
✅ Practical Implementation:
- Algorithm design patterns
- API development (REST)
- Frontend-backend integration
- Testing and benchmarking
- ✅ Cryptography course projects
- ✅ Security concept demonstrations
- ✅ Algorithm visualization
- ✅ Performance analysis
- ✅ Code review and learning
- Language: Python 3.13+
- Framework: Flask 3.0.0
- CORS: Flask-CORS 4.0.0
- Testing: pytest
- Visualization: matplotlib, numpy
- Framework: React 18.3.1
- Build Tool: Vite 5.4.2
- Styling: Tailwind CSS 3.4.1
- HTTP Client: Fetch API
- Package Manager: npm, pip
- Virtual Environment: venv
- Version Control: Git
Comprehensive documentation available:
- QUICK_START.md - Get running in 2 minutes
- START_PROJECT.md - Complete setup guide
- PROJECT_STRUCTURE.md - Architecture details
- RUN_BENCHMARK.md - Performance testing
- FLASK_SERVER_GUIDE.md - API troubleshooting
- NAK_PRESENTATION_SLIDES.md - Presentation content
- PERFORMANCE_SLIDES.md - Benchmark analysis
This is an educational project for CSCI 663.
Group Members:
- Implementation: RSA algorithms, Flask API, testing
- Implementation: AES algorithms, frontend integration
- Documentation: Technical writing, presentation slides
This is an educational implementation for learning purposes only.
DO NOT use in production systems. Use established cryptographic libraries:
- Python:
cryptography,PyCryptodome - OpenSSL
- libsodium
Educational project for academic purposes. CSCI 663 - Introduction to Cryptography
To run the complete project:
# First time setup
chmod +x start_all.sh
# Start everything
./start_all.shThen open: http://localhost:5173
Features:
- ✅ RSA encryption/decryption (256, 512, 1024, 2048-bit)
- ✅ AES encryption/decryption (128, 192, 256-bit)
- ✅ Digital signatures with SHA-256 hashing and verification
- ✅ Authentication and non-repudiation support
- ✅ Key import/export functionality
- ✅ Flexible input parsing (hex/decimal)
- ✅ Miller-Rabin primality testing (k=5, error ≈ 0.1%)
- ✅ Extended Euclidean Algorithm for modular inverse
- ✅ REST API (port 8080)
- ✅ Interactive web UI (port 5173)
- ✅ 72+ unit tests (46 RSA + 26 API)
- ✅ Performance benchmarks with visual graphs
Perfect for:
- 🎓 Learning cryptography concepts
- 📊 Algorithm demonstrations
- 🔬 Performance analysis and benchmarking
- 💻 Code review and study
- 🎯 Educational presentations
Quick Commands:
# Run all tests
python3 rsa/test_rsa.py # 46 core RSA tests
python3 -m pytest api/test_flask_api.py -v # 26 API tests
python3 -m pytest aes/test_aes.py -v # AES tests
# Run benchmarks
python3 rsa/benchmark_rsa.py # Text output
python3 rsa/benchmark_with_graph.py # Visual graphs
# Start services individually
python3 api/app.py # Backend only
npm run dev # Frontend onlyMade with 🔐 for CSCI 663 - Introduction to Cryptography