Skip to content

403F2E/Project_init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

project_init

A lightweight and robust Rust library for classical cryptography. This library provides a clean, trait-based design (Cipher) to easily encrypt and decrypt text using classic algorithms, currently supporting both Caesar and Vigenère ciphers.


Architecture

The project is structured to be simple yet powerful:

  • Cipher Trait: The core interface defining cipher and decipher operations.
  • Error Handling: Custom CipherError types built using thiserror to handle invalid alphabet inputs gracefully.
  • High Performance: Built-in lower and upper $26 \times 26$ byte grids (TABULA_RECTA) for fast lookup-based polyalphabetic substitutions.

Requirements & Installation

  • Requirements: Rust toolchain (2024 edition or later).
  • Installation: Add this to your project's Cargo.toml:
[dependencies]
project_init = { path = "path/to/project_init" }

To build the library directly from the source:

cargo build

Usage

Here is how you can use the ciphers in your Rust application. Both implementations automatically preserve capitalization, spacing, and punctuation.

Caesar Cipher

A simple shift cipher requiring a u8 key:

use project_init::{Ceaser, Cipher};

fn main() {
    let caesar = Ceaser::new(3);
    
    let encrypted = caesar.cipher("hello, world").unwrap();
    println!("Encrypted: {}", encrypted); // Output: "khoor, zruog"
    
    let decrypted = caesar.decipher(&encrypted).unwrap();
    println!("Decrypted: {}", decrypted); // Output: "hello, world"
}

Vigenère Cipher

A polyalphabetic cipher requiring an alphabetic keyword:

use project_init::{Cipher, Vigenere};

fn main() {
    let vigenere = Vigenere::new("test");
    
    let encrypted = vigenere.cipher("hello, world").unwrap();
    println!("Encrypted: {}", encrypted); // Output: "aideh, agkeh"
    
    let decrypted = vigenere.decipher(&encrypted).unwrap();
    println!("Decrypted: {}", decrypted); // Output: "hello, world"
}

Progress So Far

  • Core framework: Shared Cipher trait and unified error types powered by thiserror.
  • Tabula Recta grids: Built-in 2D lookup grids for polyalphabetic operations.
  • Caesar cipher: Shifts text with key, preserving non-alphabetic elements.
  • Vigenère cipher: Keyword-based shifting that handles non-alphabetic spaces seamlessly.
  • Testing: Integration tests setup for all cipher implementations (tests/).

To run the test suite:

cargo test

About

a simple rust library that ciphers and deciphers text and messages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages