Struct cipher_crypt::caesar::Caesar
[−]
[src]
pub struct Caesar { /* fields omitted */ }
A Caesar cipher.
This struct is created by the new()
method. See its documentation for more.
Trait Implementations
impl Cipher for Caesar
[src]
type Key = usize
type Algorithm = Caesar
fn new(shift: usize) -> Result<Caesar, &'static str>
Initialise a Caesar cipher given a specific shift value.
Will return Err
if the shift value is outside the range 1-26
.
fn encrypt(&self, message: &str) -> Result<String, &'static str>
Encrypt a message using a Caesar cipher.
Examples
Basic usage:
use cipher_crypt::{Cipher, Caesar}; let c = Caesar::new(3).unwrap(); assert_eq!("Dwwdfn dw gdzq!", c.encrypt("Attack at dawn!").unwrap());
fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>
Decrypt a message using a Caesar cipher.
Examples
Basic usage:
use cipher_crypt::{Cipher, Caesar}; let c = Caesar::new(3).unwrap(); assert_eq!("Attack at dawn!", c.decrypt("Dwwdfn dw gdzq!").unwrap());