nrot 2.0.0

simple letter substitution cipher
Documentation
  • Coverage
  • 71.43%
    5 out of 7 items documented2 out of 3 items with examples
  • Size
  • Source code size: 23.67 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 440.98 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • azzamsa/nrot
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • azzamsa

Simple letter substitution cipher 🔐️


Features

  • ROT encryption & decryption
  • Exhaustive testing

Usage

use nrot::{rot, rot_letter, Mode};

fn encrypt(input: String) {
    let rotation = 13;

    let input_length = input.len();
    let input_bytes = input.as_bytes();

    if input_length == 1 {
        let byte_result = rot_letter(Mode::Encrypt, input_bytes[0], rotation);
        println!("{}", String::from_utf8_lossy(&[byte_result]))
    } else {
        let bytes_result = rot(Mode::Encrypt, input_bytes, rotation);
        println!("{}", String::from_utf8_lossy(&bytes_result))
    };
}

fn decrypt(input: String) {
    let rotation = 13;

    let input_length = input.len();
    let input_bytes = input.as_bytes();

    if input_length == 1 {
        let byte_result = rot_letter(Mode::Decrypt, input_bytes[0], rotation);
        println!("{}", String::from_utf8_lossy(&[byte_result]))
    } else {
        let bytes_result = rot(Mode::Decrypt, input_bytes, rotation);
        println!("{}", String::from_utf8_lossy(&bytes_result))
    };
}

fn main() {
    let input = "Hello, world!".to_string();
    encrypt(input);

    let input = "Uryyb, jbeyq!".to_string();
    decrypt(input);
}

To learn more, see other examples.

Credits