๐ Cryptograph
Educational cryptography library in Rust
๐ฆ Overview
cryptograph is a Rust library that implements fundamental concepts from cryptography and number theory, with a focus on clarity, learning, and low-level understanding.
It includes:
- Classical ciphers (Caesar, Affine)
- Stream cipher primitives
- Pseudorandom bit generators (FlipFlop & LFSR)
- Bit-level utilities
- Number theory algorithms (Euclidean algorithm, Bรฉzout, modular inverse)
๐ Features
๐ Cryptography
- Caesar Cipher
- Affine Cipher
- Stream Cipher (XOR-based)
๐ง Mathematics
- Euclidean Algorithm (GCD)
- Extended Euclidean Algorithm (Bรฉzout)
- Modular Multiplicative Inverse
โ๏ธ Bit Manipulation
bytes โ bitsconversion- Bitwise operations utilities
๐ Pseudorandom Generators
- FlipFlop: a single 1-bit memory cell that can be toggled or set
- Lsfr: Linear Feedback Shift Register, classical pseudorandom bit generator
๐ฅ Installation
Add this to your Cargo.toml:
[]
= "0.1"
๐งช Usage
Caesar Cipher
use encrypt;
let encrypted = encrypt;
println!; // KHOOR
Affine Cipher
use encrypt;
let encrypted = encrypt;
println!;
Stream Cipher (XOR)
use encrypt;
let msg = b"hello";
let key = b"key";
let encrypted = encrypt;
let decrypted = encrypt; // XOR is symmetric
assert_eq!;
Bit Manipulation
use ;
let bytes = vec!;
let bits = bytes_to_bits;
let reconstructed = bits_to_bytes.unwrap;
assert_eq!;
Modular Inverse
use multiplicative_inverse;
let inv = multiplicative_inverse.unwrap;
assert_eq!;
LFSR
// Create a 4-bit LFSR
let ff = vec!;
// Initialize the LFSR
let mut lfsr = new;
// Rotate the LFSR (advance one step)
lfsr.rotate;
// Get the current state of the flip-flops
let state = lfsr.get;
// Calculate the total number of possible LFSR states
let possibilities = lfsr.calculate_possibilities;
println!;
โ ๏ธ Security Notice
This library is intended for educational purposes only.
- โ Not audited
- โ Not constant-time
- โ Not safe for production cryptography
For real-world use, consider libraries like:
- RustCrypto
- ring
๐ง Design Goals
- Simplicity over performance
- Explicit bit-level control
- Clear mathematical foundations
- Modular architecture
๐ Project Structure
cryptograph/
โโโ cryptography/
โ โโโ cesar/
โ โโโ affine/
โ โโโ streams_ciphers/
โ
โโโ math/
โ โโโ euclides/
โ โโโ bezout/
โ โโโ multiplicative_inverse/
โ
โโโ tools/
โ โโโ flip_flop.rs
โ
โโโ pseudorandom_generator/
โโโ lfsr.rs
๐ Future Improvements
- Replace
Vec<bool>with bit-packed representations - Add more secure stream cipher implementations
- Improve UTF-8 handling
- Add benchmarks and optimizations
๐ค Contributing
Contributions are welcome!
You can help by:
- Improving documentation
- Adding tests
- Optimizing implementations
- Extending cryptographic primitives
๐ License
MIT
๐ก Author Notes
This project is built to deeply understand:
- Bitwise operations
- Modular arithmetic
- Cipher design
If you're learning cryptography or low-level Rust, this crate is for you.