Struct cipher_crypt::polybius::Polybius
source · 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§
source§impl Cipher for Polybius
impl Cipher for Polybius
source§fn new(key: (String, [char; 6], [char; 6])) -> Polybius
fn new(key: (String, [char; 6], [char; 6])) -> Polybius
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 …
phraseis used to generate an alphanumeric keyed alphabet. It can contain charactersa-z 0-9.column_idsare unique identifiers used for each column of the polybius square. Valid characters are alphabetic only (a-z).row_idsare 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
keymust have a length of 36. - The
keymust contain each character of the alphanumeric alphabeta-z,0-9. - The
columnandrow_idsmust contain alphabetic characters only. - The
columnorrow_idscontain 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 9Basic 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());source§fn encrypt(&self, message: &str) -> Result<String, &'static str>
fn encrypt(&self, message: &str) -> Result<String, &'static str>
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());source§fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>
fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>
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());