4 releases

0.2.7 Jan 3, 2024
0.2.6 Dec 26, 2023
0.2.3 Dec 9, 2023
0.2.2 Dec 9, 2023

#509 in Cryptography

41 downloads per month

MIT and LGPL-3.0+

215KB
4K SLoC

Ferric Crypto Lib

This Lib is in pre-pre-pre-pre-alpha at the moment and therefore cannot be trusted in prod, also the documentation is not accurate at the moment

This is a collection of cryptographic algorithms implemented in Rust for use during the crypto courses I attend.

The structure of the project might change in the future, but for now it is a single crate with all the algorithms implemented as functions. In the future I might make structs for each algorithm and implement the Encrypt and Decrypt traits for them.

Implemented Algorithms

  • Affine Hill (Custom algorithm)
  • Bernel-Fibonaccis (Custom algorithm)
  • Bifid Chiffre
  • Ceasar
  • DES
  • Dubbel Sick-Sack (Custom algorithm)
  • Enigma
  • Kid-RSA (Custom algorithm)
  • Minigma (Custom algorithm)
  • Hill (no decrypt yet, but simple to do by hand to get a new key)
  • Monoalphabetic
  • MIX (Custom algorithm)
  • Sick-Sack (Custom algorithm)
  • Transposition (no decrypt yet)
  • TrissDES (Custom algorithm)
  • Vernam
  • Vernam (LKG28)
  • Vigenere
  • Vokkon (Custom algorithm)

Usage

Add to your project

Add the following to your Cargo.toml:

From Gitlab

[dependencies]
ferric_crypto_lib = { git = "https://gitlab.com/ferric1/ferric_crypto.git" }

From Path

[dependencies]
ferric_crypto_lib = { path = "/path/to/ferric_crypto" }

Use in your code

All algorithms are implemented as functions in the ferric_crypto_lib crate. To use them, simply import the crate and call the function you want to use. All encryption functions are withing the encrypt module and all decryption functions are within the decrypt module.

Example

TODO: fix example

use ferric_crypto_lib::encrypt::ceasar::*;
use ferric_crypto_lib::decrypt::ceasar::*;

fn main() {
    let encrypted = encrypt("Hello World");
    let decrypted = decrypt(&encrypted);
    println!("Encrypted: {}", encrypted);
    println!("Decrypted: {}", decrypted);
}

Building

Prerequisites

You will need some tools to build the library, click the links to go to the instructions for installing them:

After installing the prerequisites, follow these steps to build:

1. Clone the repository

Using HTTPS

```bash
git clone https://gitlab.com/ferric1/ferric_crypto.git
```

Using SSH

```bash
git clone git@gitlab.com:ferric1/ferric_crypto.git
```

2. Test the library

This is optional, but recommended

just test

3. Build the library

Build for Rust

just build

Build for Python

Here you need Maturin in order to build

just build-py

4. Install the library

If you intend to use the library in a python project, you need to install it. This is done with the following command:

just install-py

This will force install it to your python environment, this is so we dont need to remove it before installing a new version during development.

Development

Adding Crypto Algorithms

To add a new algorithm, simply run this command:

just add-algo <name>

This will create a new file in the src folder with the name <name>.rs and add the following code to it:

use crate::error::CharacterParseError;
use crate::Traits::{Encrypt, Decrypt};

/// Enum representing possible errors in the name cipher.
#[derive(Debug, PartialEq)]
pub enum nameError {
    CharacterParseError(CharacterParseError),
    // Define error variants here
}

/// Represents a name cipher.
#[cfg_attr(feature = "python-integration", pyclass)]
pub struct name {
    // Define struct fields here
}

impl name {
    // Define methods here
    fn new() -> Self {
        Self {
            // Define struct fields here
        }
    }
}

#[cfg(feature = "python-integration")]
mod python_integration {
    use super::*;
    use pyo3::prelude::*;
    use pyo3::{pyclass, PyResult, pymethods};

    #[pymethods]
    impl name {
        // Define Python integration methods here
    }
}

Where we replace name with the name of the new algorithm. This will also add the new algorithm to the mod.rs file inside the src/crypto_systems folder. We also make new standard files for the Encrypt, Decrypt and BruteForce traits in their respective modules, this is where the implementations of the algorithm will go.

You will also need to add the new algorithm to the lib.rs file where we define our python module.

License

This project is licensed under the MIT License - see the LICENSE file for details

Owner

Dependencies

~33MB
~667K SLoC