pub struct PolybiusSquare { /* private fields */ }
Expand description
A Polybius Square cipher implementation.
Implementations§
Source§impl PolybiusSquare
impl PolybiusSquare
Sourcepub fn new(key: &str, chars: &str) -> Self
pub fn new(key: &str, chars: &str) -> Self
Takes the key and specified characters for the Polybius Square cipher and returns a corresponding PolybiusSquare struct.
§Panics
- If
key
is not valid ascii. - If
key
contains repeated chars. - If
chars
is not valid ascii. - If
chars
contains repeated chars. - If
chars
is not of lengthsqrt(key.len())
, orkey
is not oflength chars.len()^2
.
Trait Implementations§
Source§impl Cipher for PolybiusSquare
impl Cipher for PolybiusSquare
Source§fn encipher(&self, ptext: &str) -> CipherResult
fn encipher(&self, ptext: &str) -> CipherResult
Enciphers the given plaintext (a str reference) using the Polybius Square
cipher and returns the ciphertext as a CipherResult
.
§Example
use ciphers::{Cipher, PolybiusSquare};
let ps = PolybiusSquare::new("PHQGIUMEAYLNOFDXKRCVSTZWB", "ABCDE");
let ctext = ps.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "CEBCCDBCCBCEEBABBCBCBDEAEBEDBDCACACCCDEBABBCDDBDEAEBCABC");
Source§fn decipher(&self, ctext: &str) -> CipherResult
fn decipher(&self, ctext: &str) -> CipherResult
Deciphers the given ciphertext (a str reference) using the Polybius Square
cipher and returns the plaintext as a CipherResult
.
§Example
use ciphers::{Cipher, PolybiusSquare};
let ps = PolybiusSquare::new("PHQGIUMEAYLNOFDXKRCVSTZWB", "ABCDE");
let ptext = ps.decipher("CEBCCDBCCBCEEBABBCBCBDEAEBEDBDCACACCCDEBABBCDDBDEAEBCABC");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
Auto Trait Implementations§
impl Freeze for PolybiusSquare
impl RefUnwindSafe for PolybiusSquare
impl Send for PolybiusSquare
impl Sync for PolybiusSquare
impl Unpin for PolybiusSquare
impl UnwindSafe for PolybiusSquare
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