cryptograph 0.1.5

All you need for encrypthing your messages.
Documentation

๐Ÿ” 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
  • 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 โ†” bits conversion
  • Bitwise operations utilities

๐Ÿ“ฅ 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);

โš ๏ธ 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/
โ”‚
โ””โ”€โ”€ utils/
    โ””โ”€โ”€ bits/

๐Ÿ›  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.