[−][src]Struct cipher_crypt::playfair::Playfair
A Playfair cipher.
This struct is created by the new()
method. See its documentation for more.
Trait Implementations
impl Cipher for Playfair
[src]
type Key = (String, Option<char>)
type Algorithm = Playfair
fn new(key: (String, Option<char>)) -> Playfair
[src]
Initialize a Playfair cipher.
The key
tuple maps to the following (String, Option<char>) = (keystream, null_char)
.
Where ...
- The
keystream
is used to generate a playfair table. - The
null_char
is the character that is used to pad uneven messages during the encryption process. This value will default to 'X'.
Panics
- The
keystream
must not be empty. - The
keystream
must not exceed the length of the playfair alphabet (25 characters). - The
keystream
must not contain non-alphabetic symbols or the letter 'J'.
fn encrypt(&self, message: &str) -> Result<String, &'static str>
[src]
Encrypt a message with the Playfair cipher.
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
- Message contains a non-alphabetic character.
- Message contains the null character.
- Message contains whitespace.
Examples
Basic Usage:
use cipher_crypt::{Cipher, Playfair}; let c = Playfair::new(("playfairexample".to_string(), None)); assert_eq!( c.encrypt("Hidethegoldinthetreestump").unwrap(), "BMODZBXDNABEKUDMUIXMKZZRYI" );
fn decrypt(&self, message: &str) -> Result<String, &'static str>
[src]
Decrypt a message with the Playfair cipher.
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 null characters.
Errors
- Message contains a non-alphabetic character.
- Message contains whitespace.
Examples
Basic Usage:
use cipher_crypt::{Cipher, Playfair}; let c = Playfair::new(("playfairexample".to_string(), None)); assert_eq!( c.decrypt("BMODZBXDNABEKUDMUIXMKZZRYI").unwrap(), "HIDETHEGOLDINTHETREXSTUMPX" );
Auto Trait Implementations
impl Send for Playfair
impl Sync for Playfair
impl Unpin for Playfair
impl RefUnwindSafe for Playfair
impl UnwindSafe for Playfair
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,