playfair_cipher

Crates.ioplayfair_cipher
lib.rsplayfair_cipher
version0.3.5
sourcesrc
created_at2023-01-14 10:53:21.522272
updated_at2024-03-01 20:12:25.921107
descriptionImplementation of Playfair, Two square and Four square cipher
homepagehttps://github.com/sdoerig/playfair_cipher
repositoryhttps://github.com/sdoerig/playfair_cipher
max_upload_size
id758789
size82,468
Stefan Dörig (sdoerig)

documentation

README

General

The crate contains the playfair, the two square and the four square cipers. Note all are pre computer cipers. Do not feel like protecting data of any value with them. Any of those are crackable in very short time.

When using the method encrypt the payload is converted to uppercase and any character not within the range A..I and K..Z is ignored. E.g. "I would like 4 tins of jam." becomes "IWOULDLIKETINSOFIAM". So you don't need to clear off not encryptable characters when using this library.

playfair_cipher

Implementation of the PlayFair cipher - nothing special, nothing useful, just for fun.

Encrypt

use playfair_cipher::{playfair::PlayFairKey, errors::CharNotInKeyError};
use use playfair_cipher::cryptable::Cypher;

let pfc = PlayFairKey::new("playfair example");
match pfc.encrypt("hide the gold in the tree stump") {
  Ok(crypt) => {
    assert_eq!(crypt, "BMODZBXDNABEKUDMUIXMMOUVIF");
  }
  Err(e) => panic!("CharNotInKeyError {}", e),
};

Decrypt

use playfair_cipher::playfair::PlayFairKey as PlayFairKey;
use playfair_cipher::errors::CharNotInKeyError as CharNotInKeyError;
use playfair_cipher::cryptable::Cypher;

let pfc = PlayFairKey::new("playfair example");
match pfc.decrypt("BMODZBXDNABEKUDMUIXMMOUVIF") {
  Ok(crypt) => {
    assert_eq!(crypt, "HIDETHEGOLDINTHETREXESTUMP");
  }
  Err(e) => panic!("CharNotInKeyError {}", e),
}; 

four_square_ciper

Implementation of the FourSquare cipher - nothing special, nothing useful, just for fun.

Encrypt

use playfair_cipher::{four_square::FourSquare, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;

let fsq = FourSquare::new("EXAMPLE", "KEYWORD");
match fsq.encrypt("joe") {
  Ok(crypt) => {
    assert_eq!(crypt, "DIAZ");
  }
  Err(e) => panic!("CharNotInKeyError {}", e),
};

Decrypt

use playfair_cipher::{four_square::FourSquare, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;

let fsq = FourSquare::new("EXAMPLE", "KEYWORD");
match fsq.decrypt("DIAZ") {
  Ok(crypt) => {
    assert_eq!(crypt, "IOEX");
  }
  Err(e) => panic!("CharNotInKeyError {}", e),
};

two_square_ciper

Implementation of the TwoSquare cipher - nothing special, nothing useful, just for fun.

Encrypt

use playfair_cipher::{two_square::TwoSquare, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;

let tsq = TwoSquare::new("EXAMPLE", "KEYWORD");
match tsq.encrypt("joe") {
  Ok(crypt) => {
    assert_eq!(crypt, "NYMT");
  }
  Err(e) => panic!("CharNotInKeyError {}", e),
};

Decrypt

use playfair_cipher::{two_square::TwoSquare, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;

let tsq = TwoSquare::new("EXAMPLE", "KEYWORD");
match tsq.decrypt("NYMT") {
  Ok(crypt) => {
    assert_eq!(crypt, "IOEX");
  }
  Err(e) => panic!("CharNotInKeyError {}", e),
};

That's it.

Commit count: 34

cargo fmt