pub struct Polybius { /* private fields */ }
Expand description

A Polybius square cipher.

This struct is created by the new() method. See its documentation for more.

Trait Implementations§

Initialise a Polybius square cipher.

In this implementation each part of the key is used to initialise a 6x6 polybius square. The key tuple maps to the following (String, [char; 6], [char; 6]) = (phase, column_ids, row_ids).

Where …

  • phrase is used to generate an alphanumeric keyed alphabet. It can contain characters a-z 0-9.
  • column_ids are unique identifiers used for each column of the polybius square. Valid characters are alphabetic only (a-z).
  • row_ids are unique identifiers used for each row of the polybius square. Valid characters can be alphabetic only (a-z).
Panics
  • If a non-alphanumeric symbol is part of the key.
  • The key must have a length of 36.
  • The key must contain each character of the alphanumeric alphabet a-z, 0-9.
  • The column and row_ids must contain alphabetic characters only.
  • The column or row_ids contain repeated characters.
Example

Lets say the phrase was or0an3ge the column_ids were ['A','Z','C','D','E','F'] and the row_ids were ['A','B','G','D','E','F']. Then the polybius square would look like …

__ A Z C D E F
A| o r 0 a n 3
B| g e b c d f
G| h i j k l m
D| p q s t u v
E| w x y z 1 2
F| 4 5 6 7 8 9

Basic usage:

use cipher_crypt::{Cipher, Polybius};

let p = Polybius::new((String::from("or0an3ge"), ['A','Z','C','D','E','F'],
    ['A','B','G','D','E','F']));;

assert_eq!("EEAC AAazadaebabzdc adaebe EF ADdadagebzdc!",
   p.encrypt("10 Oranges and 2 Apples!").unwrap());

Encrypt a message using a Polybius square cipher.

Examples

Basic usage:

use cipher_crypt::{Cipher, Polybius};

let p = Polybius::new((String::from("p0lyb1us"), ['A','Z','C','D','E','F'],
    ['A','B','G','D','E','F']));;

assert_eq!("BCdfdfbcbdgf 🗡️ dfgcbf bfbcbzdf ezbcacac",
   p.encrypt("Attack 🗡️ the east wall").unwrap());

Decrypt a message using a Polybius square cipher.

Examples

Basic usage:

use cipher_crypt::{Cipher, Polybius};

let p = Polybius::new((String::from("p0lyb1us"), ['A','Z','C','D','E','F'],
    ['A','B','G','D','E','F']));;

assert_eq!("Attack 🗡️ the east wall",
   p.decrypt("BCdfdfbcbdgf 🗡️ dfgcbf bfbcbzdf ezbcacac").unwrap());

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.