pub struct PlayFairKey { /* private fields */ }Expand description
Struct represents a PlayFaire Cipher. It’s holding the key and the position of any character in the key.
Implementations§
Source§impl PlayFairKey
impl PlayFairKey
Sourcepub fn new_5_to_5(key: &str) -> Self
pub fn new_5_to_5(key: &str) -> Self
Constructs a new PlayFaire cipher based on a 5 to 5 square. J is replaced by I, no digits. Passkey can only contain A-I and K-Z.
§Example
use playfair_cipher::playfair::PlayFairKey as PlayFairKey;
let pfc = PlayFairKey::new_5_to_5("Secret");Sourcepub fn new_6_to_6(key: &str) -> Self
pub fn new_6_to_6(key: &str) -> Self
Constructs a new PlayFaire cipher based on a 6 to 6 square. A-Z and 0-9 are encryptable too. Passkey can contain A-Z and 0-9.
§Example
use playfair_cipher::playfair::PlayFairKey as PlayFairKey;
let pfc = PlayFairKey::new_6_to_6("Secret");Trait Implementations§
Source§impl Cipher for PlayFairKey
impl Cipher for PlayFairKey
Source§fn encrypt(&self, payload: &str) -> Result<String, CharNotInKeyError>
fn encrypt(&self, payload: &str) -> Result<String, CharNotInKeyError>
Encrypts a string. Note as the PlayFair cipher is only able to encrypt the characters A-I and L-Z any spaces and J are cleared off.
§Example 5 to 5
As described at https://en.wikipedia.org/wiki/Playfair_cipher
use playfair_cipher::{playfair::PlayFairKey, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;
let pfc = PlayFairKey::new_5_to_5("playfair example");
match pfc.encrypt("hide the gold in the tree stump") {
Ok(crypt) => {
assert_eq!(crypt, "BMODZBXDNABEKUDMUIXMMOUVIF");
}
Err(e) => panic!("CharNotInKeyError {}", e),
};§Example 6 to 6
use playfair_cipher::{playfair::PlayFairKey, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;
let pfc = PlayFairKey::new_6_to_6("play 3645 fair 8760 example");
match pfc.encrypt("hide the gold in the tree stump at 5 o'clock.") {
Ok(crypt) => {
assert_eq!(crypt, "SXG0SJGQW5H5OUGX2MXMXQUN733Q0WDPNDHB");
}
Err(e) => panic!("CharNotInKeyError {}", e),
};Source§fn decrypt(&self, payload: &str) -> Result<String, CharNotInKeyError>
fn decrypt(&self, payload: &str) -> Result<String, CharNotInKeyError>
Decrypts a string.
§Example 5 to 5
As described at https://en.wikipedia.org/wiki/Playfair_cipher
use playfair_cipher::playfair::PlayFairKey as PlayFairKey;
use playfair_cipher::errors::CharNotInKeyError as CharNotInKeyError;
use playfair_cipher::cryptable::Cypher;
let pfc = PlayFairKey::new_5_to_5("playfair example");
match pfc.decrypt("BMODZBXDNABEKUDMUIXMMOUVIF") {
Ok(crypt) => {
assert_eq!(crypt, "HIDETHEGOLDINTHETREXESTUMP");
}
Err(e) => panic!("CharNotInKeyError {}", e),
};
§Example 6 to 6
use playfair_cipher::{playfair::PlayFairKey, errors::CharNotInKeyError};
use playfair_cipher::cryptable::Cypher;
let pfc = PlayFairKey::new_6_to_6("play 3645 fair 8760 example");
match pfc.decrypt("SXG0SJGQW5H5OUGX2MXMXQUN733Q0WDPNDHB") {
Ok(crypt) => {
assert_eq!(crypt, "HIDETHEGOLDINTHETREXESTUMPAT5OCLOCKX");
}
Err(e) => panic!("CharNotInKeyError {}", e),
};Auto Trait Implementations§
impl Freeze for PlayFairKey
impl RefUnwindSafe for PlayFairKey
impl Send for PlayFairKey
impl Sync for PlayFairKey
impl Unpin for PlayFairKey
impl UnsafeUnpin for PlayFairKey
impl UnwindSafe for PlayFairKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more