Skip to content

Cryptor is encryption machine corresponding to the diversity of algorithms.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE.md
MIT
LICENSE-MIT.md
Notifications You must be signed in to change notification settings

atsushi130/Cryptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cryptor

MIT / Apache2.0 dual licensed Travis Build Status crates.io Document

Cryptor is encryption machine corresponding to the diversity of algorithms.

Dependencies

Insert to Cargo.toml of your project.

[dependencies]
cryptor = "0.1.3"

or

// Newest versioncargo add cryptor

// Version specificationcargo add [email protected]

// If not exist on crates.iomkdir libcd libgit clone https://github.com/atsushi130/Cryptorcd ..cargo add cryptor --path=lib/cryptor/

Default crypto algorithm

  • Enigma
  • Base64

Usage

Import modules

extern crate cryptor;
use cryptor::cryptor::{ Cryptor, CryptoValue, Algorithm };

Implement structure with this Algorithm trait.

pub trait Algorithm {
    type V: Algorithm;
    fn encrypt(&mut self, character: &char) -> CryptoValue<Self::V>;
    fn decrypt(&mut self, character: &char) -> CryptoValue<Self::V>;
}

Cryptor have member with Algorithm trait. Dependency injection your implemented structure to Cryptor.

let mut cryptor = Cryptor::new(YourAlgorithm);

Return type of encrypt and decrypt method is CryptoValue<YourAlgorithm>.

let encrypted: CryptoValue<YourAlgorithm> = cryptor.encrypt(&string);
println!("encrypted string is {}", encrypted.text);

let decrypted: CryptoValue<YourAlgorithm> = cryptor.decrypt(&string);
println!("decrypted string is {}", decrypted.text);

Run

cargo buildcargo run

Test

cargo test

Change logs

v0.1.3
Defined associated function to builds new Cryptor.

impl<T: Algorithm> Cryptor<T> {
    pub fn new(algorithm: T) -> Self {
        Cryptor {
            algorithm
        }
    }
}

changed usage

let mut cryptor = Cryptor::new(your_algorithm);

LICENSE

This project is dual-licensed under MIT and Apache 2.0.