An open API service indexing awesome lists of open source software.

https://github.com/abdorrahmani/cryptolens

CryptoLens is an educational CLI tool designed to help users understand various encryption methods and their underlying principles. It provides step-by-step visual explanations of different encryption algorithms and their processes, making cryptography concepts more accessible and easier to understand.
https://github.com/abdorrahmani/cryptolens

aes-encryption anophel base64 caesar-cipher cryptography cryptolens go golang hmac jwt jwt-decode pbkdf rsa sha256-hash

Last synced: 3 months ago
JSON representation

CryptoLens is an educational CLI tool designed to help users understand various encryption methods and their underlying principles. It provides step-by-step visual explanations of different encryption algorithms and their processes, making cryptography concepts more accessible and easier to understand.

Awesome Lists containing this project

README

          

# CryptoLens ๐Ÿ”

[![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat&logo=go)](https://golang.org)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/abdorrahmani/cryptolens)](https://goreportcard.com/report/github.com/abdorrahmani/cryptolens)
[![GoDoc](https://godoc.org/github.com/abdorrahmani/cryptolens?status.svg)](https://godoc.org/github.com/abdorrahmani/cryptolens)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
[![Release](https://img.shields.io/github/v/release/abdorrahmani/cryptolens?include_prereleases&sort=semver)](https://github.com/abdorrahmani/cryptolens/releases)
[![Security](https://img.shields.io/badge/Security-Audited-brightgreen.svg)](SECURITY.md)
[![Tests](https://img.shields.io/badge/Tests-Passing-brightgreen.svg)](https://github.com/abdorrahmani/cryptolens/actions)
[![Coverage](https://img.shields.io/badge/Coverage-90%25-brightgreen.svg)](https://codecov.io/gh/abdorrahmani/cryptolens)
[![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux%20%7C%20macOS-blue.svg)](https://github.com/abdorrahmani/cryptolens/releases)


CryptoLens Logo


Your Interactive Cryptography Learning Tool


CryptoLens Command Line Interface


Interactive Command Line Interface

## ๐Ÿ“– Overview
CryptoLens is an educational CLI tool designed to help users understand various encryption methods and their underlying principles. It provides step-by-step visual explanations of different encryption algorithms and their processes, making cryptography concepts more accessible and easier to understand.

## ๐ŸŒŸ Highlights

- ๐ŸŽ“ **Educational Focus**: Perfect for learning cryptography concepts
- ๐Ÿ” **Multiple Algorithms**: Support for various encryption methods
- ๐Ÿ“Š **Visual Learning**: Step-by-step process visualization
- ๐Ÿ”’ **Security First**: Best practices and security considerations
- ๐Ÿš€ **Modern Features**: Latest cryptographic standards
- ๐ŸŽจ **Beautiful UI**: Colored output and ASCII art
- ๐Ÿ“ฑ **Cross-Platform**: Works on Windows, Linux, and macOS
- ๐Ÿ”„ **Active Development**: Regular updates and improvements

## ๐Ÿ† Features in Numbers

- 10+ Encryption Methods
- 6 HMAC Algorithms
- 3 PBKDF Implementations
- 2 Key Exchange Protocols
- 3 JWT Algorithms
- 90%+ Test Coverage
- 100% Security Audited
- 24/7 Community Support

# ๐Ÿ“š Supported Algorithms

Each algorithm below is fully documented in the [`/docs`](./docs) folder. See the linked docs for in-depth technical details, security notes, and troubleshooting.

## โœจ Features

### ๐Ÿ”„ Multiple Encryption Methods
- **Base64 Encoding**
- Binary-to-text encoding
- Step-by-step visualization of the encoding process
- ASCII and binary representations
- Support for both encoding and decoding operations

- **Caesar Cipher**
- Classical substitution cipher
- Character-by-character transformation
- Alphabet shift visualization
- Customizable shift value
- Support for both encryption and decryption

- **AES Encryption**
- Modern symmetric encryption (AES-256)
- Block cipher operations
- Secure key and IV handling
- Support for both encryption and decryption
- Automatic key generation

- **ChaCha20-Poly1305**
- Modern stream cipher with AEAD
- High-performance encryption
- Authentication and encryption in one operation
- Support for both encryption and decryption
- Secure nonce handling

- **SHA-256 Hashing**
- Cryptographic hash function
- One-way transformation
- Hash value generation
- Input validation and error handling

- **RSA Encryption**
- Asymmetric encryption (RSA-2048)
- Public/private key pair generation
- Secure key storage in project directory
- Support for both encryption and decryption
- Automatic key pair management
- Base64 encoded output for encrypted data

- **HMAC Authentication**
- Hash-based Message Authentication Code
- Multiple hash algorithm support:
- SHA-1 (legacy, not recommended)
- SHA-256 (widely used)
- SHA-512 (higher security margin)
- BLAKE2b-256 (faster alternative)
- BLAKE2b-512 (high performance)
- BLAKE3 (latest generation)
- Real-time performance measurements
- Detailed algorithm information
- Step-by-step HMAC process visualization
- Secure key management
- Output in both Hex and Base64 formats
- Built-in benchmarking tool:
- Compare performance of all HMAC algorithms
- Customizable number of iterations
- Sample text input
- Performance recommendations
- Detailed timing statistics
- Percentage-based performance comparison
- Interactive loading animation
- Colored ASCII art visualization
- Proportional scaling for performance bars

- **Password-Based Key Derivation**
- Multiple algorithm support:
- PBKDF2 (Password-Based Key Derivation Function 2)
- Argon2id (Memory-Hard Function)
- Scrypt (Memory-Hard Function)
- Configurable parameters:
- Iterations/work factor
- Memory usage (for Argon2id and Scrypt)
- Threads (for Argon2id)
- Key length
- Secure salt generation
- One-way key derivation
- Detailed parameter information
- Security recommendations
- Base64 encoded output
- Colored ASCII art visualization for benchmarks

- **Diffie-Hellman Key Exchange**
- Authenticated key exchange implementation
- RSA key pairs for Alice and Bob
- SHA-256 hashing before RSA signing
- Signature verification for key authenticity
- AES-GCM encryption using derived shared secret
- TLS-like protocol demonstration
- MITM prevention measures
- Performance comparison with X25519

- **X25519 Key Exchange**
- Modern Curve25519 implementation
- HKDF key derivation
- AES-GCM encryption demo
- Proper scalar validation
- Performance benchmarking
- TLS 1.3 connection flow
- Professional ASCII diagrams
- Security best practices

- **JWT Support**
- Multiple algorithm support:
- HS256 (HMAC with SHA-256)
- RS256 (RSA with SHA-256)
- EdDSA (Edwards-curve Digital Signature Algorithm)
- JWT processor configuration
- Secret key management
- Token generation and verification
- Claims handling
- Expiration management

### ๐ŸŽฏ Attack Simulations
- **ECB Mode Vulnerability**
- Demonstrates the weakness of Electronic Codebook (ECB) mode
- Shows how patterns in plaintext are preserved in ciphertext
- Visual representation of block patterns
- Real-world examples of ECB vulnerabilities

- **Nonce Reuse in AEAD**
- Simulates the catastrophic effects of nonce reuse in ChaCha20-Poly1305
- Demonstrates how nonce reuse breaks confidentiality
- Shows practical examples of nonce reuse attacks
- Best practices for nonce management

- **Timing Attack on HMAC**
- Simulates timing side-channel attacks on HMAC verification
- Demonstrates constant-time comparison importance
- Shows how timing differences can leak information
- Countermeasures and secure implementations

- **Brute Force Attacks**
- Simulates brute force attacks on weak keys and passwords
- Demonstrates password strength importance
- Shows time estimates for different key lengths
- Best practices for key and password generation

- **JWT None Algorithm Attack**
- Demonstrates the vulnerability of accepting "none" algorithm
- Shows how to forge valid JWTs without a secret
- Explains proper JWT algorithm validation
- Security best practices for JWT implementation

### ๐ŸŽฏ Key Features
- Interactive CLI interface with intuitive menu system
- Real-time step-by-step encryption process visualization
- Detailed explanations of each algorithm's principles
- Binary, hexadecimal, and ASCII representations
- Educational notes and security considerations
- Input validation and error handling
- Factory pattern for encryption method selection
- Modular and extensible architecture
- Secure key storage in project directory
- Cross-platform compatibility (Windows, Linux, macOS)
- Performance measurements for HMAC algorithms
- Comprehensive algorithm information display
- Interactive loading animations for long operations
- Version number display in welcome message
- Colored ASCII art visualization for benchmarks
- TLS 1.3 connection flow documentation
- Professional ASCII diagrams for key exchange
- Security warnings and best practices

## ๐Ÿš€ Installation

### Prerequisites
- Go 1.21 or higher
- Git (for installation from source)

### Using Go Install
```bash
go install github.com/abdorrahmani/cryptolens@latest
```

### From Source
```bash
# Clone the repository
git clone https://github.com/abdorrahmani/cryptolens.git

# Navigate to project directory
cd cryptolens

# Build the project
go build -o cryptolens cmd/cryptolens/main.go

# Move the binary to your PATH (optional)
mv cryptolens /usr/local/bin/
```

## ๐Ÿ’ป Usage

### Basic Usage
Run the program:
```bash
cryptolens
```

### Interactive Menu
The program will present you with an interactive menu:
1. Choose an encryption method (1-10)
2. Enter your text
3. View the detailed encryption process and explanation
4. See the final result

### Key Storage
- Encryption keys are stored in the `keys` directory in the project root
- RSA keys are stored as PEM files
- AES keys are stored as binary files
- HMAC keys are stored as binary files
- The `keys` directory is automatically created on first run
- Keys are securely stored with appropriate file permissions

### Example Output
```
Encryption Process Visualization:
=================================
Base64 Encoding Process
=====================
Original Text: Hello
โ†“
ASCII Values: 48 65 6c 6c 6f
โ†“
Binary Representation: 01001000 01100101 01101100 01101100 01101111
โ†“
Base64 Encoded: SGVsbG8=
=================================

Decryption Process Visualization:
=================================
Base64 Decoding Process
=====================
Base64 Encoded Text: SGVsbG8=
โ†“
ASCII Values: 48 65 6c 6c 6f
โ†“
Binary Representation: 01001000 01100101 01101100 01101100 01101111
โ†“
Decoded Text: Hello
=================================

HMAC Example (SHA-256):
=================================
HMAC Process
Input Text: Hello
โ†“
HMAC Key: [secure key]
โ†“
HMAC Result (Hex): [64 characters]
HMAC Result (Base64): [44 characters]
=================================

PBKDF Example (Argon2id):
=================================
Using argon2id for key derivation
Salt (base64): [random salt]
โ†“
Argon2id Parameters:
- Iterations: 100000
- Memory: 65536 KB
- Threads: 4
- Key Length: 256 bits
โ†“
Derived Key (base64): [derived key]
=================================

X25519 Key Exchange:
=================================
Alice's Public Key: [32 bytes]
Bob's Public Key: [32 bytes]
โ†“
Shared Secret: [32 bytes]
โ†“
AES-GCM Encrypted Message: [encrypted data]
=================================

JWT Example (RS256):
=================================
JWT Header: {"alg":"RS256","typ":"JWT"}
โ†“
JWT Payload: {"sub":"1234567890","name":"John Doe"}
โ†“
JWT Signature: [signature]
โ†“
Final JWT: [header].[payload].[signature]
=================================
```

# ๐Ÿ“ Project Structure

```
cryptolens/
โ”œโ”€โ”€ cmd/
โ”‚ โ””โ”€โ”€ cryptolens/
โ”‚ โ””โ”€โ”€ main.go # Application entry point
โ”œโ”€โ”€ internal/
โ”‚ โ”œโ”€โ”€ crypto/ # Encryption implementations
โ”‚ โ”‚ โ”œโ”€โ”€ base64.go # Base64 encoding/decoding
โ”‚ โ”‚ โ”œโ”€โ”€ caesar.go # Caesar cipher implementation
โ”‚ โ”‚ โ”œโ”€โ”€ aes.go # AES encryption/decryption
โ”‚ โ”‚ โ”œโ”€โ”€ chacha20poly1305.go # ChaCha20-Poly1305 implementation
โ”‚ โ”‚ โ”œโ”€โ”€ sha256.go # SHA-256 hashing
โ”‚ โ”‚ โ”œโ”€โ”€ rsa.go # RSA encryption/decryption
โ”‚ โ”‚ โ”œโ”€โ”€ hmac.go # HMAC implementation
โ”‚ โ”‚ โ”œโ”€โ”€ pbkdf.go # PBKDF implementation
โ”‚ โ”‚ โ”œโ”€โ”€ dh.go # Diffie-Hellman implementation
โ”‚ โ”‚ โ”œโ”€โ”€ x25519.go # X25519 implementation
โ”‚ โ”‚ โ”œโ”€โ”€ jwt.go # JWT implementation
โ”‚ โ”‚ โ”œโ”€โ”€ interfaces.go # Encryption processor interface
โ”‚ โ”‚ โ””โ”€โ”€ keymanager.go # Key management
โ”‚ โ”œโ”€โ”€ cli/ # CLI interface components
โ”‚ โ”‚ โ”œโ”€โ”€ menu.go # Interactive menu system
โ”‚ โ”‚ โ”œโ”€โ”€ display.go # Output formatting
โ”‚ โ”‚ โ”œโ”€โ”€ input.go # User input handling
โ”‚ โ”‚ โ”œโ”€โ”€ interfaces.go # Interface definitions
โ”‚ โ”‚ โ””โ”€โ”€ factory.go # Encryption method factory
โ”‚ โ”œโ”€โ”€ config/ # Configuration management
โ”‚ โ”‚ โ””โ”€โ”€ config.go # Configuration handling
โ”‚ โ”œโ”€โ”€ utils/ # Utility functions
โ”‚ โ”‚ โ”œโ”€โ”€ visualizer.go # Process visualization
โ”‚ โ”‚ โ””โ”€โ”€ theme.go # Color theme management
โ”‚ โ”œโ”€โ”€ input/ # Input handling
โ”‚ โ”‚ โ””โ”€โ”€ input.go # Input processing
โ”‚ โ””โ”€โ”€ benchmark/ # Benchmarking tools
โ”‚ โ””โ”€โ”€ benchmark.go # Performance measurement
โ”œโ”€โ”€ keys/ # Encryption keys storage
โ”‚ โ”œโ”€โ”€ rsa_private.pem # RSA private key
โ”‚ โ”œโ”€โ”€ rsa_public.pem # RSA public key
โ”‚ โ”œโ”€โ”€ aes_key.bin # AES key
โ”‚ โ”œโ”€โ”€ hmac_key.bin # HMAC key
โ”‚ โ”œโ”€โ”€ dh_private.pem # DH private key
โ”‚ โ”œโ”€โ”€ dh_public.pem # DH public key
โ”‚ โ”œโ”€โ”€ x25519_private.pem # X25519 private key
โ”‚ โ””โ”€โ”€ x25519_public.pem # X25519 public key
โ”œโ”€โ”€ assets/ # Project assets
โ”œโ”€โ”€ config/ # Configuration files
โ”‚ โ””โ”€โ”€ config.yaml # Default configuration
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md
```

## ๐Ÿ”ง Development

### Building from Source
```bash
# Clone the repository
git clone https://github.com/abdorrahmani/cryptolens.git

# Navigate to project directory
cd cryptolens

# Build the project
go build -o cryptolens cmd/cryptolens/main.go

# Run tests
go test ./...
```

### Adding New Features
1. Create a new encryption implementation in `internal/crypto/`
2. Implement the required interfaces
3. Add the new method to the factory in `internal/cli/factory.go`
4. Update the menu system in `internal/cli/menu.go`
5. Add appropriate tests
6. Update configuration in `config/config.yaml`

## ๐Ÿค Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Quick Start for Contributors
```bash
# Fork and clone
git clone https://github.com/abdorrahmani/cryptolens.git
cd cryptolens

# Install dependencies
go mod download

# Run tests
go test ./...

# Build
go build -o cryptolens cmd/cryptolens/main.go
```

### Development Guidelines
- Follow Go best practices
- Write comprehensive tests
- Update documentation
- Add examples
- Follow security guidelines

## ๐Ÿ“Š Performance

### HMAC Benchmark Results
```
Algorithm | Time (ยตs) | Relative Speed
-------------|-----------|---------------
BLAKE3 | 0.5 | 100%
BLAKE2b-512 | 0.8 | 62.5%
SHA-512 | 1.2 | 41.7%
SHA-256 | 1.5 | 33.3%
SHA-1 | 1.8 | 27.8%
```

### PBKDF Benchmark Results
```
Algorithm | Time (ms) | Memory (MB) | Security Level
----------|-----------|-------------|---------------
Argon2id | 100 | 64 | High
Scrypt | 120 | 32 | High
PBKDF2 | 150 | 1 | Medium
```

## ๐ŸŽฏ Use Cases

- ๐ŸŽ“ **Education**: Learn cryptography concepts
- ๐Ÿ” **Development**: Test encryption implementations
- ๐Ÿ”’ **Security**: Verify cryptographic operations
- ๐Ÿ“š **Research**: Experiment with different algorithms
- ๐Ÿ› ๏ธ **Testing**: Validate cryptographic functions
- ๐Ÿ“Š **Benchmarking**: Compare algorithm performance

## ๐Ÿ“ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Go Standard Library for cryptographic functions
- The cryptography community for educational resources
- BLAKE3 team for their fast and secure hash function
- All contributors who help improve this project

## ๐Ÿ“ซ Contact

- GitHub: [@abdorrahmani](https://github.com/abdorrahmani)
- Project Link: [https://github.com/abdorrahmani/cryptolens](https://github.com/abdorrahmani/cryptolens)