[−][src]Struct cipher_crypt::columnar_transposition::ColumnarTransposition
A Columnar Transposition cipher.
This struct is created by the new()
method. See its documentation for more.
Trait Implementations
impl Cipher for ColumnarTransposition
[src]
type Key = (String, Option<char>)
type Algorithm = ColumnarTransposition
fn new(key: (String, Option<char>)) -> ColumnarTransposition
[src]
Initialize a Columnar Transposition cipher.
Where...
- Elements of
keystream
are used as the column identifiers. - The optional
null_char
is used to pad messages of uneven length. - The
derived_key
is used to initialise the column structures in the cipher.
Panics
- The
keystream
length is 0. - The
keystream
contains non-alphanumeric symbols. - The
keystream
contains duplicate characters. - The
null_char
is a character within thekeystream
fn encrypt(&self, message: &str) -> Result<String, &'static str>
[src]
Encrypt a message with a Columnar Transposition cipher.
All characters (including utf8) can be encrypted during the transposition process.
However, it is important to note that if padding characters are being used (null_char
),
the user must ensure that the message does not contain these padding characters, otherwise
problems will occur during decryption. For this reason, the function will Err
if it
detects padding characters in the message to be encrypted.
Examples
Basic usage:
use cipher_crypt::{Cipher, ColumnarTransposition}; let key_word = String::from("zebras"); let null_char = None; let ct = ColumnarTransposition::new((key_word, null_char));; assert_eq!("respce!uemeers-taSs g", ct.encrypt("Super-secret message!").unwrap());
fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>
[src]
Decrypt a ciphertext with a Columnar Transposition cipher.
Examples
Basic usage:
use cipher_crypt::{Cipher, ColumnarTransposition}; let key_word = String::from("zebras"); let null_char = None; let ct = ColumnarTransposition::new((key_word, null_char));; assert_eq!("Super-secret message!", ct.decrypt("respce!uemeers-taSs g").unwrap());
Using whitespace as null (special case): This will strip only trailing whitespace in message during decryption
use cipher_crypt::{Cipher, ColumnarTransposition}; let key_word = String::from("zebras"); let null_char = None; let message = "we are discovered "; // Only trailing spaces will be stripped let ct = ColumnarTransposition::new((key_word, null_char));; assert_eq!(ct.decrypt(&ct.encrypt(message).unwrap()).unwrap(),"we are discovered");
Auto Trait Implementations
impl Send for ColumnarTransposition
impl Sync for ColumnarTransposition
impl Unpin for ColumnarTransposition
impl RefUnwindSafe for ColumnarTransposition
impl UnwindSafe for ColumnarTransposition
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,