Struct cipher_crypt::affine::Affine [−][src]
pub struct Affine { /* fields omitted */ }
An Affine cipher.
This struct is created by the new()
method. See its documentation for more.
Trait Implementations
impl Cipher for Affine
[src]
impl Cipher for Affine
type Key = (usize, usize)
type Algorithm = Affine
fn new(a_b: (usize, usize)) -> Result<Affine, &'static str>
[src]
fn new(a_b: (usize, usize)) -> Result<Affine, &'static str>
Initialise an Affine cipher given the keys a
and b
.
Will return Err
if one of the following conditions is detected:
a
orb
are not in the inclusive range1 - 26
.a
has a factor in common with 26.
fn encrypt(&self, message: &str) -> Result<String, &'static str>
[src]
fn encrypt(&self, message: &str) -> Result<String, &'static str>
Encrypt a message using an Affine cipher.
Examples
Basic usage:
use cipher_crypt::{Cipher, Affine}; let a = Affine::new((3, 7)).unwrap(); assert_eq!("Hmmhnl hm qhvu!", a.encrypt("Attack at dawn!").unwrap());
fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>
[src]
fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>
Decrypt a message using an Affine cipher.
Examples
Basic usage:
use cipher_crypt::{Cipher, Affine}; let a = Affine::new((3, 7)).unwrap(); assert_eq!("Attack at dawn!", a.decrypt("Hmmhnl hm qhvu!").unwrap());