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§

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’.

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"
);

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§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.