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 …
phrase
is used to generate an alphanumeric keyed alphabet. It can contain charactersa-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 alphabeta-z
,0-9
. - The
column
androw_ids
must contain alphabetic characters only. - The
column
orrow_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());
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());
type Key = (String, [char; 6], [char; 6])
type Algorithm = Polybius
Auto Trait Implementations§
impl Freeze for Polybius
impl RefUnwindSafe for Polybius
impl Send for Polybius
impl Sync for Polybius
impl Unpin for Polybius
impl UnwindSafe for Polybius
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