[][src]Struct ciphers::PolybiusSquare

pub struct PolybiusSquare { /* fields omitted */ }

A Polybius Square cipher implementation.

Methods

impl PolybiusSquare[src]

pub fn new(key: &str, chars: &str) -> Self[src]

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 length sqrt(key.len()), or key is not of length chars.len()^2.

Trait Implementations

impl Cipher for PolybiusSquare[src]

fn encipher(&self, ptext: &str) -> CipherResult[src]

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

fn decipher(&self, ctext: &str) -> CipherResult[src]

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

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]