Struct cipher_crypt::playfair::Playfair
source · pub struct Playfair { /* private fields */ }Expand description
A Playfair cipher.
This struct is created by the new() method. See its documentation for more.
Trait Implementations§
source§impl Cipher for Playfair
impl Cipher for Playfair
source§fn new(key: Self::Key) -> Result<Playfair, &'static str>
fn new(key: Self::Key) -> Result<Playfair, &'static str>
Initialize a Playfair cipher.
Warning
- The 5x5 key table requires any ‘J’ characters in the key to be substituted with ‘I’ characters (I = J).
source§fn encrypt(&self, message: &str) -> Result<String, &'static str>
fn encrypt(&self, message: &str) -> Result<String, &'static str>
Encrypt a message with the Playfair cipher.
Examples
Basic Usage:
use cipher_crypt::{Cipher, Playfair};
let c = Playfair::new("playfair example".to_string()).unwrap();
assert_eq!(
c.encrypt("Hide the gold in the tree stump").unwrap(),
"BMODZBXDNABEKUDMUIXMMOUVIF"
);Warning
- The 5x5 key table requires any ‘J’ characters in the message to be substituted with ‘I’ characters (i.e. I = J).
- The resulting ciphertext will be fully uppercase with no whitespace.
Errors
- Messages must contain alphabetic characters only.
source§fn decrypt(&self, message: &str) -> Result<String, &'static str>
fn decrypt(&self, message: &str) -> Result<String, &'static str>
Decrypt a message with the Playfair cipher.
Examples
Basic Usage:
use cipher_crypt::{Cipher, Playfair};
let c = Playfair::new("playfair example".to_string()).unwrap();
assert_eq!(
c.decrypt("BMODZBXDNABEKUDMUIXMMOUVIF").unwrap(),
"HIDETHEGOLDINTHETREXESTUMP"
);
Warning
- The 5x5 key table requires any ‘J’ characters in the message to be substituted with ‘I’ characters (i.e. I = J).
- The resulting plaintext will be fully uppercase with no whitespace.
- The resulting plaintext may contain added ‘X’ pad characters.
Errors
- Messages must contain only alphabetic characters.