Skip to content

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.

License

Notifications You must be signed in to change notification settings

abdorrahmani/CryptoLens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CryptoLens πŸ”

Go Version License Go Report Card GoDoc PRs Welcome Release Security Tests Coverage Platform

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

go install github.com/abdorrahmani/cryptolens@latest

From Source

# 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:

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

# 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 for details.

Quick Start for Contributors

# 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 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

About

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.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages