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
impl ADFGVX
Sourcepub fn new(key1: &str, key2: &str) -> Result<Self>
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
impl Block for ADFGVX
Source§fn block_size(&self) -> usize
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
fn encrypt(&self, dst: &mut [u8], src: &[u8]) -> usize
Encrypts plaintext using the ADFGVX cipher.
The encryption is performed in two stages:
- Each plaintext character is substituted using the Polybius square, producing two ADFGVX characters (row and column coordinates)
- 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
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:
- The columnar transposition is reversed to recover the bigrammatic text
- 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.