ADFGVX

Struct ADFGVX 

Source
pub struct ADFGVX { /* private fields */ }
Expand description

ADFGVX cipher combining Polybius square substitution with columnar transposition.

This structure holds the two components of the ADFGVX cipher:

  • A Polybius square cipher using the letters A, D, F, G, V, X
  • A columnar transposition cipher for the second encryption stage

Implementations§

Source§

impl ADFGVX

Source

pub fn new(key1: &str, key2: &str) -> Result<Self>

Creates a new ADFGVX cipher with the given keys.

§Arguments
  • key1 - The keyword for the Polybius square substitution (should contain unique letters)
  • key2 - The keyword for the columnar transposition (defines column order)
§Returns

Returns Ok(ADFGVX) if both keys are valid, or Err(String) with an error message if either key is invalid (e.g., empty or contains invalid characters).

§Examples
let cipher = ADFGVX::new("PORTABLE", "SUBWAY").unwrap();
§Errors

Returns an error if:

  • Either key is empty
  • The keys contain invalid characters
  • The Polybius square or transposition cipher cannot be initialized

Trait Implementations§

Source§

impl Block for ADFGVX

Source§

fn block_size(&self) -> usize

Returns the block size for the cipher.

The block size is determined by the transposition cipher’s block size, which is twice the length of the transposition key (since each character is first encoded into two ADFGVX characters).

§Returns

The block size in bytes.

Source§

fn encrypt(&self, dst: &mut [u8], src: &[u8]) -> usize

Encrypts plaintext using the ADFGVX cipher.

The encryption is performed in two stages:

  1. Each plaintext character is substituted using the Polybius square, producing two ADFGVX characters (row and column coordinates)
  2. The resulting bigrammatic text is transposed using columnar transposition
§Arguments
  • dst - Destination buffer for the ciphertext (must be large enough)
  • src - Source plaintext bytes to encrypt
§Returns

The number of bytes written to dst.

Source§

fn decrypt(&self, dst: &mut [u8], src: &[u8]) -> usize

Decrypts ciphertext using the ADFGVX cipher.

The decryption is performed by reversing the two encryption stages:

  1. The columnar transposition is reversed to recover the bigrammatic text
  2. Each pair of ADFGVX characters is converted back to the original character using the Polybius square
§Arguments
  • dst - Destination buffer for the plaintext (must be large enough)
  • src - Source ciphertext bytes to decrypt
§Returns

The number of bytes written to dst.

Source§

impl Debug for ADFGVX

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for ADFGVX

§

impl !RefUnwindSafe for ADFGVX

§

impl Send for ADFGVX

§

impl !Sync for ADFGVX

§

impl Unpin for ADFGVX

§

impl UnwindSafe for ADFGVX

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.