Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cryptor"
version = "0.1.3"
version = "0.1.4"
authors = ["atsushi130 <atsushi_main@outlook.jp>"]
license = "MIT/Apache-2.0"
description = "Cryptor is encryption machine corresponding to the diversity of algorithms."
Expand Down
59 changes: 40 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
[![MIT / Apache2.0 dual licensed](https://img.shields.io/badge/dual%20license-MIT%20/%20Apache%202.0-blue.svg)](./LICENSE-MIT.md)
[![Travis Build Status](https://api.travis-ci.org/atsushi130/Cryptor.svg?branch=master)](https://travis-ci.org/atsushi130/Cryptor)
[![crates.io](https://img.shields.io/crates/v/cryptor.svg)](https://crates.io/crates/cryptor)
[![Document](https://img.shields.io/badge/Cryptor-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.3/cryptor/)
[![Document](https://img.shields.io/badge/Cryptor-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.4/cryptor/)

Cryptor is encryption machine corresponding to the diversity of algorithms.

## Dependencies
Insert to Cargo.toml of your project.
```toml
[dependencies]
cryptor = "0.1.3"
cryptor = "0.1.4"
```
or
```console
// Newest version
❯ cargo add cryptor

// Version specification
❯ cargo add cryptor@0.1.3
❯ cargo add cryptor@0.1.4

// If not exist on crates.io
❯ mkdir lib
Expand All @@ -37,15 +37,15 @@ or
Import modules
```rust
extern crate cryptor;
use cryptor::cryptor::{ Cryptor, CryptoValue, Algorithm };
use cryptor::cryptor::{ Cryptor, CryptoValue, CryptoError, Algorithm };
```

Implement structure with this Algorithm trait.
```rust
pub trait Algorithm {
type V: Algorithm;
fn encrypt(&mut self, character: &char) -> CryptoValue<Self::V>;
fn decrypt(&mut self, character: &char) -> CryptoValue<Self::V>;
fn encrypt(&mut self, character: &char) -> Result<CryptoValue<Self::V>, CryptoError>;
fn decrypt(&mut self, character: &char) -> Result<CryptoValue<Self::V>, CryptoError>;
}
```

Expand All @@ -54,13 +54,17 @@ Cryptor have member with Algorithm trait. Dependency injection your implemented
let mut cryptor = Cryptor::new(YourAlgorithm);
```

Return type of encrypt and decrypt method is `CryptoValue<YourAlgorithm>`.
Return type of encrypt and decrypt method is `Result<CryptoValue<YourAlgorithm>, CryptoError>`.
```rust
let encrypted: CryptoValue<YourAlgorithm> = cryptor.encrypt(&string);
println!("encrypted string is {}", encrypted.text);
match cryptor.encrypt(&string) {
Ok(ref crypted) => println!("crypted: {}", crypted.text),
Err(ref error) => println!("{}", error)
}

let decrypted: CryptoValue<YourAlgorithm> = cryptor.decrypt(&string);
println!("decrypted string is {}", decrypted.text);
match cryptor.decrypt(&string) {
Ok(ref crypted) => println!("crypted: {}", crypted.text),
Err(ref error) => println!("{}", error)
}
```

## Run
Expand All @@ -77,21 +81,38 @@ println!("decrypted string is {}", decrypted.text);
```

## Change logs
**v0.1.3**
Defined associated function to builds new Cryptor.
**v0.1.4**
Add exception of Cryptor and Enigma.

**CryptoError**
```rust
pub enum CryptoError {
InvalidString(String),
InvalidByte(usize, u8, DecodeError),
InvalidLength(DecodeError),
UTF8Error(FromUtf8Error)
}
```

**EnigmaError**
```rust
impl<T: Algorithm> Cryptor<T> {
pub fn new(algorithm: T) -> Self {
Cryptor {
algorithm
}
}
pub enum EnigmaError {
InvalidLength
}
```

**changed usage**
```rust
let mut cryptor = Cryptor::new(your_algorithm);
match cryptor.encrypt(string) {
Ok(ref crypted) => println!("crypted: {}", crypted.text),
Err(ref error) => println!("{}", error)
}

match cryptor.decrypt(string) {
Ok(ref crypted) => println!("crypted: {}", crypted.text),
Err(ref error) => println!("{}", error)
}
```

## LICENSE
Expand Down
14 changes: 9 additions & 5 deletions src/cryptor/algorithm/base64/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base64
[![Base64](https://img.shields.io/badge/Cryptor-Base64-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/base64)
[![Document](https://img.shields.io/badge/Base64-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.3/cryptor/cryptor/struct.Base64.html)
[![Document](https://img.shields.io/badge/Base64-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.4/cryptor/cryptor/struct.Base64.html)

## Usage
**Import modules**
Expand All @@ -17,13 +17,17 @@ let mut cryptor = Cryptor::new(Base64);

**Encryption**
```rust
let encrypted: CryptoValue<Base64> = cryptor.encrypt(&"A quick brown fox jumps over the lazy dog.");
println!("encrypted: {}", encrypted.text);
match cryptor.encrypt("A quick brown fox jumps over the lazy dog.") {
Ok(ref crypted) => println!("crypted: {}", crypted.text),
Err(ref error) => println!("{}", error)
}
```

**Decryption**
```rust
let decrypted: CryptoValue<Base64>> = cryptor.encrypt(&encrypted);
println!("decrypted: {}", decrypted); // decrypted: A quick brown fox jumps over the lazy dog.
match cryptor.decrypt(&string) {
Ok(ref crypted) => println!("crypted: {}", crypted.text), // crypted: A quick brown fox jumps over the lazy dog.
Err(ref error) => println!("{}", error)
}
```

21 changes: 14 additions & 7 deletions src/cryptor/algorithm/enigma/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Enigma
[![Enigma](https://img.shields.io/badge/Cryptor-Enigma-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/enigma)
[![Document](https://img.shields.io/badge/Enigma-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.3/cryptor/cryptor/struct.Enigma.html)
[![Document](https://img.shields.io/badge/Enigma-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.4/cryptor/cryptor/struct.Enigma.html)

## Usage
**Import modules**
Expand Down Expand Up @@ -32,18 +32,25 @@ let mut cryptor = Cryptor::new(enigma);

**Encryption**
```rust
let encrypted: CryptoValue<Enigma> = cryptor.encrypt(&"A quick brown fox jumps over the lazy dog.");
println!("encrypted: {}", encrypted.text);
match cryptor.encrypt(&"A quick brown fox jumps over the lazy dog.") {
Ok(ref crypted) => println!("crypted: {}", crypted.text),
Err(ref error) => println!("{}", error)
}
```

**Decryption**
```rust
let decrypted: CryptoValue<Enigma> = cryptor.encrypt(&encrypted);
println!("decrypted: {}", decrypted); // decrypted: A quick brown fox jumps over the lazy dog.
match cryptor.decrypt(&string) {
Ok(ref crypted) => println!("crypted: {}", crypted.text), // crypted: A quick brown fox jumps over the lazy dog.
Err(ref error) => println!("{}", error)
}
```

**Set router's position**
To set the position, specify a character string. The length of the specified string must be equal to the number of routers.
```
cryptor.algorithm.set_positons("ABC");
```rust
match cryptor.algorithm.set_positons("ABC") {
Ok(_) => println!("set positions."),
Err(ref error) => println!("{}", error)
}
```