cryptograph 0.1.11

All you need for encrypthing your messages.
Documentation

๐Ÿ” Cryptograph

Educational cryptography library written in Rust


๐Ÿ“ฆ Overview

cryptograph is a Rust library that implements fundamental concepts from cryptography, bit manipulation, and number theory, with a focus on clarity, learning, and low-level understanding.

This crate is designed for:

  • Learning cryptography
  • Understanding cipher construction
  • Practicing bitwise programming in Rust
  • Exploring pseudorandom generators

๐Ÿš€ Features

๐Ÿ”‘ Cryptography

  • Caesar Cipher
  • Affine Cipher
  • Stream Cipher (XOR-based)
  • DES (Data Encryption Standard)

๐Ÿ”„ Pseudorandom Generators

  • FlipFlop โ€” 1-bit memory cell
  • LFSR โ€” Linear Feedback Shift Register

โš™๏ธ Bit Manipulation

  • bytes โ†” bits conversion
  • Bitwise utilities

๐Ÿง  Mathematics

  • Euclidean Algorithm (GCD)
  • Extended Euclidean Algorithm (Bรฉzout)
  • Modular Multiplicative Inverse

๐Ÿ“ฅ Installation

Add this to your Cargo.toml:

[dependencies]
cryptograph = "0.1"

๐Ÿงช Usage

Caesar Cipher

use cryptograph::cryptography::cesar::encrypt;

let encrypted = encrypt("HELLO", 3);
println!("{}", encrypted); // KHOOR

Affine Cipher

use cryptograph::cryptography::affine::encrypt;

let encrypted = encrypt("HELLO", 5, 8);
println!("{}", encrypted);

Stream Cipher (XOR)

use cryptograph::cryptography::streams_ciphers::encrypt;

let msg = b"hello";
let key = b"key";

let encrypted = encrypt(msg, key);
let decrypted = encrypt(&encrypted, key); // XOR is symmetric

assert_eq!(msg, decrypted);

Bit Manipulation

use cryptograph::utils::bits::{bytes_to_bits, bits_to_bytes};

let bytes = vec![0b10100001];

let bits = bytes_to_bits(&bytes);
let reconstructed = bits_to_bytes(&bits).unwrap();

assert_eq!(bytes, reconstructed);

Modular Inverse

use cryptograph::math::multiplicative_inverse;

let inv = multiplicative_inverse(5, 7).unwrap();

assert_eq!((5 * inv) % 7, 1);

LFSR

// Create a 4-bit LFSR
let ff = vec![
    FlipFlop::new(true),
    FlipFlop::new(false),
    FlipFlop::new(true),
    FlipFlop::new(false),
];

// Initialize the LFSR
let mut lfsr = Lsfr::new(ff);

// 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!("Possible states: {}", possibilities);

DES (Data Encryption Standard)

let plaintext = 0x0123456789ABCDEF;
let key = 0x133457799BBCDFF1;

let des = Des::new(plaintext);
let encrypted = des.encrypt(key);

println!("{:016X}", encrypted);

โš ๏ธ 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/
โ”‚   โ”œโ”€โ”€ des/
โ”‚   โ””โ”€โ”€ streams_ciphers/
โ”‚
โ”œโ”€โ”€ math/
โ”‚   โ”œโ”€โ”€ euclides/
โ”‚   โ”œโ”€โ”€ bezout/
โ”‚   โ””โ”€โ”€ multiplicative_inverse/
โ”‚
โ”œโ”€โ”€ tools/
โ”‚   โ””โ”€โ”€ flip_flop.rs
โ”‚
โ””โ”€โ”€ pseudorandom_generator/
    โ””โ”€โ”€ lfsr.rs

๐Ÿค 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
  • pseudorandom number generator

If you're learning cryptography or low-level Rust, this crate is for you.