A modern web application for generating cryptographic keys using Context-Free Grammar (CFG) based systems. The application provides a comprehensive interface for key generation, parse tree visualization, entropy analysis, and AES encryption/decryption.
- Multiple Selection Support: Select one or more grammar modes to combine in key generation
- Available Modes:
- Numeric: Numbers only (0-9)
- Alphabetic: Letters only (a-z, A-Z)
- Alphanumeric: Letters and numbers (a-z, A-Z, 0-9)
- Symbolic: Special characters only
- Combine multiple modes for enhanced key diversity
- Randomized CFG derivations for high entropy
- Configurable key length
- Unique structure generation using descriptive nonterminal names
- Single source of truth for generated keys
- Animated step-by-step derivation process
- Interactive controls (Play, Pause, Reset, Slider)
- Color-coded symbols (blue for nonterminals, green for terminals)
- Complete derivation history
- Full parse tree structure display
- Proper node alignment and layout
- SVG-based rendering with automatic scaling
- Supports deep tree structures (3+ levels)
- Handles all terminal characters including special symbols like
|
- Shannon entropy calculation
- Visual color-coded bar (red → yellow → green)
- Entropy quality assessment
- Maximum entropy comparison
- AES-GCM authenticated encryption
- Encrypt/decrypt text using generated keys
- PBKDF2 key derivation
- Secure nonce generation
- Base64 encoded output
- FastAPI - Modern Python web framework
- Uvicorn - ASGI server
- Cryptography - AES-GCM encryption
- Pydantic - Data validation
- React 18 - UI library
- Vite - Build tool and dev server
- React Router - Multi-page navigation
- TailwindCSS - Utility-first CSS framework
- DaisyUI - Component library
- Framer Motion - Animation library
- Axios - HTTP client
TOA_Project/
├── backend/
│ ├── core/
│ │ ├── cfg_generator.py # CFG-based key generation
│ │ ├── entropy.py # Shannon entropy calculation
│ │ └── aes_crypto.py # AES-GCM encryption/decryption
│ ├── routers/
│ │ ├── cfg.py # CFG endpoints
│ │ ├── entropy.py # Entropy endpoints
│ │ └── aes.py # AES endpoints
│ └── main.py # FastAPI application
├── frontend/
│ ├── src/
│ │ ├── pages/
│ │ │ ├── Home.jsx # Landing page
│ │ │ ├── KeyGenerator.jsx # Key generation page
│ │ │ ├── ParseTree.jsx # Parse tree visualization page
│ │ │ └── Encryption.jsx # Encryption/decryption page
│ │ ├── components/
│ │ │ ├── GrammarModeSelection.jsx
│ │ │ ├── KeyGenerator.jsx
│ │ │ ├── ParseTreeVisualization.jsx
│ │ │ ├── EntropyIndicator.jsx
│ │ │ └── AESEncryption.jsx
│ │ └── api/
│ │ └── api.js # API client
│ └── package.json
├── requirements.txt
└── README.md
- Python 3.12+
- Node.js 18+ and npm
- pip (Python package manager)
- Navigate to the project directory:
cd TOA_Project- Install Python dependencies:
pip install -r requirements.txt- Start the backend server:
python -m uvicorn backend.main:app --reload --port 8001The backend API will be available at http://localhost:8001
- API Documentation:
http://localhost:8001/docs - Health Check:
http://localhost:8001/api/health
- Navigate to the frontend directory:
cd frontend- Install Node.js dependencies:
npm install- Start the development server:
npm run devThe frontend application will be available at http://localhost:5174
- Navigate to the Generate page
- Select one or more grammar modes (Numeric, Alphabetic, Alphanumeric, Symbolic)
- Optionally set a key length (default: 16 characters)
- Click Generate Key
- View the generated key, entropy analysis, and parse tree
- After generating a key, click View Parse Tree button
- Or navigate to the Parse Tree page from the menu
- Switch between Stepwise and Tree View modes
- Use controls to step through the derivation process
- Navigate to the Encryption page
- Enter or paste your encryption key
- Enter plaintext to encrypt
- Click Encrypt to get encrypted data and nonce
- Click Decrypt to recover the original plaintext
GET /api/cfg/modes
POST /api/cfg/generate
Body: {
"modes": ["numeric", "alphabetic", "alphanumeric", "symbolic"],
"length": 16 // optional
}
POST /api/entropy/calculate
Body: {
"text": "your_key_here"
}
POST /api/aes/encrypt
Body: {
"plaintext": "text to encrypt",
"key": "encryption_key"
}
POST /api/aes/decrypt
Body: {
"encrypted": "base64_encrypted_data",
"nonce": "base64_nonce",
"key": "encryption_key"
}
- High Entropy Keys: CFG-based generation ensures randomness
- AES-GCM Encryption: Authenticated encryption with Galois/Counter Mode
- PBKDF2 Key Derivation: Secure key derivation from user input
- Unique Nonces: Each encryption uses a unique nonce
- Shannon Entropy Analysis: Mathematical assessment of key strength
- Dark Theme: Professional dark theme with contrasting colors
- Responsive Design: Works on desktop, tablet, and mobile devices
- Smooth Animations: Framer Motion animations for better UX
- Color-Coded Visualization:
- Blue: Nonterminals (Start, Terminal)
- Green: Terminals (actual characters)
- Multi-Page Navigation: Clean separation of features
The CFG generator uses descriptive nonterminal names:
- Start: Root nonterminal
- Terminal: Terminal symbol nonterminal
This allows uppercase letters (A-Z) to be treated as terminals without conflicts.
Start → Terminal Terminal Terminal ...
Terminal → 0 | 1 | 2 | ... | a | b | ... | A | B | ... | ! | @ | ...
The system calculates Shannon entropy using the formula:
H(X) = -Σ P(x) * log₂(P(x))
Where:
P(x)is the probability of characterxin the key- Higher entropy indicates better cryptographic strength
- Port already in use: Change the port in
uvicorncommand or stop the existing process - Module not found: Ensure you're in the project root and dependencies are installed
- CORS errors: Check that the frontend URL is in the CORS allowed origins
- Build errors: Clear
node_modulesand reinstall:rm -rf node_modules && npm install - API connection errors: Verify backend is running on port 8001
- Parse tree not displaying: Ensure you've generated a key first
- Export parse tree as image/PDF
- Key strength recommendations
- Multiple encryption algorithms
- Key history and management
- Custom grammar rule definitions
- Batch key generation
- Key comparison tools