Struct 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

Source§

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 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());
Source§

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>

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());
Source§

type Key = (String, [char; 6], [char; 6])

Source§

type Algorithm = Polybius

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.