cryptograph 0.1.8

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
* 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 โ†” bits` conversion
* 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`:

```toml
[dependencies]
cryptograph = "0.1"
```

---

## ๐Ÿงช Usage

### Caesar Cipher

```rust
use cryptograph::cryptography::cesar::encrypt;

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

---

### Affine Cipher

```rust
use cryptograph::cryptography::affine::encrypt;

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

---

### Stream Cipher (XOR)

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

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

```rust
use cryptograph::math::multiplicative_inverse;

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

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

### LFSR

```rust
// 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);
```

---

## โš ๏ธ 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.

---