ECB_ISO

Trait ECB_ISO 

Source
pub trait ECB_ISO<T>: Sized {
Show 27 methods // Required methods fn encrypt( &mut self, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64; fn encrypt_into_vec<U>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64 where U: SmallUInt + Copy + Clone; fn encrypt_into_array<U, const N: usize>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64 where U: SmallUInt + Copy + Clone; fn decrypt( &mut self, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64; fn decrypt_into_array<U, const N: usize>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64 where U: SmallUInt + Copy + Clone; // Provided methods fn encrypt_str(&mut self, message: &str, cipher: *mut u8) -> u64 { ... } fn encrypt_str_into_vec<U>( &mut self, message: &str, cipher: &mut Vec<U>, ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn encrypt_str_into_array<U, const N: usize>( &mut self, message: &str, cipher: &mut [U; N], ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn encrypt_string(&mut self, message: &String, cipher: *mut u8) -> u64 { ... } fn encrypt_string_into_vec<U>( &mut self, message: &String, cipher: &mut Vec<U>, ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn encrypt_string_into_array<U, const N: usize>( &mut self, message: &String, cipher: &mut [U; N], ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn encrypt_vec<U>(&mut self, message: &Vec<U>, cipher: *mut u8) -> u64 where U: SmallUInt + Copy + Clone { ... } fn encrypt_vec_into_vec<U, V>( &mut self, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, message: &Vec<U>, cipher: &mut [V; N], ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn encrypt_array<U, const N: usize>( &mut self, message: &[U; N], cipher: *mut u8, ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, message: &[U; N], cipher: &mut Vec<V>, ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, message: &[U; N], cipher: &mut [V; M], ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn decrypt_into_vec<U>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn decrypt_into_string( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64 { ... } fn decrypt_vec<U>(&mut self, cipher: &Vec<U>, message: *mut u8) -> u64 where U: SmallUInt + Copy + Clone { ... } fn decrypt_vec_into_vec<U, V>( &mut self, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, cipher: &Vec<U>, message: &mut [V; N], ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn decrypt_vec_into_string<U>( &mut self, cipher: &Vec<U>, message: &mut String, ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn decrypt_array<U, const N: usize>( &mut self, cipher: &[U; N], message: *mut u8, ) -> u64 where U: SmallUInt + Copy + Clone { ... } fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, cipher: &[U; N], message: &mut Vec<V>, ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, cipher: &[U; N], message: &mut [V; M], ) -> u64 where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone { ... } fn decrypt_array_into_string<U, const N: usize>( &mut self, cipher: &[U; N], message: &mut String, ) -> u64 where U: SmallUInt + Copy + Clone { ... }
}
Expand description

ECB (Electronic CodeBook) is one of the operation modes for encryption/decryption. And ISO 7816-4 is the one of the padding ways.

Required Methods§

Source

fn encrypt( &mut self, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64

Encrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • message is an immutable pointer to u8 which is *const u8, and is the place where the plaintext to be encrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the plaintext message in bytes.
  • cipher is a mutable pointer to u8 which is *mut u8, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_*_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • If length_in_bytes is 0, it means the message is null string. So, only padding bytes will be encrypted, and stored in the memory area that starts from cipher.
  • The size of the memory area which starts at cipher is assumed to be enough to store the ciphertext.
  • The size of the area for ciphertext should be prepared to be (length_in_bytes + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
tdes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Source

fn encrypt_into_vec<U>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in Vec<U>.

§Arguments
  • message is an immutable pointer to u8 which is *const u8, and is the place where the plaintext to be encrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the plaintext message in bytes.
  • cipher is a mutable reference to Vec<U> object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_*_into_vec().
  • This method is useful to use in hybrid programming with C/C++.
  • If length_in_bytes is 0, it means the message is a null string. So, only padding bytes will be encrypted, and stored in the Vec<U> object which is referred to as cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Source

fn encrypt_into_array<U, const N: usize>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in array [U; N].

§Arguments
  • message is an immutable pointer to u8 which is *const u8, and is the place where the plaintext to be encrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the plaintext message in bytes.
  • cipher is a mutable reference to an array [U; N] object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_*_into_array().
  • This method is useful to use in hybrid programming with C/C++.
  • If length_in_bytes is 0, it means the message is null data. So, only padding bytes will be encrypted, and stored in the array [U; N] object cipher.
  • If U::size_in_bytes() * N is less than length_in_bytes’s next multiple of size_of::<T>(), this method does not perform encryption but returns zero.
  • If U::size_in_bytes() * N is equal to length_in_bytes’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and returns the size of the ciphertext including padding bits in bytes.
  • If U::size_in_bytes() * N is greater than length_in_bytes’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and then fills the rest of the elements of the array cipher with zeros, and returns the size of the ciphertext including padding bits in bytes.
  • The size of the area for ciphertext should be prepared to be (length_in_bytes + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
tdes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Source

fn decrypt( &mut self, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64

Decrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • cipher is an immutable pointer to u8 which is *const u8, and is the place where the ciphertext to be decrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the ciphertext cipher in bytes.
  • message is a mutable pointer to u8 which is *mut u8, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If length_in_bytes is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as decrypt_*_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • length_in_bytes cannot be other than any multiple of size_of::<T>().
  • The size of the memory area which starts at message is assumed to be enough to store the plaintext. So, it is responsible for you to prepare the message area big enough!
  • The size of the area for plaintext does not have to be prepared more than length_in_bytes - 1.
  • If the size of the area for plaintext is prepared more than length_in_bytes - 1, the rest of the area will be filled with 0s.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = vec![0; 55];
a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = vec![0; 55];
a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = vec![0; 55];
taes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = vec![0; 55];
tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Source

fn decrypt_into_array<U, const N: usize>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
where U: SmallUInt + Copy + Clone,

Decrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in array [U; N].

§Arguments
  • cipher is an immutable pointer to u8 which is *const u8, and is the place where the ciphertext to be decrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the ciphertext cipher in bytes.
  • message is a mutable reference to an array [U; N] object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If length_in_bytes is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as decrypt_*_into_array().
  • This method is useful to use in hybrid programming with C/C++.
  • length_in_bytes cannot be other than any multiple of size_of::<T>().
  • If U::size_in_bytes() * N is less than length_in_bytes - 1, this method does not perform decryption but returns zero.
  • If U::size_in_bytes() * N is equal to or greater than length_in_bytes - 1, this method performs decryption, fills the array message with the decrypted data, and then fills the rest of the elements of the array message with zeros, and returns the size of the plaintext.
  • It is responsible for you to prepare the message area big enough!
  • The size of the area for plaintext does not have to be prepared more than length_in_bytes - 1.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = [0; 64];
let len = a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = [0u8; 56];
let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = [0u8; 64];
let len = taes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = [0u8; 56];
let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Provided Methods§

Source

fn encrypt_str(&mut self, message: &str, cipher: *mut u8) -> u64

Encrypts the data in a str object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • message is an immutable reference to str object which is &str, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable pointer to u8 which is *mut u8, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_str_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • If message is a null string “”, only padding bytes will be encrypted, and stored in the memory area that starts from cipher.
  • The size of the memory area which starts at cipher is assumed to be enough to store the ciphertext.
  • The size of the area for ciphertext should be prepared to be (message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_str(&message, cipher.as_mut_ptr());
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt_str(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
tdes.encrypt_str(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 146)
132fn bigcryptor64_encrypt_str_with_padding_iso_ecb()
133{
134    println!("bigcryptor64_encrypt_str_with_padding_iso_ecb()");
135    use std::io::Write;
136    use std::fmt::Write as _;
137    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
138
139    // TDES case
140    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
141                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
142                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
143    let message = "In the beginning God created the heavens and the earth.";
144    println!("M =\t{}", message);
145    let mut cipher = [0_u8; 56];
146    tdes.encrypt_str(&message, cipher.as_mut_ptr());
147    print!("C =\t");
148    for c in cipher.clone()
149        { print!("{:02X} ", c); }
150    println!();
151    let mut txt = String::new();
152    for c in cipher.clone()
153        { write!(txt, "{:02X} ", c); }
154    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
155    println!("-------------------------------");
156}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 154)
138fn bigcryptor128_encrypt_str_with_padding_iso_ecb()
139{
140    println!("bigcryptor128_encrypt_str_with_padding_iso_ecb()");
141    use std::io::Write;
142    use std::fmt::Write as _;
143    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
144
145    // TAES_128 case
146    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
147                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
148                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
149    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
150    println!("IV =	{:#034X}", iv);
151    let message = "In the beginning God created the heavens and the earth.";
152    println!("M =\t{}", message);
153    let mut cipher = [0_u8; 64];
154    taes.encrypt_str(&message, cipher.as_mut_ptr());
155    print!("C =\t");
156    for c in cipher.clone()
157        { print!("{:02X} ", c); }
158    println!();
159    let mut txt = String::new();
160    for c in cipher.clone()
161        { write!(txt, "{:02X} ", c); }
162    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
163    println!("-------------------------------");
164}
examples/aes_ecb_iso_examples.rs (line 418)
403fn aes_encrypt_str_with_padding_iso_ecb()
404{
405    println!("aes_encrypt_str_with_padding_iso_ecb()");
406    use std::io::Write;
407    use std::fmt::Write as _;
408    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
409
410    // Normal case for AES-128
411    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
412    println!("K =\t{:#016X}", key);
413    let mut a_aes = AES_128::new_with_key_u128(key);
414
415    let message = "In the beginning God created the heavens and the earth.";
416    println!("M =\t{}", message);
417    let mut cipher = [0_u8; 64];
418    a_aes.encrypt_str(&message, cipher.as_mut_ptr());
419    print!("C =\t");
420    for c in cipher.clone()
421        { print!("{:02X} ", c); }
422    println!();
423    let mut txt = String::new();
424    for c in cipher.clone()
425        { write!(txt, "{:02X} ", c); }
426    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
427    println!();
428
429    // Normal case for AES-192
430    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
431    print!("K =\t");
432    for i in 0..24
433        { print!("{:02X}", key[i]); }
434    println!();
435    let mut a_aes = AES_192::new_with_key(&key);
436
437    let message = "In the beginning God created the heavens and the earth.";
438    println!("M =\t{}", message);
439    let mut cipher = [0_u8; 64];
440    a_aes.encrypt_str(&message, cipher.as_mut_ptr());
441    print!("C =\t");
442    for c in cipher.clone()
443        { print!("{:02X} ", c); }
444    println!();
445    let mut txt = String::new();
446    for c in cipher.clone()
447        { write!(txt, "{:02X} ", c); }
448    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
449    println!();
450
451    // Normal case for AES-256
452    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
453    print!("K =\t");
454    for i in 0..32
455        { print!("{:02X}", key[i]); }
456    println!();
457    let mut a_aes = AES_256::new_with_key(&key);
458
459    let message = "In the beginning God created the heavens and the earth.";
460    println!("M =\t{}", message);
461    let mut cipher = [0_u8; 64];
462    a_aes.encrypt_str(&message, cipher.as_mut_ptr());
463    print!("C =\t");
464    for c in cipher.clone()
465        { print!("{:02X} ", c); }
466    println!();
467    let mut txt = String::new();
468    for c in cipher.clone()
469        { write!(txt, "{:02X} ", c); }
470    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
471    println!();
472
473    // Normal case for Rijndael-256-256
474    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
475    print!("K =\t");
476    for i in 0..32
477        { print!("{:02X}", key[i]); }
478    println!();
479    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
480
481    let message = "In the beginning God created the heavens and the earth.";
482    println!("M =\t{}", message);
483    let mut cipher = [0_u8; 64];
484    a_rijndael.encrypt_str(&message, cipher.as_mut_ptr());
485    print!("C =\t");
486    for c in cipher.clone()
487        { print!("{:02X} ", c); }
488    println!();
489    let mut txt = String::new();
490    for c in cipher.clone()
491        { write!(txt, "{:02X} ", c); }
492    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
493    println!();
494
495    // Normal case for Rijndael-512-512 for post-quantum
496    use cryptocol::number::SharedArrays;
497    use cryptocol::hash::SHA3_512;
498    let mut sha3 = SHA3_512::new();
499    sha3.absorb_str("Post-quantum");
500    let key: [u8; 64] = sha3.get_hash_value_in_array();
501    print!("K =\t");
502    for i in 0..64
503        { print!("{:02X}", key[i]); }
504    println!();
505    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
506    let message = "In the beginning God created the heavens and the earth.";
507    println!("M =\t{}", message);
508    let mut cipher = [0_u8; 64];
509    a_rijndael.encrypt_str(&message, cipher.as_mut_ptr());
510    print!("C =\t");
511    for c in cipher.clone()
512        { print!("{:02X} ", c); }
513    println!();
514    let mut txt = String::new();
515    for c in cipher.clone()
516        { write!(txt, "{:02X} ", c); }
517    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
518    println!("-------------------------------");
519}
examples/des_ecb_iso_examples.rs (line 587)
572fn des_encrypt_str_with_padding_iso_ecb()
573{
574    println!("des_encrypt_str_with_padding_iso_ecb()");
575    use std::io::Write;
576    use std::fmt::Write as _;
577    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
578
579    // Normal case
580    let key = 0x_1234567890ABCDEF_u64;
581    println!("K =\t{:#016X}", key);
582    let mut a_des = DES::new_with_key_u64(key);
583
584    let message = "In the beginning God created the heavens and the earth.";
585    println!("M =\t{}", message);
586    let mut cipher = [0_u8; 56];
587    a_des.encrypt_str(&message, cipher.as_mut_ptr());
588    print!("C (16 rounds) =\t");
589    for c in cipher.clone()
590        { print!("{:02X} ", c); }
591    println!();
592    let mut txt = String::new();
593    for c in cipher.clone()
594        { write!(txt, "{:02X} ", c); }
595    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
596    println!();
597
598    // Expanded case for 128 rounds
599    let key = 0x_1234567890ABCDEF_u64;
600    println!("K =\t{:#016X}", key);
601    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
602
603    let message = "In the beginning God created the heavens and the earth.";
604    println!("M =\t{}", message);
605    let mut cipher = [0_u8; 56];
606    a_des.encrypt_str(&message, cipher.as_mut_ptr());
607    print!("C (128 rounds) =\t");
608    for c in cipher.clone()
609        { print!("{:02X} ", c); }
610    println!();
611    let mut txt = String::new();
612    for c in cipher.clone()
613        { write!(txt, "{:02X} ", c); }
614    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
615    println!();
616
617    // Expanded case for 0 rounds which means that key is meaningless
618    let key1 = 0x_1234567890ABCDEF_u64;
619    let key2 = 0_u64;
620    println!("K =\t{:#016X}", key);
621    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
622    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
623
624    let message = "In the beginning God created the heavens and the earth.";
625    println!("M =\t{}", message);
626    let mut cipher1 = [0_u8; 56];
627    let mut cipher2 = [0_u8; 56];
628    c_des.encrypt_str(&message, cipher1.as_mut_ptr());
629    d_des.encrypt_str(&message, cipher2.as_mut_ptr());
630    print!("C (0 rounds) =\t");
631    for c in cipher1.clone()
632        { print!("{:02X} ", c); }
633    println!();
634    let mut txt = String::new();
635    for c in cipher1.clone()
636        { write!(txt, "{:02X} ", c); }
637    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
638    print!("D (0 rounds) =\t");
639    for c in cipher2.clone()
640        { print!("{:02X} ", c); }
641    println!();
642    let mut txt = String::new();
643    for c in cipher2.clone()
644        { write!(txt, "{:02X} ", c); }
645    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
646    println!();
647
648    // Normal case for the message of 0 bytes
649    let key = 0x_1234567890ABCDEF_u64;
650    println!("K =\t{:#016X}", key);
651    let mut a_des = DES::new_with_key_u64(key);
652
653    let message = "";
654    println!("M =\t{}", message);
655    let mut cipher = [0_u8; 8];
656    a_des.encrypt_str(&message, cipher.as_mut_ptr());
657    print!("C =\t");
658    for c in cipher.clone()
659        { print!("{:02X} ", c); }
660    println!();
661    let mut txt = String::new();
662    for c in cipher.clone()
663        { write!(txt, "{:02X} ", c); }
664    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
665    println!();
666
667    // Normal case for the message shorter than 8 bytes
668    let key = 0x_1234567890ABCDEF_u64;
669    println!("K =\t{:#016X}", key);
670    let mut a_des = DES::new_with_key_u64(key);
671
672    let message = "7 bytes";
673    println!("M =\t{}", message);
674    let mut cipher = [0_u8; 8];
675    a_des.encrypt_str(&message, cipher.as_mut_ptr());
676    print!("C =\t");
677    for c in cipher.clone()
678        { print!("{:02X} ", c); }
679    println!();
680    let mut txt = String::new();
681    for c in cipher.clone()
682        { write!(txt, "{:02X} ", c); }
683    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
684    println!();
685
686    // Normal case for the message of 8 bytes
687    let key = 0x_1234567890ABCDEF_u64;
688    println!("K =\t{:#016X}", key);
689    let mut a_des = DES::new_with_key_u64(key);
690
691    let message = "I am OK.";
692    println!("M =\t{}", message);
693    let mut cipher = [0_u8; 16];
694    a_des.encrypt_str(&message, cipher.as_mut_ptr());
695    print!("C =\t");
696    for c in cipher.clone()
697        { print!("{:02X} ", c); }
698    println!();
699    let mut txt = String::new();
700    for c in cipher.clone()
701        { write!(txt, "{:02X} ", c); }
702    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
703    println!();
704
705    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
706    let key = 0x_1234567890ABCDEF_u64;
707    println!("K =\t{:#016X}", key);
708    let mut a_des = DES::new_with_key_u64(key);
709
710    let message = "PARK Youngho";
711    println!("M =\t{}", message);
712    let mut cipher = [0_u8; 16];
713    a_des.encrypt_str(&message, cipher.as_mut_ptr());
714    print!("C =\t");
715    for c in cipher.clone()
716        { print!("{:02X} ", c); }
717    println!();
718    let mut txt = String::new();
719    for c in cipher.clone()
720        { write!(txt, "{:02X} ", c); }
721    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
722    println!();
723
724
725    // Normal case for the message of 16 bytes
726    let key = 0x_1234567890ABCDEF_u64;
727    println!("K =\t{:#016X}", key);
728    let mut a_des = DES::new_with_key_u64(key);
729
730    let message = "고맙습니다.";
731    println!("M =\t{}", message);
732    let mut cipher = [0_u8; 24];
733    a_des.encrypt_str(&message, cipher.as_mut_ptr());
734    print!("C =\t");
735    for c in cipher.clone()
736        { print!("{:02X} ", c); }
737    println!();
738    let mut txt = String::new();
739    for c in cipher.clone()
740        { write!(txt, "{:02X} ", c); }
741    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
742    println!("-------------------------------");
743}
Source

fn encrypt_str_into_vec<U>(&mut self, message: &str, cipher: &mut Vec<U>) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data in str with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in Vec<U>.

§Arguments
  • message is an immutable reference to str object which is &str, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to Vec<U> object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is a null string “”, only padding bytes will be encrypted, and stored in the Vec<U> object which is referred to as cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 171)
158fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_vec()
159{
160    println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_vec()");
161    use std::io::Write;
162    use std::fmt::Write as _;
163    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
164
165    // TDES case
166    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
167                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
168                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
169    let message = "In the beginning God created the heavens and the earth.";
170    let mut cipher = Vec::<u8>::new();
171    tdes.encrypt_str_into_vec(&message, &mut cipher);
172    print!("C =\t");
173    for c in cipher.clone()
174        { print!("{:02X} ", c); }
175    println!();
176    let mut txt = String::new();
177    for c in cipher.clone()
178        { write!(txt, "{:02X} ", c); }
179    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
180    println!("-------------------------------");
181}
182
183fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()
184{
185    println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()");
186    use std::io::Write;
187    use std::fmt::Write as _;
188    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
189
190    // TDES case
191    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
192                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
193                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194    let message = "In the beginning God created the heavens and the earth.";
195    let mut cipher = [0_u8; 56];
196    tdes.encrypt_str_into_array(&message, &mut cipher);
197    print!("C =\t");
198    for c in cipher.clone()
199        { print!("{:02X} ", c); }
200    println!();
201    let mut txt = String::new();
202    for c in cipher.clone()
203        { write!(txt, "{:02X} ", c); }
204    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
205    println!("-------------------------------");
206}
207
208fn bigcryptor64_encrypt_string_with_padding_iso_ecb()
209{
210    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb()");
211    use std::io::Write;
212    use std::fmt::Write as _;
213    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
214
215    // TDES case
216    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219    let message = "In the beginning God created the heavens and the earth.".to_string();
220    let mut cipher = [0_u8; 56];
221    tdes.encrypt_string(&message, cipher.as_mut_ptr());
222    print!("C =\t");
223    for c in cipher.clone()
224        { print!("{:02X} ", c); }
225    println!();
226    let mut txt = String::new();
227    for c in cipher.clone()
228        { write!(txt, "{:02X} ", c); }
229    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230    println!("-------------------------------");
231}
232
233fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()
234{
235    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()");
236    use std::io::Write;
237    use std::fmt::Write as _;
238    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
239
240    // TDES case
241    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244    let message = "In the beginning God created the heavens and the earth.".to_string();
245    let mut cipher = Vec::<u8>::new();
246    tdes.encrypt_string_into_vec(&message, &mut cipher);
247    print!("C =\t");
248    for c in cipher.clone()
249        { print!("{:02X} ", c); }
250    println!();
251    let mut txt = String::new();
252    for c in cipher.clone()
253        { write!(txt, "{:02X} ", c); }
254    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255    println!("-------------------------------");
256}
257
258fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()
259{
260    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()");
261    use std::io::Write;
262    use std::fmt::Write as _;
263    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
264
265    // TDES case
266    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269    let message = "In the beginning God created the heavens and the earth.".to_string();
270    let mut cipher = [0_u8; 56];
271    tdes.encrypt_string_into_array(&message, &mut cipher);
272    print!("C =\t");
273    for c in cipher.clone()
274        { print!("{:02X} ", c); }
275    println!();
276    let mut txt = String::new();
277    for c in cipher.clone()
278        { write!(txt, "{:02X} ", c); }
279    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280    println!("-------------------------------");
281}
282
283fn bigcryptor64_encrypt_vec_with_padding_iso_ecb()
284{
285    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb()");
286    use std::io::Write;
287    use std::fmt::Write as _;
288    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
289
290    // TDES case
291    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294    let message = "In the beginning God created the heavens and the earth.";
295    println!("M =\t{}", message);
296    let message = unsafe { message.to_string().as_mut_vec().clone() };
297    let mut cipher = [0_u8; 56];
298    tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299    print!("C =\t");
300    for c in cipher.clone()
301        { print!("{:02X} ", c); }
302    println!();
303    let mut txt = String::new();
304    for c in cipher.clone()
305        { write!(txt, "{:02X} ", c); }
306    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307    println!("-------------------------------");
308}
309
310fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()
311{
312    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()");
313    use std::io::Write;
314    use std::fmt::Write as _;
315    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
316
317    // TDES case
318    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321    let message = "In the beginning God created the heavens and the earth.";
322    println!("M =\t{}", message);
323    let message = unsafe { message.to_string().as_mut_vec().clone() };
324    let mut cipher = Vec::<u8>::new();
325    tdes.encrypt_vec_into_vec(&message, &mut cipher);
326    print!("C =\t");
327    for c in cipher.clone()
328        { print!("{:02X} ", c); }
329    println!();
330    let mut txt = String::new();
331    for c in cipher.clone()
332        { write!(txt, "{:02X} ", c); }
333    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334    println!("-------------------------------");
335}
336
337fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()
338{
339    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()");
340    use std::io::Write;
341    use std::fmt::Write as _;
342    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
343
344    // TDES case
345    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348    let message = "In the beginning God created the heavens and the earth.";
349    println!("M =\t{}", message);
350    let message = unsafe { message.to_string().as_mut_vec().clone() };
351    let mut cipher = [0_u8; 56];
352    tdes.encrypt_vec_into_array(&message, &mut cipher);
353    print!("C =\t");
354    for c in cipher.clone()
355        { print!("{:02X} ", c); }
356    println!();
357    let mut txt = String::new();
358    for c in cipher.clone()
359        { write!(txt, "{:02X} ", c); }
360    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361    println!("-------------------------------");
362}
363
364fn bigcryptor64_encrypt_array_with_padding_iso_ecb()
365{
366    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb()");
367    use std::io::Write;
368    use std::fmt::Write as _;
369    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
370
371    // TDES case
372    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375    let mes = "In the beginning God created the heavens and the earth.";
376    println!("M =\t{}", mes);
377    let mut message = [0_u8; 55];
378    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379    let mut cipher = [0_u8; 56];
380    tdes.encrypt_array(&message, cipher.as_mut_ptr());
381    print!("C =\t");
382    for c in cipher.clone()
383        { print!("{:02X} ", c); }
384    println!();
385    let mut txt = String::new();
386    for c in cipher.clone()
387        { write!(txt, "{:02X} ", c); }
388    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389    println!("-------------------------------");
390}
391
392fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()
393{
394    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()");
395    use std::io::Write;
396    use std::fmt::Write as _;
397    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
398
399    // TDES case
400    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403    let mes = "In the beginning God created the heavens and the earth.";
404    println!("M =\t{}", mes);
405    let mut message = [0_u8; 55];
406    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407    let mut cipher = Vec::<u8>::new();
408    tdes.encrypt_array_into_vec(&message, &mut cipher);
409    print!("C =\t");
410    for c in cipher.clone()
411        { print!("{:02X} ", c); }
412    println!();
413    let mut txt = String::new();
414    for c in cipher.clone()
415        { write!(txt, "{:02X} ", c); }
416    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417    println!("-------------------------------");
418}
419
420fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()
421{
422    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()");
423    use std::io::Write;
424    use std::fmt::Write as _;
425    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
426
427    // TDES case
428    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431    let mes = "In the beginning God created the heavens and the earth.";
432    println!("M =\t{}", mes);
433    let mut message = [0_u8; 55];
434    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435    let mut cipher = [0_u8; 56];
436    tdes.encrypt_array_into_array(&message, &mut cipher);
437    for c in cipher.clone()
438        { print!("{:02X} ", c); }
439    println!();
440    let mut txt = String::new();
441    for c in cipher.clone()
442        { write!(txt, "{:02X} ", c); }
443    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444    println!("-------------------------------");
445}
446
447fn bigcryptor64_decrypt_with_padding_iso_ecb()
448{
449    println!("bigcryptor64_decrypt_with_padding_iso_ecb()");
450    use std::io::Write;
451    use std::fmt::Write as _;
452    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
453
454    // TDES case
455    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
456                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
457                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
458    let message = "In the beginning God created the heavens and the earth.";
459    println!("M =\t{}", message);
460    let mut cipher = Vec::<u8>::new();
461    tdes.encrypt_str_into_vec(&message, &mut cipher);
462    print!("C =\t");
463    for c in cipher.clone()
464        { print!("{:02X} ", c); }
465    println!();
466    let mut txt = String::new();
467    for c in cipher.clone()
468        { write!(txt, "{:02X} ", c); }
469    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
470
471    let mut recovered = vec![0; 55];
472    tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
473    print!("Ba =\t");
474    for b in recovered.clone()
475        { print!("{:02X} ", b); }
476    println!();
477    let mut txt = String::new();
478    for c in recovered.clone()
479        { write!(txt, "{:02X} ", c); }
480    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
481
482    let mut converted = String::new();
483    unsafe { converted.as_mut_vec() }.append(&mut recovered);
484    
485    println!("Bb =\t{}", converted);
486    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
487    assert_eq!(converted, message);
488    println!("-------------------------------");
489}
490
491fn bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()
492{
493    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()");
494    use std::io::Write;
495    use std::fmt::Write as _;
496    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
497
498    // TDES case
499    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502    let message = "In the beginning God created the heavens and the earth.";
503    println!("M =\t{}", message);
504    let mut cipher = Vec::<u8>::new();
505    tdes.encrypt_str_into_vec(&message, &mut cipher);
506    print!("C =\t");
507    for c in cipher.clone()
508        { print!("{:02X} ", c); }
509    println!();
510    let mut txt = String::new();
511    for c in cipher.clone()
512        { write!(txt, "{:02X} ", c); }
513    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515    let mut recovered = Vec::<u8>::new();
516    tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517    print!("Ba =\t");
518    for b in recovered.clone()
519        { print!("{:02X} ", b); }
520    println!();
521    let mut txt = String::new();
522    for c in recovered.clone()
523        { write!(txt, "{:02X} ", c); }
524    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526    let mut converted = String::new();
527    unsafe { converted.as_mut_vec() }.append(&mut recovered);
528    
529    println!("Bb =\t{}", converted);
530    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531    assert_eq!(converted, message);
532    println!("-------------------------------");
533}
534
535fn bigcryptor64_decrypt_with_padding_iso_ecb_into_array()
536{
537    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_array()");
538    use std::io::Write;
539    use std::fmt::Write as _;
540    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
541
542    // TDES case
543    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
544                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
545                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
546    let message = "In the beginning God created the heavens and the earth.";
547    println!("M =\t{}", message);
548    let mut cipher = Vec::<u8>::new();
549    tdes.encrypt_str_into_vec(&message, &mut cipher);
550    print!("C =\t");
551    for c in cipher.clone()
552        { print!("{:02X} ", c); }
553    println!();
554    let mut txt = String::new();
555    for c in cipher.clone()
556        { write!(txt, "{:02X} ", c); }
557    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
558
559    let mut recovered = [0u8; 56];
560    let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
561    print!("Ba =\t");
562    for b in recovered.clone()
563        { print!("{:02X} ", b); }
564    println!();
565    let mut txt = String::new();
566    for c in recovered.clone()
567        { write!(txt, "{:02X} ", c); }
568    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
569
570    let mut converted = String::new();
571    unsafe { converted.as_mut_vec() }.write(&recovered);
572    unsafe { converted.as_mut_vec() }.truncate(len as usize);
573    println!("Bb =\t{}", converted);
574    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
575    assert_eq!(converted, message);
576    println!("-------------------------------");
577}
578
579fn bigcryptor64_decrypt_with_padding_iso_ecb_into_string()
580{
581    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_string()");
582    use std::io::Write;
583    use std::fmt::Write as _;
584    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
585
586    // TDES case
587    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590    let message = "In the beginning God created the heavens and the earth.";
591    println!("M =\t{}", message);
592    let mut cipher = Vec::<u8>::new();
593    tdes.encrypt_str_into_vec(&message, &mut cipher);
594    print!("C =\t");
595    for c in cipher.clone()
596        { print!("{:02X} ", c); }
597    println!();
598    let mut txt = String::new();
599    for c in cipher.clone()
600        { write!(txt, "{:02X} ", c); }
601    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603    let mut recovered = String::new();
604    tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605    println!("B =\t{}", recovered);
606    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607    assert_eq!(recovered, message);
608    println!("-------------------------------");
609}
610
611fn bigcryptor64_decrypt_vec_with_padding_iso_ecb()
612{
613    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb()");
614    use std::io::Write;
615    use std::fmt::Write as _;
616    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
617
618    // TDES case
619    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622    let message = "In the beginning God created the heavens and the earth.";
623    println!("M =\t{}", message);
624    let mut cipher = Vec::<u8>::new();
625    tdes.encrypt_str_into_vec(&message, &mut cipher);
626    print!("C =\t");
627    for c in cipher.clone()
628        { print!("{:02X} ", c); }
629    println!();
630    let mut txt = String::new();
631    for c in cipher.clone()
632        { write!(txt, "{:02X} ", c); }
633    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635    let mut recovered = vec![0; 55];
636    tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637    print!("Ba =\t");
638    for b in recovered.clone()
639        { print!("{:02X} ", b); }
640    println!();
641    let mut txt = String::new();
642    for c in recovered.clone()
643        { write!(txt, "{:02X} ", c); }
644    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646    let mut converted = String::new();
647    unsafe { converted.as_mut_vec() }.append(&mut recovered);
648    
649    println!("Bb =\t{}", converted);
650    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651    assert_eq!(converted, message);
652    println!("-------------------------------");
653}
654
655fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()
656{
657    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()");
658    use std::io::Write;
659    use std::fmt::Write as _;
660    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
661
662    // TDES case
663    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666    let message = "In the beginning God created the heavens and the earth.";
667    println!("M =\t{}", message);
668    let mut cipher = Vec::<u8>::new();
669    tdes.encrypt_str_into_vec(&message, &mut cipher);
670    print!("C =\t");
671    for c in cipher.clone()
672        { print!("{:02X} ", c); }
673    println!();
674    let mut txt = String::new();
675    for c in cipher.clone()
676        { write!(txt, "{:02X} ", c); }
677    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679    let mut recovered = Vec::<u8>::new();
680    tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681    print!("Ba =\t");
682    for b in recovered.clone()
683        { print!("{:02X} ", b); }
684    println!();
685    let mut txt = String::new();
686    for c in recovered.clone()
687        { write!(txt, "{:02X} ", c); }
688    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690    let mut converted = String::new();
691    unsafe { converted.as_mut_vec() }.append(&mut recovered);
692    
693    println!("Bb =\t{}", converted);
694    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695    assert_eq!(converted, message);
696    println!("-------------------------------");
697}
698
699fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()
700{
701    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()");
702    use std::io::Write;
703    use std::fmt::Write as _;
704    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
705
706    // TDES case
707    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710    let message = "In the beginning God created the heavens and the earth.";
711    println!("M =\t{}", message);
712    let mut cipher = Vec::<u8>::new();
713    tdes.encrypt_str_into_vec(&message, &mut cipher);
714    print!("C =\t");
715    for c in cipher.clone()
716        { print!("{:02X} ", c); }
717    println!();
718    let mut txt = String::new();
719    for c in cipher.clone()
720        { write!(txt, "{:02X} ", c); }
721    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723    let mut recovered = [0u8; 56];
724    let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725    print!("Ba =\t");
726    for b in recovered.clone()
727        { print!("{:02X} ", b); }
728    println!();
729    let mut txt = String::new();
730    for c in recovered.clone()
731        { write!(txt, "{:02X} ", c); }
732    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734    let mut converted = String::new();
735    unsafe { converted.as_mut_vec() }.write(&recovered);
736    unsafe { converted.as_mut_vec() }.truncate(len as usize);
737    println!("Bb =\t{}", converted);
738    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739    assert_eq!(converted, message);
740    println!("-------------------------------");
741}
742
743fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()
744{
745    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()");
746    use std::io::Write;
747    use std::fmt::Write as _;
748    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
749
750    // TDES case
751    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754    let message = "In the beginning God created the heavens and the earth.";
755    println!("M =\t{}", message);
756    let mut cipher = Vec::<u8>::new();
757    tdes.encrypt_str_into_vec(&message, &mut cipher);
758    print!("C =\t");
759    for c in cipher.clone()
760        { print!("{:02X} ", c); }
761    println!();
762    let mut txt = String::new();
763    for c in cipher.clone()
764        { write!(txt, "{:02X} ", c); }
765    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767    let mut recovered = String::new();
768    tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769    println!("B =\t{}", recovered);
770    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771    assert_eq!(recovered, message);
772    println!("-------------------------------");
773}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 181)
166fn bigcryptor128_encrypt_str_with_padding_iso_ecb_into_vec()
167{
168    println!("bigcryptor128_encrypt_str_with_padding_iso_ecb_into_vec()");
169    use std::io::Write;
170    use std::fmt::Write as _;
171    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
172
173    // TAES_128 case
174    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
175                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
176                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
177    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
178    println!("IV =	{:#034X}", iv);
179    let message = "In the beginning God created the heavens and the earth.";
180    let mut cipher = Vec::<u8>::new();
181    taes.encrypt_str_into_vec(&message, &mut cipher);
182    print!("C =\t");
183    for c in cipher.clone()
184        { print!("{:02X} ", c); }
185    println!();
186    let mut txt = String::new();
187    for c in cipher.clone()
188        { write!(txt, "{:02X} ", c); }
189    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
190    println!("-------------------------------");
191}
192
193fn bigcryptor128_encrypt_str_with_padding_iso_ecb_into_array()
194{
195    println!("bigcryptor128_encrypt_str_with_padding_iso_ecb_into_array()");
196    use std::io::Write;
197    use std::fmt::Write as _;
198    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
199
200    // TAES_128 case
201    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
202                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
203                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
204    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
205    println!("IV =	{:#034X}", iv);
206    let message = "In the beginning God created the heavens and the earth.";
207    let mut cipher = [0_u8; 64];
208    taes.encrypt_str_into_array(&message, &mut cipher);
209    print!("C =\t");
210    for c in cipher.clone()
211        { print!("{:02X} ", c); }
212    println!();
213    let mut txt = String::new();
214    for c in cipher.clone()
215        { write!(txt, "{:02X} ", c); }
216    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
217    println!("-------------------------------");
218}
219
220fn bigcryptor128_encrypt_string_with_padding_iso_ecb()
221{
222    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb()");
223    use std::io::Write;
224    use std::fmt::Write as _;
225    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
226
227    // TAES_128 case
228    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
229                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
230                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
231    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
232    println!("IV =	{:#034X}", iv);
233    let message = "In the beginning God created the heavens and the earth.".to_string();
234    let mut cipher = [0_u8; 64];
235    taes.encrypt_string(&message, cipher.as_mut_ptr());
236    print!("C =\t");
237    for c in cipher.clone()
238        { print!("{:02X} ", c); }
239    println!();
240    let mut txt = String::new();
241    for c in cipher.clone()
242        { write!(txt, "{:02X} ", c); }
243    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
244    println!("-------------------------------");
245}
246
247fn bigcryptor128_encrypt_string_with_padding_iso_ecb_into_vec()
248{
249    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb_into_vec()");
250    use std::io::Write;
251    use std::fmt::Write as _;
252    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
253
254    // TAES_128 case
255    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
256                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
257                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
258    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
259    println!("IV =	{:#034X}", iv);
260    let message = "In the beginning God created the heavens and the earth.".to_string();
261    let mut cipher = Vec::<u8>::new();
262    taes.encrypt_string_into_vec(&message, &mut cipher);
263    print!("C =\t");
264    for c in cipher.clone()
265        { print!("{:02X} ", c); }
266    println!();
267    let mut txt = String::new();
268    for c in cipher.clone()
269        { write!(txt, "{:02X} ", c); }
270    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
271    println!("-------------------------------");
272}
273
274fn bigcryptor128_encrypt_string_with_padding_iso_ecb_into_array()
275{
276    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb_into_array()");
277    use std::io::Write;
278    use std::fmt::Write as _;
279    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
280
281    // TAES_128 case
282    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
283                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
284                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
285    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
286    println!("IV =	{:#034X}", iv);
287    let message = "In the beginning God created the heavens and the earth.".to_string();
288    let mut cipher = [0_u8; 64];
289    taes.encrypt_string_into_array(&message, &mut cipher);
290    print!("C =\t");
291    for c in cipher.clone()
292        { print!("{:02X} ", c); }
293    println!();
294    let mut txt = String::new();
295    for c in cipher.clone()
296        { write!(txt, "{:02X} ", c); }
297    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
298    println!("-------------------------------");
299}
300
301fn bigcryptor128_encrypt_vec_with_padding_iso_ecb()
302{
303    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb()");
304    use std::io::Write;
305    use std::fmt::Write as _;
306    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
307
308    // TAES_128 case
309    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
310                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
311                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
312    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
313    println!("IV =	{:#034X}", iv);
314    let message = "In the beginning God created the heavens and the earth.";
315    println!("M =\t{}", message);
316    let message = unsafe { message.to_string().as_mut_vec().clone() };
317    let mut cipher = [0_u8; 64];
318    taes.encrypt_vec(&message, cipher.as_mut_ptr());
319    print!("C =\t");
320    for c in cipher.clone()
321        { print!("{:02X} ", c); }
322    println!();
323    let mut txt = String::new();
324    for c in cipher.clone()
325        { write!(txt, "{:02X} ", c); }
326    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
327    println!("-------------------------------");
328}
329
330fn bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_vec()
331{
332    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_vec()");
333    use std::io::Write;
334    use std::fmt::Write as _;
335    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
336
337    // TAES_128 case
338    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
339                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
340                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
341    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
342    println!("IV =	{:#034X}", iv);
343    let message = "In the beginning God created the heavens and the earth.";
344    println!("M =\t{}", message);
345    let message = unsafe { message.to_string().as_mut_vec().clone() };
346    let mut cipher = Vec::<u8>::new();
347    taes.encrypt_vec_into_vec(&message, &mut cipher);
348    print!("C =\t");
349    for c in cipher.clone()
350        { print!("{:02X} ", c); }
351    println!();
352    let mut txt = String::new();
353    for c in cipher.clone()
354        { write!(txt, "{:02X} ", c); }
355    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
356    println!("-------------------------------");
357}
358
359fn bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_array()
360{
361    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_array()");
362    use std::io::Write;
363    use std::fmt::Write as _;
364    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
365
366    // TAES_128 case
367    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
368                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
369                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
370    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
371    println!("IV =	{:#034X}", iv);
372    let message = "In the beginning God created the heavens and the earth.";
373    println!("M =\t{}", message);
374    let message = unsafe { message.to_string().as_mut_vec().clone() };
375    let mut cipher = [0_u8; 64];
376    taes.encrypt_vec_into_array(&message, &mut cipher);
377    print!("C =\t");
378    for c in cipher.clone()
379        { print!("{:02X} ", c); }
380    println!();
381    let mut txt = String::new();
382    for c in cipher.clone()
383        { write!(txt, "{:02X} ", c); }
384    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
385    println!("-------------------------------");
386}
387
388fn bigcryptor128_encrypt_array_with_padding_iso_ecb()
389{
390    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb()");
391    use std::io::Write;
392    use std::fmt::Write as _;
393    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
394
395    // TAES_128 case
396    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
397                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
398                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
399    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
400    println!("IV =	{:#034X}", iv);
401    let mes = "In the beginning God created the heavens and the earth.";
402    println!("M =\t{}", mes);
403    let mut message = [0_u8; 55];
404    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405    let mut cipher = [0_u8; 64];
406    taes.encrypt_array(&message, cipher.as_mut_ptr());
407    print!("C =\t");
408    for c in cipher.clone()
409        { print!("{:02X} ", c); }
410    println!();
411    let mut txt = String::new();
412    for c in cipher.clone()
413        { write!(txt, "{:02X} ", c); }
414    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
415    println!("-------------------------------");
416}
417
418fn bigcryptor128_encrypt_array_with_padding_iso_ecb_into_vec()
419{
420    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb_into_vec()");
421    use std::io::Write;
422    use std::fmt::Write as _;
423    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
424
425    // TAES_128 case
426    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
427                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
428                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
429    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
430    println!("IV =	{:#034X}", iv);
431    let mes = "In the beginning God created the heavens and the earth.";
432    println!("M =\t{}", mes);
433    let mut message = [0_u8; 55];
434    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435    let mut cipher = Vec::<u8>::new();
436    taes.encrypt_array_into_vec(&message, &mut cipher);
437    print!("C =\t");
438    for c in cipher.clone()
439        { print!("{:02X} ", c); }
440    println!();
441    let mut txt = String::new();
442    for c in cipher.clone()
443        { write!(txt, "{:02X} ", c); }
444    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
445    println!("-------------------------------");
446}
447
448fn bigcryptor128_encrypt_array_with_padding_iso_ecb_into_array()
449{
450    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb_into_array()");
451    use std::io::Write;
452    use std::fmt::Write as _;
453    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
454
455    // TAES_128 case
456    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
457                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
458                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
459    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
460    println!("IV =	{:#034X}", iv);
461    let mes = "In the beginning God created the heavens and the earth.";
462    println!("M =\t{}", mes);
463    let mut message = [0_u8; 55];
464    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465    let mut cipher = [0_u8; 64];
466    taes.encrypt_array_into_array(&message, &mut cipher);
467    for c in cipher.clone()
468        { print!("{:02X} ", c); }
469    println!();
470    let mut txt = String::new();
471    for c in cipher.clone()
472        { write!(txt, "{:02X} ", c); }
473    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
474    println!("-------------------------------");
475}
476
477fn bigcryptor128_decrypt_with_padding_iso_ecb()
478{
479    println!("bigcryptor128_decrypt_with_padding_iso_ecb()");
480    use std::io::Write;
481    use std::fmt::Write as _;
482    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
483
484    // TAES_128 case
485    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
486                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
487                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
488    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
489    println!("IV =	{:#034X}", iv);
490    let message = "In the beginning God created the heavens and the earth.";
491    println!("M =\t{}", message);
492    let mut cipher = Vec::<u8>::new();
493    taes.encrypt_str_into_vec(&message, &mut cipher);
494    print!("C =\t");
495    for c in cipher.clone()
496        { print!("{:02X} ", c); }
497    println!();
498    let mut txt = String::new();
499    for c in cipher.clone()
500        { write!(txt, "{:02X} ", c); }
501    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
502
503    let mut recovered = vec![0; 55];
504    taes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
505    print!("Ba =\t");
506    for b in recovered.clone()
507        { print!("{:02X} ", b); }
508    println!();
509    let mut txt = String::new();
510    for c in recovered.clone()
511        { write!(txt, "{:02X} ", c); }
512    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
513
514    let mut converted = String::new();
515    unsafe { converted.as_mut_vec() }.append(&mut recovered);
516    
517    println!("Bb =\t{}", converted);
518    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
519    assert_eq!(converted, message);
520    println!("-------------------------------");
521}
522
523fn bigcryptor128_decrypt_with_padding_iso_ecb_into_vec()
524{
525    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_vec()");
526    use std::io::Write;
527    use std::fmt::Write as _;
528    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
529
530    // TAES_128 case
531    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
532                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
533                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
534    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
535    println!("IV =	{:#034X}", iv);
536    let message = "In the beginning God created the heavens and the earth.";
537    println!("M =\t{}", message);
538    let mut cipher = Vec::<u8>::new();
539    taes.encrypt_str_into_vec(&message, &mut cipher);
540    print!("C =\t");
541    for c in cipher.clone()
542        { print!("{:02X} ", c); }
543    println!();
544    let mut txt = String::new();
545    for c in cipher.clone()
546        { write!(txt, "{:02X} ", c); }
547    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
548
549    let mut recovered = Vec::<u8>::new();
550    taes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551    print!("Ba =\t");
552    for b in recovered.clone()
553        { print!("{:02X} ", b); }
554    println!();
555    let mut txt = String::new();
556    for c in recovered.clone()
557        { write!(txt, "{:02X} ", c); }
558    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560    let mut converted = String::new();
561    unsafe { converted.as_mut_vec() }.append(&mut recovered);
562    
563    println!("Bb =\t{}", converted);
564    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565    assert_eq!(converted, message);
566    println!("-------------------------------");
567}
568
569fn bigcryptor128_decrypt_with_padding_iso_ecb_into_array()
570{
571    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_array()");
572    use std::io::Write;
573    use std::fmt::Write as _;
574    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
575
576    // TAES_128 case
577    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
578                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
579                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
580    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
581    println!("IV =	{:#034X}", iv);
582    let message = "In the beginning God created the heavens and the earth.";
583    println!("M =\t{}", message);
584    let mut cipher = Vec::<u8>::new();
585    taes.encrypt_str_into_vec(&message, &mut cipher);
586    print!("C =\t");
587    for c in cipher.clone()
588        { print!("{:02X} ", c); }
589    println!();
590    let mut txt = String::new();
591    for c in cipher.clone()
592        { write!(txt, "{:02X} ", c); }
593    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
594
595    let mut recovered = [0u8; 64];
596    let len = taes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
597    print!("Ba =\t");
598    for b in recovered.clone()
599        { print!("{:02X} ", b); }
600    println!();
601    let mut txt = String::new();
602    for c in recovered.clone()
603        { write!(txt, "{:02X} ", c); }
604    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
605
606    let mut converted = String::new();
607    unsafe { converted.as_mut_vec() }.write(&recovered);
608    unsafe { converted.as_mut_vec() }.truncate(len as usize);
609    println!("Bb =\t{}", converted);
610    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
611    assert_eq!(converted, message);
612    println!("-------------------------------");
613}
614
615fn bigcryptor128_decrypt_with_padding_iso_ecb_into_string()
616{
617    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_string()");
618    use std::io::Write;
619    use std::fmt::Write as _;
620    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
621
622    // TAES_128 case
623    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
624                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
625                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
626    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
627    println!("IV =	{:#034X}", iv);
628    let message = "In the beginning God created the heavens and the earth.";
629    println!("M =\t{}", message);
630    let mut cipher = Vec::<u8>::new();
631    taes.encrypt_str_into_vec(&message, &mut cipher);
632    print!("C =\t");
633    for c in cipher.clone()
634        { print!("{:02X} ", c); }
635    println!();
636    let mut txt = String::new();
637    for c in cipher.clone()
638        { write!(txt, "{:02X} ", c); }
639    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
640
641    let mut recovered = String::new();
642    taes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643    println!("B =\t{}", recovered);
644    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645    assert_eq!(recovered, message);
646    println!("-------------------------------");
647}
648
649fn bigcryptor128_decrypt_vec_with_padding_iso_ecb()
650{
651    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb()");
652    use std::io::Write;
653    use std::fmt::Write as _;
654    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
655
656    // TAES_128 case
657    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
658                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
659                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
660    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
661    println!("IV =	{:#034X}", iv);
662    let message = "In the beginning God created the heavens and the earth.";
663    println!("M =\t{}", message);
664    let mut cipher = Vec::<u8>::new();
665    taes.encrypt_str_into_vec(&message, &mut cipher);
666    print!("C =\t");
667    for c in cipher.clone()
668        { print!("{:02X} ", c); }
669    println!();
670    let mut txt = String::new();
671    for c in cipher.clone()
672        { write!(txt, "{:02X} ", c); }
673    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
674
675    let mut recovered = vec![0; 55];
676    taes.decrypt_vec(&cipher, recovered.as_mut_ptr());
677    print!("Ba =\t");
678    for b in recovered.clone()
679        { print!("{:02X} ", b); }
680    println!();
681    let mut txt = String::new();
682    for c in recovered.clone()
683        { write!(txt, "{:02X} ", c); }
684    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686    let mut converted = String::new();
687    unsafe { converted.as_mut_vec() }.append(&mut recovered);
688    
689    println!("Bb =\t{}", converted);
690    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691    assert_eq!(converted, message);
692    println!("-------------------------------");
693}
694
695fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_vec()
696{
697    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_vec()");
698    use std::io::Write;
699    use std::fmt::Write as _;
700    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
701
702    // TAES_128 case
703    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
704                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
705                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
706    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
707    println!("IV =	{:#034X}", iv);
708    let message = "In the beginning God created the heavens and the earth.";
709    println!("M =\t{}", message);
710    let mut cipher = Vec::<u8>::new();
711    taes.encrypt_str_into_vec(&message, &mut cipher);
712    print!("C =\t");
713    for c in cipher.clone()
714        { print!("{:02X} ", c); }
715    println!();
716    let mut txt = String::new();
717    for c in cipher.clone()
718        { write!(txt, "{:02X} ", c); }
719    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
720
721    let mut recovered = Vec::<u8>::new();
722    taes.decrypt_vec_into_vec(&cipher, &mut recovered);
723    print!("Ba =\t");
724    for b in recovered.clone()
725        { print!("{:02X} ", b); }
726    println!();
727    let mut txt = String::new();
728    for c in recovered.clone()
729        { write!(txt, "{:02X} ", c); }
730    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732    let mut converted = String::new();
733    unsafe { converted.as_mut_vec() }.append(&mut recovered);
734    
735    println!("Bb =\t{}", converted);
736    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737    assert_eq!(converted, message);
738    println!("-------------------------------");
739}
740
741fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_array()
742{
743    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_array()");
744    use std::io::Write;
745    use std::fmt::Write as _;
746    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
747
748    // TAES_128 case
749    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
750                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
751                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
752    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
753    println!("IV =	{:#034X}", iv);
754    let message = "In the beginning God created the heavens and the earth.";
755    println!("M =\t{}", message);
756    let mut cipher = Vec::<u8>::new();
757    taes.encrypt_str_into_vec(&message, &mut cipher);
758    print!("C =\t");
759    for c in cipher.clone()
760        { print!("{:02X} ", c); }
761    println!();
762    let mut txt = String::new();
763    for c in cipher.clone()
764        { write!(txt, "{:02X} ", c); }
765    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
766
767    let mut recovered = [0u8; 64];
768    let len = taes.decrypt_vec_into_array(&cipher, &mut recovered);
769    print!("Ba =\t");
770    for b in recovered.clone()
771        { print!("{:02X} ", b); }
772    println!();
773    let mut txt = String::new();
774    for c in recovered.clone()
775        { write!(txt, "{:02X} ", c); }
776    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
777
778    let mut converted = String::new();
779    unsafe { converted.as_mut_vec() }.write(&recovered);
780    unsafe { converted.as_mut_vec() }.truncate(len as usize);
781    println!("Bb =\t{}", converted);
782    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783    assert_eq!(converted, message);
784    println!("-------------------------------");
785}
786
787fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_string()
788{
789    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_string()");
790    use std::io::Write;
791    use std::fmt::Write as _;
792    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
793
794    // TAES_128 case
795    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
796                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
797                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
798    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
799    println!("IV =	{:#034X}", iv);
800    let message = "In the beginning God created the heavens and the earth.";
801    println!("M =\t{}", message);
802    let mut cipher = Vec::<u8>::new();
803    taes.encrypt_str_into_vec(&message, &mut cipher);
804    print!("C =\t");
805    for c in cipher.clone()
806        { print!("{:02X} ", c); }
807    println!();
808    let mut txt = String::new();
809    for c in cipher.clone()
810        { write!(txt, "{:02X} ", c); }
811    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
812
813    let mut recovered = String::new();
814    taes.decrypt_vec_into_string(&cipher, &mut recovered);
815    println!("B =\t{}", recovered);
816    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817    assert_eq!(recovered, message);
818    println!("-------------------------------");
819}
examples/aes_ecb_iso_examples.rs (line 536)
521fn aes_encrypt_str_with_padding_iso_ecb_into_vec()
522{
523    println!("aes_encrypt_str_with_padding_iso_ecb_into_vec()");
524    use std::io::Write;
525    use std::fmt::Write as _;
526    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
527
528    // Normal case for AES-128
529    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
530    println!("K =\t{:#016X}", key);
531    let mut a_aes = AES_128::new_with_key_u128(key);
532
533    let message = "In the beginning God created the heavens and the earth.";
534    println!("M =\t{}", message);
535    let mut cipher = Vec::<u8>::new();
536    a_aes.encrypt_str_into_vec(&message, &mut cipher);
537    print!("C =\t");
538    for c in cipher.clone()
539        { print!("{:02X} ", c); }
540    println!();
541    let mut txt = String::new();
542    for c in cipher.clone()
543        { write!(txt, "{:02X} ", c); }
544    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
545    println!();
546
547    // Normal case for AES-192
548    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
549    print!("K =\t");
550    for i in 0..24
551        { print!("{:02X}", key[i]); }
552    println!();
553    let mut a_aes = AES_192::new_with_key(&key);
554
555    let message = "In the beginning God created the heavens and the earth.";
556    println!("M =\t{}", message);
557    let mut cipher = Vec::<u8>::new();
558    a_aes.encrypt_str_into_vec(&message, &mut cipher);
559    print!("C =\t");
560    for c in cipher.clone()
561        { print!("{:02X} ", c); }
562    println!();
563    let mut txt = String::new();
564    for c in cipher.clone()
565        { write!(txt, "{:02X} ", c); }
566    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
567    println!();
568
569    // Normal case for AES-256
570    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
571    print!("K =\t");
572    for i in 0..32
573        { print!("{:02X}", key[i]); }
574    println!();
575    let mut a_aes = AES_256::new_with_key(&key);
576
577    let message = "In the beginning God created the heavens and the earth.";
578    println!("M =\t{}", message);
579    let mut cipher = Vec::<u8>::new();
580    a_aes.encrypt_str_into_vec(&message, &mut cipher);
581    print!("C =\t");
582    for c in cipher.clone()
583        { print!("{:02X} ", c); }
584    println!();
585    let mut txt = String::new();
586    for c in cipher.clone()
587        { write!(txt, "{:02X} ", c); }
588    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
589    println!();
590
591    // Normal case for Rijndael-256-256
592    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
593    print!("K =\t");
594    for i in 0..32
595        { print!("{:02X}", key[i]); }
596    println!();
597    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
598
599    let message = "In the beginning God created the heavens and the earth.";
600    println!("M =\t{}", message);
601    let mut cipher = Vec::<u8>::new();
602    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
603    print!("C =\t");
604    for c in cipher.clone()
605        { print!("{:02X} ", c); }
606    println!();
607    let mut txt = String::new();
608    for c in cipher.clone()
609        { write!(txt, "{:02X} ", c); }
610    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
611    println!();
612
613    // Normal case for Rijndael-512-512 for post-quantum
614    use cryptocol::number::SharedArrays;
615    use cryptocol::hash::SHA3_512;
616    let mut sha3 = SHA3_512::new();
617    sha3.absorb_str("Post-quantum");
618    let key: [u8; 64] = sha3.get_hash_value_in_array();
619    print!("K =\t");
620    for i in 0..64
621        { print!("{:02X}", key[i]); }
622    println!();
623    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
624    let message = "In the beginning God created the heavens and the earth.";
625    println!("M =\t{}", message);
626    let mut cipher = Vec::<u8>::new();
627    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
628    print!("C =\t");
629    for c in cipher.clone()
630        { print!("{:02X} ", c); }
631    println!();
632    let mut txt = String::new();
633    for c in cipher.clone()
634        { write!(txt, "{:02X} ", c); }
635    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
636    println!("-------------------------------");
637}
638
639fn aes_encrypt_str_with_padding_iso_ecb_into_array()
640{
641    println!("aes_encrypt_str_with_padding_iso_ecb_into_array()");
642    use std::io::Write;
643    use std::fmt::Write as _;
644    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
645
646    // Normal case for AES-128
647    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
648    println!("K =\t{:#016X}", key);
649    let mut a_aes = AES_128::new_with_key_u128(key);
650
651    let message = "In the beginning God created the heavens and the earth.";
652    println!("M =\t{}", message);
653    let mut cipher = [0_u8; 64];
654    a_aes.encrypt_str_into_array(&message, &mut cipher);
655    print!("C =\t");
656    for c in cipher.clone()
657        { print!("{:02X} ", c); }
658    println!();
659    let mut txt = String::new();
660    for c in cipher.clone()
661        { write!(txt, "{:02X} ", c); }
662    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
663    println!();
664
665    // Normal case for AES-192
666    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
667    print!("K =\t");
668    for i in 0..24
669        { print!("{:02X}", key[i]); }
670    println!();
671    let mut a_aes = AES_192::new_with_key(&key);
672
673    let message = "In the beginning God created the heavens and the earth.";
674    println!("M =\t{}", message);
675    let mut cipher = [0_u8; 64];
676    a_aes.encrypt_str_into_array(&message, &mut cipher);
677    print!("C =\t");
678    for c in cipher.clone()
679        { print!("{:02X} ", c); }
680    println!();
681    let mut txt = String::new();
682    for c in cipher.clone()
683        { write!(txt, "{:02X} ", c); }
684    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
685    println!();
686
687    // Normal case for AES-256
688    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
689    print!("K =\t");
690    for i in 0..32
691        { print!("{:02X}", key[i]); }
692    println!();
693    let mut a_aes = AES_256::new_with_key(&key);
694
695    let message = "In the beginning God created the heavens and the earth.";
696    println!("M =\t{}", message);
697    let mut cipher = [0_u8; 64];
698    a_aes.encrypt_str_into_array(&message, &mut cipher);
699    print!("C =\t");
700    for c in cipher.clone()
701        { print!("{:02X} ", c); }
702    println!();
703    let mut txt = String::new();
704    for c in cipher.clone()
705        { write!(txt, "{:02X} ", c); }
706    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
707    println!();
708
709    // Normal case for Rijndael-256-256
710    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
711    print!("K =\t");
712    for i in 0..32
713        { print!("{:02X}", key[i]); }
714    println!();
715    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
716
717    let message = "In the beginning God created the heavens and the earth.";
718    println!("M =\t{}", message);
719    let mut cipher = [0_u8; 64];
720    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
721    print!("C =\t");
722    for c in cipher.clone()
723        { print!("{:02X} ", c); }
724    println!();
725    let mut txt = String::new();
726    for c in cipher.clone()
727        { write!(txt, "{:02X} ", c); }
728    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
729    println!();
730
731    // Normal case for Rijndael-512-512 for post-quantum
732    use cryptocol::number::SharedArrays;
733    use cryptocol::hash::SHA3_512;
734    let mut sha3 = SHA3_512::new();
735    sha3.absorb_str("Post-quantum");
736    let key: [u8; 64] = sha3.get_hash_value_in_array();
737    print!("K =\t");
738    for i in 0..64
739        { print!("{:02X}", key[i]); }
740    println!();
741    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
742    let message = "In the beginning God created the heavens and the earth.";
743    println!("M =\t{}", message);
744    let mut cipher = [0_u8; 64];
745    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
746    print!("C =\t");
747    for c in cipher.clone()
748        { print!("{:02X} ", c); }
749    println!();
750    let mut txt = String::new();
751    for c in cipher.clone()
752        { write!(txt, "{:02X} ", c); }
753    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
754    println!("-------------------------------");
755}
756
757fn aes_encrypt_string_with_padding_iso_ecb()
758{
759    println!("aes_encrypt_string_with_padding_iso_ecb()");
760    use std::io::Write;
761    use std::fmt::Write as _;
762    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
763
764    // Normal case for AES-128
765    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
766    println!("K =\t{:#016X}", key);
767    let mut a_aes = AES_128::new_with_key_u128(key);
768
769    let message = "In the beginning God created the heavens and the earth.".to_string();
770    println!("M =\t{}", message);
771    let mut cipher = [0_u8; 64];
772    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
773    print!("C =\t");
774    for c in cipher.clone()
775        { print!("{:02X} ", c); }
776    println!();
777    let mut txt = String::new();
778    for c in cipher.clone()
779        { write!(txt, "{:02X} ", c); }
780    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
781    println!();
782
783    // Normal case for AES-192
784    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
785    print!("K =\t");
786    for i in 0..24
787        { print!("{:02X}", key[i]); }
788    println!();
789    let mut a_aes = AES_192::new_with_key(&key);
790
791    let message = "In the beginning God created the heavens and the earth.".to_string();
792    println!("M =\t{}", message);
793    let mut cipher = [0_u8; 64];
794    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
795    print!("C =\t");
796    for c in cipher.clone()
797        { print!("{:02X} ", c); }
798    println!();
799    let mut txt = String::new();
800    for c in cipher.clone()
801        { write!(txt, "{:02X} ", c); }
802    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
803    println!();
804
805    // Normal case for AES-256
806    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
807    print!("K =\t");
808    for i in 0..32
809        { print!("{:02X}", key[i]); }
810    println!();
811    let mut a_aes = AES_256::new_with_key(&key);
812
813    let message = "In the beginning God created the heavens and the earth.".to_string();
814    println!("M =\t{}", message);
815    let mut cipher = [0_u8; 64];
816    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
817    print!("C =\t");
818    for c in cipher.clone()
819        { print!("{:02X} ", c); }
820    println!();
821    let mut txt = String::new();
822    for c in cipher.clone()
823        { write!(txt, "{:02X} ", c); }
824    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
825    println!();
826
827    // Normal case for Rijndael-256-256
828    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
829    print!("K =\t");
830    for i in 0..32
831        { print!("{:02X}", key[i]); }
832    println!();
833    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
834
835    let message = "In the beginning God created the heavens and the earth.".to_string();
836    println!("M =\t{}", message);
837    let mut cipher = [0_u8; 64];
838    a_rijndael.encrypt_string(&message, cipher.as_mut_ptr());
839    print!("C =\t");
840    for c in cipher.clone()
841        { print!("{:02X} ", c); }
842    println!();
843    let mut txt = String::new();
844    for c in cipher.clone()
845        { write!(txt, "{:02X} ", c); }
846    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
847    println!();
848
849    // Normal case for Rijndael-512-512 for post-quantum
850    use cryptocol::number::SharedArrays;
851    use cryptocol::hash::SHA3_512;
852    let mut sha3 = SHA3_512::new();
853    sha3.absorb_str("Post-quantum");
854    let key: [u8; 64] = sha3.get_hash_value_in_array();
855    print!("K =\t");
856    for i in 0..64
857        { print!("{:02X}", key[i]); }
858    println!();
859    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
860
861    let message = "In the beginning God created the heavens and the earth.".to_string();
862    println!("M =\t{}", message);
863    let mut cipher = [0_u8; 64];
864    a_rijndael.encrypt_string(&message, cipher.as_mut_ptr());
865    print!("C =\t");
866    for c in cipher.clone()
867        { print!("{:02X} ", c); }
868    println!();
869    let mut txt = String::new();
870    for c in cipher.clone()
871        { write!(txt, "{:02X} ", c); }
872    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
873    println!("-------------------------------");
874}
875
876fn aes_encrypt_string_with_padding_iso_ecb_into_vec()
877{
878    println!("aes_encrypt_string_with_padding_iso_ecb_into_vec()");
879    use std::io::Write;
880    use std::fmt::Write as _;
881    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
882
883    // Normal case for AES-128
884    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
885    println!("K =\t{:#016X}", key);
886    let mut a_aes = AES_128::new_with_key_u128(key);
887
888    let message = "In the beginning God created the heavens and the earth.".to_string();
889    println!("M =\t{}", message);
890    let mut cipher = Vec::<u8>::new();
891    a_aes.encrypt_string_into_vec(&message, &mut cipher);
892    print!("C =\t");
893    for c in cipher.clone()
894        { print!("{:02X} ", c); }
895    println!();
896    let mut txt = String::new();
897    for c in cipher.clone()
898        { write!(txt, "{:02X} ", c); }
899    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
900    println!();
901
902    // Normal case for AES-192
903    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
904    print!("K =\t");
905    for i in 0..24
906        { print!("{:02X}", key[i]); }
907    println!();
908    let mut a_aes = AES_192::new_with_key(&key);
909
910    let message = "In the beginning God created the heavens and the earth.".to_string();
911    println!("M =\t{}", message);
912    let mut cipher = Vec::<u8>::new();
913    a_aes.encrypt_string_into_vec(&message, &mut cipher);
914    print!("C =\t");
915    for c in cipher.clone()
916        { print!("{:02X} ", c); }
917    println!();
918    let mut txt = String::new();
919    for c in cipher.clone()
920        { write!(txt, "{:02X} ", c); }
921    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
922    println!();
923
924    // Normal case for AES-256
925    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
926    print!("K =\t");
927    for i in 0..32
928        { print!("{:02X}", key[i]); }
929    println!();
930    let mut a_aes = AES_256::new_with_key(&key);
931
932    let message = "In the beginning God created the heavens and the earth.".to_string();
933    println!("M =\t{}", message);
934    let mut cipher = Vec::<u8>::new();
935    a_aes.encrypt_string_into_vec(&message, &mut cipher);
936    print!("C =\t");
937    for c in cipher.clone()
938        { print!("{:02X} ", c); }
939    println!();
940    let mut txt = String::new();
941    for c in cipher.clone()
942        { write!(txt, "{:02X} ", c); }
943    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
944    println!();
945
946    // Normal case for Rijndael-256-256
947    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
948    print!("K =\t");
949    for i in 0..32
950        { print!("{:02X}", key[i]); }
951    println!();
952    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
953
954    let message = "In the beginning God created the heavens and the earth.".to_string();
955    println!("M =\t{}", message);
956    let mut cipher = Vec::<u8>::new();
957    a_rijndael.encrypt_string_into_vec(&message, &mut cipher);
958    print!("C =\t");
959    for c in cipher.clone()
960        { print!("{:02X} ", c); }
961    println!();
962    let mut txt = String::new();
963    for c in cipher.clone()
964        { write!(txt, "{:02X} ", c); }
965    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
966    println!();
967
968    // Normal case for Rijndael-512-512 for post-quantum
969    use cryptocol::number::SharedArrays;
970    use cryptocol::hash::SHA3_512;
971    let mut sha3 = SHA3_512::new();
972    sha3.absorb_str("Post-quantum");
973    let key: [u8; 64] = sha3.get_hash_value_in_array();
974    print!("K =\t");
975    for i in 0..64
976        { print!("{:02X}", key[i]); }
977    println!();
978    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
979    let message = "In the beginning God created the heavens and the earth.".to_string();
980    println!("M =\t{}", message);
981    let mut cipher = Vec::<u8>::new();
982    a_rijndael.encrypt_string_into_vec(&message, &mut cipher);
983    print!("C =\t");
984    for c in cipher.clone()
985        { print!("{:02X} ", c); }
986    println!();
987    let mut txt = String::new();
988    for c in cipher.clone()
989        { write!(txt, "{:02X} ", c); }
990    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
991    println!("-------------------------------");
992}
993
994fn aes_encrypt_string_with_padding_iso_ecb_into_array()
995{
996    println!("aes_encrypt_string_with_padding_iso_ecb_into_array()");
997    use std::io::Write;
998    use std::fmt::Write as _;
999    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1000
1001    // Normal case for AES-128
1002    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1003    println!("K =\t{:#016X}", key);
1004    let mut a_aes = AES_128::new_with_key_u128(key);
1005
1006    let message = "In the beginning God created the heavens and the earth.".to_string();
1007    println!("M =\t{}", message);
1008    let mut cipher = [0_u8; 64];
1009    a_aes.encrypt_string_into_array(&message, &mut cipher);
1010    print!("C =\t");
1011    for c in cipher.clone()
1012        { print!("{:02X} ", c); }
1013    println!();
1014    let mut txt = String::new();
1015    for c in cipher.clone()
1016        { write!(txt, "{:02X} ", c); }
1017    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1018    println!();
1019
1020    // Normal case for AES-192
1021    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1022    print!("K =\t");
1023    for i in 0..24
1024        { print!("{:02X}", key[i]); }
1025    println!();
1026    let mut a_aes = AES_192::new_with_key(&key);
1027
1028    let message = "In the beginning God created the heavens and the earth.".to_string();
1029    println!("M =\t{}", message);
1030    let mut cipher = [0_u8; 64];
1031    a_aes.encrypt_string_into_array(&message, &mut cipher);
1032    print!("C =\t");
1033    for c in cipher.clone()
1034        { print!("{:02X} ", c); }
1035    println!();
1036    let mut txt = String::new();
1037    for c in cipher.clone()
1038        { write!(txt, "{:02X} ", c); }
1039    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1040    println!();
1041
1042    // Normal case for AES-256
1043    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1044    print!("K =\t");
1045    for i in 0..32
1046        { print!("{:02X}", key[i]); }
1047    println!();
1048    let mut a_aes = AES_256::new_with_key(&key);
1049
1050    let message = "In the beginning God created the heavens and the earth.".to_string();
1051    println!("M =\t{}", message);
1052    let mut cipher = [0_u8; 64];
1053    a_aes.encrypt_string_into_array(&message, &mut cipher);
1054    print!("C =\t");
1055    for c in cipher.clone()
1056        { print!("{:02X} ", c); }
1057    println!();
1058    let mut txt = String::new();
1059    for c in cipher.clone()
1060        { write!(txt, "{:02X} ", c); }
1061    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1062    println!();
1063
1064    // Normal case for Rijndael-256-256
1065    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1066    print!("K =\t");
1067    for i in 0..32
1068        { print!("{:02X}", key[i]); }
1069    println!();
1070    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1071
1072    let message = "In the beginning God created the heavens and the earth.".to_string();
1073    println!("M =\t{}", message);
1074    let mut cipher = [0_u8; 64];
1075    a_rijndael.encrypt_string_into_array(&message, &mut cipher);
1076    print!("C =\t");
1077    for c in cipher.clone()
1078        { print!("{:02X} ", c); }
1079    println!();
1080    let mut txt = String::new();
1081    for c in cipher.clone()
1082        { write!(txt, "{:02X} ", c); }
1083    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1084    println!();
1085
1086    // Normal case for Rijndael-512-512 for post-quantum
1087    use cryptocol::number::SharedArrays;
1088    use cryptocol::hash::SHA3_512;
1089    let mut sha3 = SHA3_512::new();
1090    sha3.absorb_str("Post-quantum");
1091    let key: [u8; 64] = sha3.get_hash_value_in_array();
1092    print!("K =\t");
1093    for i in 0..64
1094        { print!("{:02X}", key[i]); }
1095    println!();
1096    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1097    let message = "In the beginning God created the heavens and the earth.".to_string();
1098    println!("M =\t{}", message);
1099    let mut cipher = [0_u8; 64];
1100    a_rijndael.encrypt_string_into_array(&message, &mut cipher);
1101    print!("C =\t");
1102    for c in cipher.clone()
1103        { print!("{:02X} ", c); }
1104    println!();
1105    let mut txt = String::new();
1106    for c in cipher.clone()
1107        { write!(txt, "{:02X} ", c); }
1108    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1109    println!("-------------------------------");
1110}
1111
1112fn aes_encrypt_vec_with_padding_iso_ecb()
1113{
1114    println!("aes_encrypt_vec_with_padding_iso_ecb()");
1115    use std::io::Write;
1116    use std::fmt::Write as _;
1117    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1118
1119    // Normal case for AES-128
1120    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1121    println!("K =\t{:#016X}", key);
1122    let mut a_aes = AES_128::new_with_key_u128(key);
1123
1124    let message = "In the beginning God created the heavens and the earth.";
1125    println!("M =\t{}", message);
1126    let message = unsafe { message.to_string().as_mut_vec().clone() };
1127    let mut cipher = [0_u8; 64];
1128    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1129    print!("C =\t");
1130    for c in cipher.clone()
1131        { print!("{:02X} ", c); }
1132    println!();
1133    let mut txt = String::new();
1134    for c in cipher.clone()
1135        { write!(txt, "{:02X} ", c); }
1136    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1137    println!();
1138
1139    // Normal case for AES-192
1140    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1141    print!("K =\t");
1142    for i in 0..24
1143        { print!("{:02X}", key[i]); }
1144    println!();
1145    let mut a_aes = AES_192::new_with_key(&key);
1146
1147    let message = "In the beginning God created the heavens and the earth.";
1148    println!("M =\t{}", message);
1149    let message = unsafe { message.to_string().as_mut_vec().clone() };
1150    let mut cipher = [0_u8; 64];
1151    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1152    print!("C =\t");
1153    for c in cipher.clone()
1154        { print!("{:02X} ", c); }
1155    println!();
1156    let mut txt = String::new();
1157    for c in cipher.clone()
1158        { write!(txt, "{:02X} ", c); }
1159    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1160    println!();
1161
1162    // Normal case for AES-256
1163    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1164    print!("K =\t");
1165    for i in 0..32
1166        { print!("{:02X}", key[i]); }
1167    println!();
1168    let mut a_aes = AES_256::new_with_key(&key);
1169
1170    let message = "In the beginning God created the heavens and the earth.";
1171    println!("M =\t{}", message);
1172    let message = unsafe { message.to_string().as_mut_vec().clone() };
1173    let mut cipher = [0_u8; 64];
1174    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1175    print!("C =\t");
1176    for c in cipher.clone()
1177        { print!("{:02X} ", c); }
1178    println!();
1179    let mut txt = String::new();
1180    for c in cipher.clone()
1181        { write!(txt, "{:02X} ", c); }
1182    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1183    println!();
1184
1185    // Normal case for Rijndael-256-256
1186    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1187    print!("K =\t");
1188    for i in 0..32
1189        { print!("{:02X}", key[i]); }
1190    println!();
1191    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1192
1193    let message = "In the beginning God created the heavens and the earth.";
1194    println!("M =\t{}", message);
1195    let message = unsafe { message.to_string().as_mut_vec().clone() };
1196    let mut cipher = [0_u8; 64];
1197    a_rijndael.encrypt_vec(&message, cipher.as_mut_ptr());
1198    print!("C =\t");
1199    for c in cipher.clone()
1200        { print!("{:02X} ", c); }
1201    println!();
1202    let mut txt = String::new();
1203    for c in cipher.clone()
1204        { write!(txt, "{:02X} ", c); }
1205    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1206    println!();
1207
1208    // Normal case for Rijndael-512-512 for post-quantum
1209    use cryptocol::number::SharedArrays;
1210    use cryptocol::hash::SHA3_512;
1211    let mut sha3 = SHA3_512::new();
1212    sha3.absorb_str("Post-quantum");
1213    let key: [u8; 64] = sha3.get_hash_value_in_array();
1214    print!("K =\t");
1215    for i in 0..64
1216        { print!("{:02X}", key[i]); }
1217    println!();
1218    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1219    let message = "In the beginning God created the heavens and the earth.";
1220    println!("M =\t{}", message);
1221    let message = unsafe { message.to_string().as_mut_vec().clone() };
1222    let mut cipher = [0_u8; 64];
1223    a_rijndael.encrypt_vec(&message, cipher.as_mut_ptr());
1224    print!("C =\t");
1225    for c in cipher.clone()
1226        { print!("{:02X} ", c); }
1227    println!();
1228    let mut txt = String::new();
1229    for c in cipher.clone()
1230        { write!(txt, "{:02X} ", c); }
1231    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1232    println!("-------------------------------");
1233}
1234
1235fn aes_encrypt_vec_with_padding_iso_ecb_into_vec()
1236{
1237    println!("aes_encrypt_vec_with_padding_iso_ecb_into_vec()");
1238    use std::io::Write;
1239    use std::fmt::Write as _;
1240    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1241
1242    // Normal case for AES-128
1243    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1244    println!("K =\t{:#016X}", key);
1245    let mut a_aes = AES_128::new_with_key_u128(key);
1246
1247    let message = "In the beginning God created the heavens and the earth.";
1248    println!("M =\t{}", message);
1249    let message = unsafe { message.to_string().as_mut_vec().clone() };
1250    let mut cipher = Vec::<u8>::new();
1251    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1252    print!("C =\t");
1253    for c in cipher.clone()
1254        { print!("{:02X} ", c); }
1255    println!();
1256    let mut txt = String::new();
1257    for c in cipher.clone()
1258        { write!(txt, "{:02X} ", c); }
1259    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1260    println!();
1261
1262    // Normal case for AES-192
1263    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1264    print!("K =\t");
1265    for i in 0..24
1266        { print!("{:02X}", key[i]); }
1267    println!();
1268    let mut a_aes = AES_192::new_with_key(&key);
1269
1270    let message = "In the beginning God created the heavens and the earth.";
1271    println!("M =\t{}", message);
1272    let message = unsafe { message.to_string().as_mut_vec().clone() };
1273    let mut cipher = Vec::<u8>::new();
1274    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1275    print!("C =\t");
1276    for c in cipher.clone()
1277        { print!("{:02X} ", c); }
1278    println!();
1279    let mut txt = String::new();
1280    for c in cipher.clone()
1281        { write!(txt, "{:02X} ", c); }
1282    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1283    println!();
1284
1285    // Normal case for AES-256
1286    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1287    print!("K =\t");
1288    for i in 0..32
1289        { print!("{:02X}", key[i]); }
1290    println!();
1291    let mut a_aes = AES_256::new_with_key(&key);
1292
1293    let message = "In the beginning God created the heavens and the earth.";
1294    println!("M =\t{}", message);
1295    let message = unsafe { message.to_string().as_mut_vec().clone() };
1296    let mut cipher = Vec::<u8>::new();
1297    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1298    print!("C =\t");
1299    for c in cipher.clone()
1300        { print!("{:02X} ", c); }
1301    println!();
1302    let mut txt = String::new();
1303    for c in cipher.clone()
1304        { write!(txt, "{:02X} ", c); }
1305    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1306    println!();
1307
1308    // Normal case for Rijndael-256-256
1309    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1310    print!("K =\t");
1311    for i in 0..32
1312        { print!("{:02X}", key[i]); }
1313    println!();
1314    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1315
1316    let message = "In the beginning God created the heavens and the earth.";
1317    println!("M =\t{}", message);
1318    let message = unsafe { message.to_string().as_mut_vec().clone() };
1319    let mut cipher = Vec::<u8>::new();
1320    a_rijndael.encrypt_vec_into_vec(&message, &mut cipher);
1321    print!("C =\t");
1322    for c in cipher.clone()
1323        { print!("{:02X} ", c); }
1324    println!();
1325    let mut txt = String::new();
1326    for c in cipher.clone()
1327        { write!(txt, "{:02X} ", c); }
1328    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1329    println!();
1330
1331    // Normal case for Rijndael-512-512 for post-quantum
1332    use cryptocol::number::SharedArrays;
1333    use cryptocol::hash::SHA3_512;
1334    let mut sha3 = SHA3_512::new();
1335    sha3.absorb_str("Post-quantum");
1336    let key: [u8; 64] = sha3.get_hash_value_in_array();
1337    print!("K =\t");
1338    for i in 0..64
1339        { print!("{:02X}", key[i]); }
1340    println!();
1341    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1342    let message = "In the beginning God created the heavens and the earth.";
1343    println!("M =\t{}", message);
1344    let message = unsafe { message.to_string().as_mut_vec().clone() };
1345    let mut cipher = Vec::<u8>::new();
1346    a_rijndael.encrypt_vec_into_vec(&message, &mut cipher);
1347    print!("C =\t");
1348    for c in cipher.clone()
1349        { print!("{:02X} ", c); }
1350    println!();
1351    let mut txt = String::new();
1352    for c in cipher.clone()
1353        { write!(txt, "{:02X} ", c); }
1354    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1355    println!("-------------------------------");
1356}
1357
1358fn aes_encrypt_vec_with_padding_iso_ecb_into_array()
1359{
1360    println!("aes_encrypt_vec_with_padding_iso_ecb_into_array()");
1361    use std::io::Write;
1362    use std::fmt::Write as _;
1363    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1364
1365    // Normal case for AES-128
1366    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1367    println!("K =\t{:#016X}", key);
1368    let mut a_aes = AES_128::new_with_key_u128(key);
1369
1370    let message = "In the beginning God created the heavens and the earth.";
1371    println!("M =\t{}", message);
1372    let message = unsafe { message.to_string().as_mut_vec().clone() };
1373    let mut cipher = [0_u8; 64];
1374    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1375    print!("C =\t");
1376    for c in cipher.clone()
1377        { print!("{:02X} ", c); }
1378    println!();
1379    let mut txt = String::new();
1380    for c in cipher.clone()
1381        { write!(txt, "{:02X} ", c); }
1382    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1383    println!();
1384
1385    // Normal case for AES-192
1386    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1387    print!("K =\t");
1388    for i in 0..24
1389        { print!("{:02X}", key[i]); }
1390    println!();
1391    let mut a_aes = AES_192::new_with_key(&key);
1392
1393    let message = "In the beginning God created the heavens and the earth.";
1394    println!("M =\t{}", message);
1395    let message = unsafe { message.to_string().as_mut_vec().clone() };
1396    let mut cipher = [0_u8; 64];
1397    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1398    print!("C =\t");
1399    for c in cipher.clone()
1400        { print!("{:02X} ", c); }
1401    println!();
1402    let mut txt = String::new();
1403    for c in cipher.clone()
1404        { write!(txt, "{:02X} ", c); }
1405    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1406    println!();
1407
1408    // Normal case for AES-256
1409    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1410    print!("K =\t");
1411    for i in 0..32
1412        { print!("{:02X}", key[i]); }
1413    println!();
1414    let mut a_aes = AES_256::new_with_key(&key);
1415
1416    let message = "In the beginning God created the heavens and the earth.";
1417    println!("M =\t{}", message);
1418    let message = unsafe { message.to_string().as_mut_vec().clone() };
1419    let mut cipher = [0_u8; 64];
1420    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1421    print!("C =\t");
1422    for c in cipher.clone()
1423        { print!("{:02X} ", c); }
1424    println!();
1425    let mut txt = String::new();
1426    for c in cipher.clone()
1427        { write!(txt, "{:02X} ", c); }
1428    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1429    println!();
1430
1431    // Normal case for Rijndael-256-256
1432    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1433    print!("K =\t");
1434    for i in 0..32
1435        { print!("{:02X}", key[i]); }
1436    println!();
1437    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1438
1439    let message = "In the beginning God created the heavens and the earth.";
1440    println!("M =\t{}", message);
1441    let message = unsafe { message.to_string().as_mut_vec().clone() };
1442    let mut cipher = [0_u8; 64];
1443    a_rijndael.encrypt_vec_into_array(&message, &mut cipher);
1444    print!("C =\t");
1445    for c in cipher.clone()
1446        { print!("{:02X} ", c); }
1447    println!();
1448    let mut txt = String::new();
1449    for c in cipher.clone()
1450        { write!(txt, "{:02X} ", c); }
1451    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1452    println!();
1453
1454    // Normal case for Rijndael-512-512 for post-quantum
1455    use cryptocol::number::SharedArrays;
1456    use cryptocol::hash::SHA3_512;
1457    let mut sha3 = SHA3_512::new();
1458    sha3.absorb_str("Post-quantum");
1459    let key: [u8; 64] = sha3.get_hash_value_in_array();
1460    print!("K =\t");
1461    for i in 0..64
1462        { print!("{:02X}", key[i]); }
1463    println!();
1464    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1465    let message = "In the beginning God created the heavens and the earth.";
1466    println!("M =\t{}", message);
1467    let message = unsafe { message.to_string().as_mut_vec().clone() };
1468    let mut cipher = [0_u8; 64];
1469    a_rijndael.encrypt_vec_into_array(&message, &mut cipher);
1470    print!("C =\t");
1471    for c in cipher.clone()
1472        { print!("{:02X} ", c); }
1473    println!();
1474    let mut txt = String::new();
1475    for c in cipher.clone()
1476        { write!(txt, "{:02X} ", c); }
1477    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1478    println!("-------------------------------");
1479}
1480
1481fn aes_encrypt_array_with_padding_iso_ecb()
1482{
1483    println!("aes_encrypt_array_with_padding_iso_ecb()");
1484    use std::io::Write;
1485    use std::fmt::Write as _;
1486    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1487
1488    // Normal case for AES-128
1489    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1490    println!("K =\t{:#016X}", key);
1491    let mut a_aes = AES_128::new_with_key_u128(key);
1492
1493    let mes = "In the beginning God created the heavens and the earth.";
1494    println!("M =\t{}", mes);
1495    let mut message = [0_u8; 55];
1496    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1497    let mut cipher = [0_u8; 64];
1498    a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1499    print!("C =\t");
1500    for c in cipher.clone()
1501        { print!("{:02X} ", c); }
1502    println!();
1503    let mut txt = String::new();
1504    for c in cipher.clone()
1505        { write!(txt, "{:02X} ", c); }
1506    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1507    println!();
1508
1509    // Normal case for AES-192
1510    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1511    print!("K =\t");
1512    for i in 0..24
1513        { print!("{:02X}", key[i]); }
1514    println!();
1515    let mut a_aes = AES_192::new_with_key(&key);
1516
1517    let mes = "In the beginning God created the heavens and the earth.";
1518    println!("M =\t{}", mes);
1519    let mut message = [0_u8; 55];
1520    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1521    let mut cipher = [0_u8; 64];
1522    a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1523    print!("C =\t");
1524    for c in cipher.clone()
1525        { print!("{:02X} ", c); }
1526    println!();
1527    let mut txt = String::new();
1528    for c in cipher.clone()
1529        { write!(txt, "{:02X} ", c); }
1530    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1531    println!();
1532
1533    // Normal case for AES-256
1534    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1535    print!("K =\t");
1536    for i in 0..32
1537        { print!("{:02X}", key[i]); }
1538    println!();
1539    let mut a_aes = AES_256::new_with_key(&key);
1540
1541    let mes = "In the beginning God created the heavens and the earth.";
1542    println!("M =\t{}", mes);
1543    let mut message = [0_u8; 55];
1544    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1545    let mut cipher = [0_u8; 64];
1546    a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1547    print!("C =\t");
1548    for c in cipher.clone()
1549        { print!("{:02X} ", c); }
1550    println!();
1551    let mut txt = String::new();
1552    for c in cipher.clone()
1553        { write!(txt, "{:02X} ", c); }
1554    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1555    println!();
1556
1557    // Normal case for Rijndael-256-256
1558    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1559    print!("K =\t");
1560    for i in 0..32
1561        { print!("{:02X}", key[i]); }
1562    println!();
1563    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1564
1565    let mes = "In the beginning God created the heavens and the earth.";
1566    println!("M =\t{}", mes);
1567    let mut message = [0_u8; 55];
1568    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1569    let mut cipher = [0_u8; 64];
1570    a_rijndael.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1571    print!("C =\t");
1572    for c in cipher.clone()
1573        { print!("{:02X} ", c); }
1574    println!();
1575    let mut txt = String::new();
1576    for c in cipher.clone()
1577        { write!(txt, "{:02X} ", c); }
1578    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1579    println!();
1580
1581    // Normal case for Rijndael-512-512 for post-quantum
1582    use cryptocol::number::SharedArrays;
1583    use cryptocol::hash::SHA3_512;
1584    let mut sha3 = SHA3_512::new();
1585    sha3.absorb_str("Post-quantum");
1586    let key: [u8; 64] = sha3.get_hash_value_in_array();
1587    print!("K =\t");
1588    for i in 0..64
1589        { print!("{:02X}", key[i]); }
1590    println!();
1591    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1592    let mes = "In the beginning God created the heavens and the earth.";
1593    println!("M =\t{}", mes);
1594    let mut message = [0_u8; 55];
1595    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1596    let mut cipher = [0_u8; 64];
1597    a_rijndael.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1598    print!("C =\t");
1599    for c in cipher.clone()
1600        { print!("{:02X} ", c); }
1601    println!();
1602    let mut txt = String::new();
1603    for c in cipher.clone()
1604        { write!(txt, "{:02X} ", c); }
1605    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1606    println!("-------------------------------");
1607}
1608
1609fn aes_encrypt_array_with_padding_iso_ecb_into_vec()
1610{
1611    println!("aes_encrypt_array_with_padding_iso_ecb_into_vec()");
1612    use std::io::Write;
1613    use std::fmt::Write as _;
1614    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1615
1616    // Normal case for AES-128
1617    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1618    println!("K =\t{:#016X}", key);
1619    let mut a_aes = AES_128::new_with_key_u128(key);
1620
1621    let mes = "In the beginning God created the heavens and the earth.";
1622    println!("M =\t{}", mes);
1623    let mut message = [0_u8; 55];
1624    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1625    let mut cipher = Vec::<u8>::new();
1626    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1627    print!("C =\t");
1628    for c in cipher.clone()
1629        { print!("{:02X} ", c); }
1630    println!();
1631    let mut txt = String::new();
1632    for c in cipher.clone()
1633        { write!(txt, "{:02X} ", c); }
1634    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1635    println!();
1636
1637    // Normal case for AES-192
1638    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1639    print!("K =\t");
1640    for i in 0..24
1641        { print!("{:02X}", key[i]); }
1642    println!();
1643    let mut a_aes = AES_192::new_with_key(&key);
1644
1645    let mes = "In the beginning God created the heavens and the earth.";
1646    println!("M =\t{}", mes);
1647    let mut message = [0_u8; 55];
1648    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1649    let mut cipher = Vec::<u8>::new();
1650    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1651    print!("C =\t");
1652    for c in cipher.clone()
1653        { print!("{:02X} ", c); }
1654    println!();
1655    let mut txt = String::new();
1656    for c in cipher.clone()
1657        { write!(txt, "{:02X} ", c); }
1658    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1659    println!();
1660
1661    // Normal case for AES-256
1662    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1663    print!("K =\t");
1664    for i in 0..32
1665        { print!("{:02X}", key[i]); }
1666    println!();
1667    let mut a_aes = AES_256::new_with_key(&key);
1668
1669    let mes = "In the beginning God created the heavens and the earth.";
1670    println!("M =\t{}", mes);
1671    let mut message = [0_u8; 55];
1672    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1673    let mut cipher = Vec::<u8>::new();
1674    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1675    print!("C =\t");
1676    for c in cipher.clone()
1677        { print!("{:02X} ", c); }
1678    println!();
1679    let mut txt = String::new();
1680    for c in cipher.clone()
1681        { write!(txt, "{:02X} ", c); }
1682    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1683    println!();
1684
1685    // Normal case for Rijndael-256-256
1686    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1687    print!("K =\t");
1688    for i in 0..32
1689        { print!("{:02X}", key[i]); }
1690    println!();
1691    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1692
1693    let mes = "In the beginning God created the heavens and the earth.";
1694    println!("M =\t{}", mes);
1695    let mut message = [0_u8; 55];
1696    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1697    let mut cipher = Vec::<u8>::new();
1698    a_rijndael.encrypt_array_into_vec(&message, &mut cipher);
1699    print!("C =\t");
1700    for c in cipher.clone()
1701        { print!("{:02X} ", c); }
1702    println!();
1703    let mut txt = String::new();
1704    for c in cipher.clone()
1705        { write!(txt, "{:02X} ", c); }
1706    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1707    println!();
1708
1709    // Normal case for Rijndael-512-512 for post-quantum
1710    use cryptocol::number::SharedArrays;
1711    use cryptocol::hash::SHA3_512;
1712    let mut sha3 = SHA3_512::new();
1713    sha3.absorb_str("Post-quantum");
1714    let key: [u8; 64] = sha3.get_hash_value_in_array();
1715    print!("K =\t");
1716    for i in 0..64
1717        { print!("{:02X}", key[i]); }
1718    println!();
1719    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1720    let mes = "In the beginning God created the heavens and the earth.";
1721    println!("M =\t{}", mes);
1722    let mut message = [0_u8; 55];
1723    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1724    let mut cipher = Vec::<u8>::new();
1725    a_rijndael.encrypt_array_into_vec(&message, &mut cipher);
1726    print!("C =\t");
1727    for c in cipher.clone()
1728        { print!("{:02X} ", c); }
1729    println!();
1730    let mut txt = String::new();
1731    for c in cipher.clone()
1732        { write!(txt, "{:02X} ", c); }
1733    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1734    println!("-------------------------------");
1735}
1736
1737fn aes_encrypt_array_with_padding_iso_ecb_into_array()
1738{
1739    println!("aes_encrypt_array_with_padding_iso_ecb_into_array()");
1740    use std::io::Write;
1741    use std::fmt::Write as _;
1742    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1743
1744    // Normal case for AES-128
1745    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1746    println!("K =\t{:#016X}", key);
1747    let mut a_aes = AES_128::new_with_key_u128(key);
1748
1749    let mes = "In the beginning God created the heavens and the earth.";
1750    println!("M =\t{}", mes);
1751    let mut message = [0_u8; 55];
1752    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1753    let mut cipher = [0_u8; 64];
1754    a_aes.encrypt_array_into_array(&message, &mut cipher);
1755    print!("C =\t");
1756    for c in cipher.clone()
1757        { print!("{:02X} ", c); }
1758    println!();
1759    let mut txt = String::new();
1760    for c in cipher.clone()
1761        { write!(txt, "{:02X} ", c); }
1762    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1763    println!();
1764
1765    // Normal case for AES-192
1766    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1767    print!("K =\t");
1768    for i in 0..24
1769        { print!("{:02X}", key[i]); }
1770    println!();
1771    let mut a_aes = AES_192::new_with_key(&key);
1772
1773    let mes = "In the beginning God created the heavens and the earth.";
1774    println!("M =\t{}", mes);
1775    let mut message = [0_u8; 55];
1776    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1777    let mut cipher = [0_u8; 64];
1778    a_aes.encrypt_array_into_array(&message, &mut cipher);
1779    print!("C =\t");
1780    for c in cipher.clone()
1781        { print!("{:02X} ", c); }
1782    println!();
1783    let mut txt = String::new();
1784    for c in cipher.clone()
1785        { write!(txt, "{:02X} ", c); }
1786    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1787    println!();
1788
1789    // Normal case for AES-256
1790    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1791    print!("K =\t");
1792    for i in 0..32
1793        { print!("{:02X}", key[i]); }
1794    println!();
1795    let mut a_aes = AES_256::new_with_key(&key);
1796
1797    let mes = "In the beginning God created the heavens and the earth.";
1798    println!("M =\t{}", mes);
1799    let mut message = [0_u8; 55];
1800    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1801    let mut cipher = [0_u8; 64];
1802    a_aes.encrypt_array_into_array(&message, &mut cipher);
1803    print!("C =\t");
1804    for c in cipher.clone()
1805        { print!("{:02X} ", c); }
1806    println!();
1807    let mut txt = String::new();
1808    for c in cipher.clone()
1809        { write!(txt, "{:02X} ", c); }
1810    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1811    println!();
1812
1813    // Normal case for Rijndael-256-256
1814    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1815    print!("K =\t");
1816    for i in 0..32
1817        { print!("{:02X}", key[i]); }
1818    println!();
1819    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1820
1821    let mes = "In the beginning God created the heavens and the earth.";
1822    println!("M =\t{}", mes);
1823    let mut message = [0_u8; 55];
1824    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1825    let mut cipher = [0_u8; 64];
1826    a_rijndael.encrypt_array_into_array(&message, &mut cipher);
1827    print!("C =\t");
1828    for c in cipher.clone()
1829        { print!("{:02X} ", c); }
1830    println!();
1831    let mut txt = String::new();
1832    for c in cipher.clone()
1833        { write!(txt, "{:02X} ", c); }
1834    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1835    println!();
1836
1837    // Normal case for Rijndael-512-512 for post-quantum
1838    use cryptocol::number::SharedArrays;
1839    use cryptocol::hash::SHA3_512;
1840    let mut sha3 = SHA3_512::new();
1841    sha3.absorb_str("Post-quantum");
1842    let key: [u8; 64] = sha3.get_hash_value_in_array();
1843    print!("K =\t");
1844    for i in 0..64
1845        { print!("{:02X}", key[i]); }
1846    println!();
1847    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1848    let mes = "In the beginning God created the heavens and the earth.";
1849    println!("M =\t{}", mes);
1850    let mut message = [0_u8; 55];
1851    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1852    let mut cipher = [0_u8; 64];
1853    a_rijndael.encrypt_array_into_array(&message, &mut cipher);
1854    print!("C =\t");
1855    for c in cipher.clone()
1856        { print!("{:02X} ", c); }
1857    println!();
1858    let mut txt = String::new();
1859    for c in cipher.clone()
1860        { write!(txt, "{:02X} ", c); }
1861    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1862    println!("-------------------------------");
1863}
1864
1865fn aes_decrypt_with_padding_iso_ecb()
1866{
1867    println!("aes_decrypt_with_padding_iso_ecb");
1868    use std::io::Write;
1869    use std::fmt::Write as _;
1870    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1871
1872    // Normal case for AES-128
1873    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1874    println!("K =\t{:#016X}", key);
1875    let mut a_aes = AES_128::new_with_key_u128(key);
1876
1877    let message = "In the beginning God created the heavens and the earth.";
1878    println!("M =\t{}", message);
1879    let mut cipher = [0_u8; 64];
1880    a_aes.encrypt_str_into_array(&message, &mut cipher);
1881    print!("C =\t");
1882    for c in cipher.clone()
1883        { print!("{:02X} ", c); }
1884    println!();
1885    let mut txt = String::new();
1886    for c in cipher.clone()
1887        { write!(txt, "{:02X} ", c); }
1888    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1889
1890    let mut recovered = vec![0; 55];
1891    a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
1892    print!("Ba =\t");
1893    for b in recovered.clone()
1894        { print!("{:02X} ", b); }
1895    println!();
1896    let mut txt = String::new();
1897    for c in recovered.clone()
1898        { write!(txt, "{:02X} ", c); }
1899    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
1900
1901    let mut converted = String::new();
1902    unsafe { converted.as_mut_vec() }.append(&mut recovered);
1903    
1904    println!("Bb =\t{}", converted);
1905    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
1906    assert_eq!(converted, message);
1907    println!();
1908
1909    // Normal case for AES-192
1910    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1911    print!("K =\t");
1912    for i in 0..24
1913        { print!("{:02X}", key[i]); }
1914    println!();
1915    let mut a_aes = AES_192::new_with_key(&key);
1916
1917    let message = "In the beginning God created the heavens and the earth.";
1918    println!("M =\t{}", message);
1919    let mut cipher = [0_u8; 64];
1920    a_aes.encrypt_str_into_array(&message, &mut cipher);
1921    print!("C =\t");
1922    for c in cipher.clone()
1923        { print!("{:02X} ", c); }
1924    println!();
1925    let mut txt = String::new();
1926    for c in cipher.clone()
1927        { write!(txt, "{:02X} ", c); }
1928    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1929
1930    let mut recovered = vec![0; 55];
1931    a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
1932    print!("Ba =\t");
1933    for b in recovered.clone()
1934        { print!("{:02X} ", b); }
1935    println!();
1936    let mut txt = String::new();
1937    for c in recovered.clone()
1938        { write!(txt, "{:02X} ", c); }
1939    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
1940
1941    let mut converted = String::new();
1942    unsafe { converted.as_mut_vec() }.append(&mut recovered);
1943    
1944    println!("Bb =\t{}", converted);
1945    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
1946    assert_eq!(converted, message);
1947    println!();
1948
1949    // Normal case for AES-256
1950    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1951    print!("K =\t");
1952    for i in 0..32
1953        { print!("{:02X}", key[i]); }
1954    println!();
1955    let mut a_aes = AES_256::new_with_key(&key);
1956
1957    let message = "In the beginning God created the heavens and the earth.";
1958    println!("M =\t{}", message);
1959    let mut cipher = [0_u8; 64];
1960    a_aes.encrypt_str_into_array(&message, &mut cipher);
1961    print!("C =\t");
1962    for c in cipher.clone()
1963        { print!("{:02X} ", c); }
1964    println!();
1965    let mut txt = String::new();
1966    for c in cipher.clone()
1967        { write!(txt, "{:02X} ", c); }
1968    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1969
1970    let mut recovered = vec![0; 55];
1971    a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
1972    print!("Ba =\t");
1973    for b in recovered.clone()
1974        { print!("{:02X} ", b); }
1975    println!();
1976    let mut txt = String::new();
1977    for c in recovered.clone()
1978        { write!(txt, "{:02X} ", c); }
1979    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
1980
1981    let mut converted = String::new();
1982    unsafe { converted.as_mut_vec() }.append(&mut recovered);
1983    
1984    println!("Bb =\t{}", converted);
1985    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
1986    assert_eq!(converted, message);
1987    println!();
1988
1989    // Normal case for Rijndael-256-256
1990    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1991    print!("K =\t");
1992    for i in 0..32
1993        { print!("{:02X}", key[i]); }
1994    println!();
1995    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1996
1997    let message = "In the beginning God created the heavens and the earth.";
1998    println!("M =\t{}", message);
1999    let mut cipher = [0_u8; 64];
2000    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2001    print!("C =\t");
2002    for c in cipher.clone()
2003        { print!("{:02X} ", c); }
2004    println!();
2005    let mut txt = String::new();
2006    for c in cipher.clone()
2007        { write!(txt, "{:02X} ", c); }
2008    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2009
2010    let mut recovered = vec![0; 55];
2011    a_rijndael.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2012    print!("Ba =\t");
2013    for b in recovered.clone()
2014        { print!("{:02X} ", b); }
2015    println!();
2016    let mut txt = String::new();
2017    for c in recovered.clone()
2018        { write!(txt, "{:02X} ", c); }
2019    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2020
2021    let mut converted = String::new();
2022    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2023    
2024    println!("Bb =\t{}", converted);
2025    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2026    assert_eq!(converted, message);
2027    println!();
2028
2029    // Normal case for Rijndael-512-512 for post-quantum
2030    use cryptocol::number::SharedArrays;
2031    use cryptocol::hash::SHA3_512;
2032    let mut sha3 = SHA3_512::new();
2033    sha3.absorb_str("Post-quantum");
2034    let key: [u8; 64] = sha3.get_hash_value_in_array();
2035    print!("K =\t");
2036    for i in 0..64
2037        { print!("{:02X}", key[i]); }
2038    println!();
2039    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2040    let message = "In the beginning God created the heavens and the earth.";
2041    println!("M =\t{}", message);
2042    let mut cipher = [0_u8; 64];
2043    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2044    print!("C =\t");
2045    for c in cipher.clone()
2046        { print!("{:02X} ", c); }
2047    println!();
2048    let mut txt = String::new();
2049    for c in cipher.clone()
2050        { write!(txt, "{:02X} ", c); }
2051    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2052    
2053    let mut recovered = vec![0; 55];
2054    a_rijndael.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2055    print!("Ba =\t");
2056    for b in recovered.clone()
2057        { print!("{:02X} ", b); }
2058    println!();
2059    let mut txt = String::new();
2060    for c in recovered.clone()
2061        { write!(txt, "{:02X} ", c); }
2062    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2063
2064    let mut converted = String::new();
2065    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2066    
2067    println!("Bb =\t{}", converted);
2068    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2069    assert_eq!(converted, message);
2070    println!("-------------------------------");
2071}
2072
2073
2074fn aes_decrypt_with_padding_iso_ecb_into_vec()
2075{
2076    println!("aes_decrypt_with_padding_iso_ecb_into_vec()");
2077    use std::io::Write;
2078    use std::fmt::Write as _;
2079    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2080
2081    // Normal case for AES-128
2082    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2083    println!("K =\t{:#016X}", key);
2084    let mut a_aes = AES_128::new_with_key_u128(key);
2085
2086    let message = "In the beginning God created the heavens and the earth.";
2087    println!("M =\t{}", message);
2088    let mut cipher = [0_u8; 64];
2089    a_aes.encrypt_str_into_array(&message, &mut cipher);
2090    print!("C =\t");
2091    for c in cipher.clone()
2092        { print!("{:02X} ", c); }
2093    println!();
2094    let mut txt = String::new();
2095    for c in cipher.clone()
2096        { write!(txt, "{:02X} ", c); }
2097    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2098    println!();
2099
2100    let mut recovered = Vec::<u8>::new();
2101    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2102    print!("Ba =\t");
2103    for b in recovered.clone()
2104        { print!("{:02X} ", b); }
2105    println!();
2106    let mut txt = String::new();
2107    for c in recovered.clone()
2108        { write!(txt, "{:02X} ", c); }
2109    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2110
2111    let mut converted = String::new();
2112    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2113    
2114    println!("Bb =\t{}", converted);
2115    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2116    assert_eq!(converted, message);
2117    println!();
2118
2119    // Normal case for AES-192
2120    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2121    print!("K =\t");
2122    for i in 0..24
2123        { print!("{:02X}", key[i]); }
2124    println!();
2125    let mut a_aes = AES_192::new_with_key(&key);
2126
2127    let message = "In the beginning God created the heavens and the earth.";
2128    println!("M =\t{}", message);
2129    let mut cipher = [0_u8; 64];
2130    a_aes.encrypt_str_into_array(&message, &mut cipher);
2131    print!("C =\t");
2132    for c in cipher.clone()
2133        { print!("{:02X} ", c); }
2134    println!();
2135    let mut txt = String::new();
2136    for c in cipher.clone()
2137        { write!(txt, "{:02X} ", c); }
2138    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2139    println!();
2140
2141    let mut recovered = Vec::<u8>::new();
2142    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2143    print!("Ba =\t");
2144    for b in recovered.clone()
2145        { print!("{:02X} ", b); }
2146    println!();
2147    let mut txt = String::new();
2148    for c in recovered.clone()
2149        { write!(txt, "{:02X} ", c); }
2150    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2151
2152    let mut converted = String::new();
2153    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2154    
2155    println!("Bb =\t{}", converted);
2156    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2157    assert_eq!(converted, message);
2158    println!();
2159
2160    // Normal case for AES-256
2161    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2162    print!("K =\t");
2163    for i in 0..32
2164        { print!("{:02X}", key[i]); }
2165    println!();
2166    let mut a_aes = AES_256::new_with_key(&key);
2167
2168    let message = "In the beginning God created the heavens and the earth.";
2169    println!("M =\t{}", message);
2170    let mut cipher = [0_u8; 64];
2171    a_aes.encrypt_str_into_array(&message, &mut cipher);
2172    print!("C =\t");
2173    for c in cipher.clone()
2174        { print!("{:02X} ", c); }
2175    println!();
2176    let mut txt = String::new();
2177    for c in cipher.clone()
2178        { write!(txt, "{:02X} ", c); }
2179    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2180    println!();
2181
2182    let mut recovered = Vec::<u8>::new();
2183    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2184    print!("Ba =\t");
2185    for b in recovered.clone()
2186        { print!("{:02X} ", b); }
2187    println!();
2188    let mut txt = String::new();
2189    for c in recovered.clone()
2190        { write!(txt, "{:02X} ", c); }
2191    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2192
2193    let mut converted = String::new();
2194    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2195    
2196    println!("Bb =\t{}", converted);
2197    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2198    assert_eq!(converted, message);
2199    println!();
2200
2201    // Normal case for Rijndael-256-256
2202    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2203    print!("K =\t");
2204    for i in 0..32
2205        { print!("{:02X}", key[i]); }
2206    println!();
2207    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2208
2209    let message = "In the beginning God created the heavens and the earth.";
2210    println!("M =\t{}", message);
2211    let mut cipher = [0_u8; 64];
2212    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2213    print!("C =\t");
2214    for c in cipher.clone()
2215        { print!("{:02X} ", c); }
2216    println!();
2217    let mut txt = String::new();
2218    for c in cipher.clone()
2219        { write!(txt, "{:02X} ", c); }
2220    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2221    println!();
2222
2223    let mut recovered = Vec::<u8>::new();
2224    a_rijndael.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2225    print!("Ba =\t");
2226    for b in recovered.clone()
2227        { print!("{:02X} ", b); }
2228    println!();
2229    let mut txt = String::new();
2230    for c in recovered.clone()
2231        { write!(txt, "{:02X} ", c); }
2232    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2233
2234    let mut converted = String::new();
2235    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2236    
2237    println!("Bb =\t{}", converted);
2238    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2239    assert_eq!(converted, message);
2240    println!();
2241
2242    // Normal case for Rijndael-512-512 for post-quantum
2243    use cryptocol::number::SharedArrays;
2244    use cryptocol::hash::SHA3_512;
2245    let mut sha3 = SHA3_512::new();
2246    sha3.absorb_str("Post-quantum");
2247    let key: [u8; 64] = sha3.get_hash_value_in_array();
2248    print!("K =\t");
2249    for i in 0..64
2250        { print!("{:02X}", key[i]); }
2251    println!();
2252    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2253    let message = "In the beginning God created the heavens and the earth.";
2254    println!("M =\t{}", message);
2255    let mut cipher = [0_u8; 64];
2256    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2257    print!("C =\t");
2258    for c in cipher.clone()
2259        { print!("{:02X} ", c); }
2260    println!();
2261    let mut txt = String::new();
2262    for c in cipher.clone()
2263        { write!(txt, "{:02X} ", c); }
2264    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2265    
2266    let mut recovered = Vec::<u8>::new();
2267    a_rijndael.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2268    print!("Ba =\t");
2269    for b in recovered.clone()
2270        { print!("{:02X} ", b); }
2271    println!();
2272    let mut txt = String::new();
2273    for c in recovered.clone()
2274        { write!(txt, "{:02X} ", c); }
2275    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2276
2277    let mut converted = String::new();
2278    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2279    
2280    println!("Bb =\t{}", converted);
2281    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2282    assert_eq!(converted, message);
2283    println!("-------------------------------");
2284}
2285
2286fn aes_decrypt_with_padding_iso_ecb_into_array()
2287{
2288    println!("aes_decrypt_with_padding_iso_ecb_into_array()");
2289    use std::io::Write;
2290    use std::fmt::Write as _;
2291    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2292
2293    // Normal case for AES-128
2294    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2295    println!("K =\t{:#016X}", key);
2296    let mut a_aes = AES_128::new_with_key_u128(key);
2297
2298    let message = "In the beginning God created the heavens and the earth.";
2299    println!("M =\t{}", message);
2300    let mut cipher = [0_u8; 64];
2301    a_aes.encrypt_str_into_array(&message, &mut cipher);
2302    print!("C =\t");
2303    for c in cipher.clone()
2304        { print!("{:02X} ", c); }
2305    println!();
2306    let mut txt = String::new();
2307    for c in cipher.clone()
2308        { write!(txt, "{:02X} ", c); }
2309    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2310
2311    let mut recovered = [0; 64];
2312    let len = a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2313    print!("Ba =\t");
2314    for b in recovered.clone()
2315        { print!("{:02X} ", b); }
2316    println!();
2317    let mut txt = String::new();
2318    for c in recovered.clone()
2319        { write!(txt, "{:02X} ", c); }
2320    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2321
2322    let mut converted = String::new();
2323    unsafe { converted.as_mut_vec() }.write(&recovered);
2324    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2325
2326    println!("Bb =\t{}", converted);
2327    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2328    assert_eq!(converted, message);
2329    println!();
2330
2331    // Normal case for AES-192
2332    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2333    print!("K =\t");
2334    for i in 0..24
2335        { print!("{:02X}", key[i]); }
2336    println!();
2337    let mut a_aes = AES_192::new_with_key(&key);
2338
2339    let message = "In the beginning God created the heavens and the earth.";
2340    println!("M =\t{}", message);
2341    let mut cipher = [0_u8; 64];
2342    a_aes.encrypt_str_into_array(&message, &mut cipher);
2343    print!("C =\t");
2344    for c in cipher.clone()
2345        { print!("{:02X} ", c); }
2346    println!();
2347    let mut txt = String::new();
2348    for c in cipher.clone()
2349        { write!(txt, "{:02X} ", c); }
2350    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2351
2352    let mut recovered = [0; 64];
2353    a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2354    print!("Ba =\t");
2355    for b in recovered.clone()
2356        { print!("{:02X} ", b); }
2357    println!();
2358    let mut txt = String::new();
2359
2360    for c in recovered.clone()
2361        { write!(txt, "{:02X} ", c); }
2362    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2363
2364    let mut converted = String::new();
2365    unsafe { converted.as_mut_vec() }.write(&recovered);
2366    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2367
2368    println!("Bb =\t{}", converted);
2369    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2370    assert_eq!(converted, message);
2371    println!();
2372
2373    // Normal case for AES-256
2374    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2375    print!("K =\t");
2376    for i in 0..32
2377        { print!("{:02X}", key[i]); }
2378    println!();
2379    let mut a_aes = AES_256::new_with_key(&key);
2380
2381    let message = "In the beginning God created the heavens and the earth.";
2382    println!("M =\t{}", message);
2383    let mut cipher = [0_u8; 64];
2384    a_aes.encrypt_str_into_array(&message, &mut cipher);
2385    print!("C =\t");
2386    for c in cipher.clone()
2387        { print!("{:02X} ", c); }
2388    println!();
2389    let mut txt = String::new();
2390    for c in cipher.clone()
2391        { write!(txt, "{:02X} ", c); }
2392    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2393
2394    let mut recovered = [0; 64];
2395    a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2396    print!("Ba =\t");
2397    for b in recovered.clone()
2398        { print!("{:02X} ", b); }
2399    println!();
2400    let mut txt = String::new();
2401    for c in recovered.clone()
2402        { write!(txt, "{:02X} ", c); }
2403    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2404
2405    let mut converted = String::new();
2406    unsafe { converted.as_mut_vec() }.write(&recovered);
2407    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2408     
2409    println!("Bb =\t{}", converted);
2410    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2411    assert_eq!(converted, message);
2412    println!();
2413
2414    // Normal case for Rijndael-256-256
2415    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2416    print!("K =\t");
2417    for i in 0..32
2418        { print!("{:02X}", key[i]); }
2419    println!();
2420    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2421
2422    let message = "In the beginning God created the heavens and the earth.";
2423    println!("M =\t{}", message);
2424    let mut cipher = [0_u8; 64];
2425    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2426    print!("C =\t");
2427    for c in cipher.clone()
2428        { print!("{:02X} ", c); }
2429    println!();
2430    let mut txt = String::new();
2431    for c in cipher.clone()
2432        { write!(txt, "{:02X} ", c); }
2433    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2434
2435    let mut recovered = [0; 64];
2436    a_rijndael.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2437    for b in recovered.clone()
2438        { print!("{:02X} ", b); }
2439    println!();
2440    let mut txt = String::new();
2441    for c in recovered.clone()
2442        { write!(txt, "{:02X} ", c); }
2443    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2444
2445    let mut converted = String::new();
2446    unsafe { converted.as_mut_vec() }.write(&recovered);
2447    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2448
2449    println!("Bb =\t{}", converted);
2450    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2451    assert_eq!(converted, message);
2452    println!();
2453
2454    // Normal case for Rijndael-512-512 for post-quantum
2455    use cryptocol::number::SharedArrays;
2456    use cryptocol::hash::SHA3_512;
2457    let mut sha3 = SHA3_512::new();
2458    sha3.absorb_str("Post-quantum");
2459    let key: [u8; 64] = sha3.get_hash_value_in_array();
2460    print!("K =\t");
2461    for i in 0..64
2462        { print!("{:02X}", key[i]); }
2463    println!();
2464    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2465
2466    let message = "In the beginning God created the heavens and the earth.";
2467    println!("M =\t{}", message);
2468    let mut cipher = [0_u8; 64];
2469    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2470    print!("C =\t");
2471    for c in cipher.clone()
2472        { print!("{:02X} ", c); }
2473    println!();
2474    let mut txt = String::new();
2475    for c in cipher.clone()
2476        { write!(txt, "{:02X} ", c); }
2477    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2478    
2479    let mut recovered = [0; 64];
2480    a_rijndael.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2481    print!("Ba =\t");
2482    for b in recovered.clone()
2483        { print!("{:02X} ", b); }
2484    println!();
2485    let mut txt = String::new();
2486    for c in recovered.clone()
2487        { write!(txt, "{:02X} ", c); }
2488    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2489
2490    let mut converted = String::new();
2491    unsafe { converted.as_mut_vec() }.write(&recovered);
2492    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2493
2494    println!("Bb =\t{}", converted);
2495    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2496    assert_eq!(converted, message);
2497    println!("-------------------------------");
2498}
2499
2500fn aes_decrypt_with_padding_iso_ecb_into_string()
2501{
2502    println!("aes_decrypt_with_padding_iso_ecb_into_string()");
2503    use std::io::Write;
2504    use std::fmt::Write as _;
2505    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2506
2507    // Normal case for AES-128
2508    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2509    println!("K =\t{:#016X}", key);
2510    let mut a_aes = AES_128::new_with_key_u128(key);
2511
2512    let message = "In the beginning God created the heavens and the earth.";
2513    println!("M =\t{}", message);
2514    let mut cipher = [0_u8; 64];
2515    a_aes.encrypt_str_into_array(&message, &mut cipher);
2516    print!("C =\t");
2517    for c in cipher.clone()
2518        { print!("{:02X} ", c); }
2519    println!();
2520    let mut txt = String::new();
2521    for c in cipher.clone()
2522        { write!(txt, "{:02X} ", c); }
2523    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2524
2525    let mut converted= String::new();
2526    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2527    println!("B =\t{}", converted);
2528    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2529    assert_eq!(converted, message);
2530    println!();
2531
2532    // Normal case for AES-192
2533    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2534    print!("K =\t");
2535    for i in 0..24
2536        { print!("{:02X}", key[i]); }
2537    println!();
2538    let mut a_aes = AES_192::new_with_key(&key);
2539
2540    let message = "In the beginning God created the heavens and the earth.";
2541    println!("M =\t{}", message);
2542    let mut cipher = [0_u8; 64];
2543    a_aes.encrypt_str_into_array(&message, &mut cipher);
2544    print!("C =\t");
2545    for c in cipher.clone()
2546        { print!("{:02X} ", c); }
2547    println!();
2548    let mut txt = String::new();
2549    for c in cipher.clone()
2550        { write!(txt, "{:02X} ", c); }
2551    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2552
2553    let mut converted= String::new();
2554    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2555    println!("B =\t{}", converted);
2556    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2557    assert_eq!(converted, message);
2558    println!();
2559
2560    // Normal case for AES-256
2561    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2562    print!("K =\t");
2563    for i in 0..32
2564        { print!("{:02X}", key[i]); }
2565    println!();
2566    let mut a_aes = AES_256::new_with_key(&key);
2567
2568    let message = "In the beginning God created the heavens and the earth.";
2569    println!("M =\t{}", message);
2570    let mut cipher = [0_u8; 64];
2571    a_aes.encrypt_str_into_array(&message, &mut cipher);
2572    print!("C =\t");
2573    for c in cipher.clone()
2574        { print!("{:02X} ", c); }
2575    println!();
2576    let mut txt = String::new();
2577    for c in cipher.clone()
2578        { write!(txt, "{:02X} ", c); }
2579    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2580
2581    let mut converted= String::new();
2582    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2583    println!("B =\t{}", converted);
2584    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2585    assert_eq!(converted, message);
2586    println!();
2587
2588    // Normal case for Rijndael-256-256
2589    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2590    print!("K =\t");
2591    for i in 0..32
2592        { print!("{:02X}", key[i]); }
2593    println!();
2594    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2595
2596    let message = "In the beginning God created the heavens and the earth.";
2597    println!("M =\t{}", message);
2598    let mut cipher = [0_u8; 64];
2599    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2600    print!("C =\t");
2601    for c in cipher.clone()
2602        { print!("{:02X} ", c); }
2603    println!();
2604    let mut txt = String::new();
2605    for c in cipher.clone()
2606        { write!(txt, "{:02X} ", c); }
2607    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2608
2609    let mut converted= String::new();
2610    a_rijndael.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2611    println!("B =\t{}", converted);
2612    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2613    assert_eq!(converted, message);
2614    println!();
2615
2616    // Normal case for Rijndael-512-512 for post-quantum
2617    use cryptocol::number::SharedArrays;
2618    use cryptocol::hash::SHA3_512;
2619    let mut sha3 = SHA3_512::new();
2620    sha3.absorb_str("Post-quantum");
2621    let key: [u8; 64] = sha3.get_hash_value_in_array();
2622    print!("K =\t");
2623    for i in 0..64
2624        { print!("{:02X}", key[i]); }
2625    println!();
2626    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2627    let message = "In the beginning God created the heavens and the earth.";
2628    println!("M =\t{}", message);
2629    let mut cipher = [0_u8; 64];
2630    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2631    print!("C =\t");
2632    for c in cipher.clone()
2633        { print!("{:02X} ", c); }
2634    println!();
2635    let mut txt = String::new();
2636    for c in cipher.clone()
2637        { write!(txt, "{:02X} ", c); }
2638    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2639    
2640    let mut converted= String::new();
2641    a_rijndael.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2642    println!("B =\t{}", converted);
2643    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2644    assert_eq!(converted, message);
2645    println!("-------------------------------");
2646}
2647
2648fn aes_decrypt_vec_with_padding_iso_ecb()
2649{
2650    println!("aes_decrypt_vec_with_padding_iso_ecb()");
2651    use std::io::Write;
2652    use std::fmt::Write as _;
2653    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2654
2655    // Normal case for AES-128
2656    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2657    println!("K =\t{:#016X}", key);
2658    let mut a_aes = AES_128::new_with_key_u128(key);
2659
2660    let message = "In the beginning God created the heavens and the earth.";
2661    println!("M =\t{}", message);
2662    let mut cipher = Vec::<u8>::new();
2663    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2664    print!("C =\t");
2665    for c in cipher.clone()
2666        { print!("{:02X} ", c); }
2667    println!();
2668    let mut txt = String::new();
2669    for c in cipher.clone()
2670        { write!(txt, "{:02X} ", c); }
2671    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2672
2673    let mut recovered = vec![0; 55];
2674    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2675    print!("Ba =\t");
2676    for b in recovered.clone()
2677        { print!("{:02X} ", b); }
2678    println!();
2679    let mut txt = String::new();
2680    for c in recovered.clone()
2681        { write!(txt, "{:02X} ", c); }
2682    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2683
2684    let mut converted = String::new();
2685    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2686    
2687    println!("Bb =\t{}", converted);
2688    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2689    assert_eq!(converted, message);
2690    println!();
2691
2692    // Normal case for AES-192
2693    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2694    print!("K =\t");
2695    for i in 0..24
2696        { print!("{:02X}", key[i]); }
2697    println!();
2698    let mut a_aes = AES_192::new_with_key(&key);
2699
2700    let message = "In the beginning God created the heavens and the earth.";
2701    println!("M =\t{}", message);
2702    let mut cipher = Vec::<u8>::new();
2703    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2704    print!("C =\t");
2705    for c in cipher.clone()
2706        { print!("{:02X} ", c); }
2707    println!();
2708    let mut txt = String::new();
2709    for c in cipher.clone()
2710        { write!(txt, "{:02X} ", c); }
2711    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2712
2713    let mut recovered = vec![0; 55];
2714    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2715    print!("Ba =\t");
2716    for b in recovered.clone()
2717        { print!("{:02X} ", b); }
2718    println!();
2719    let mut txt = String::new();
2720    for c in recovered.clone()
2721        { write!(txt, "{:02X} ", c); }
2722    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2723
2724    let mut converted = String::new();
2725    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2726    
2727    println!("Bb =\t{}", converted);
2728    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2729    assert_eq!(converted, message);
2730    println!();
2731
2732    // Normal case for AES-256
2733    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2734    print!("K =\t");
2735    for i in 0..32
2736        { print!("{:02X}", key[i]); }
2737    println!();
2738    let mut a_aes = AES_256::new_with_key(&key);
2739
2740    let message = "In the beginning God created the heavens and the earth.";
2741    println!("M =\t{}", message);
2742    let mut cipher = Vec::<u8>::new();
2743    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2744    print!("C =\t");
2745    for c in cipher.clone()
2746        { print!("{:02X} ", c); }
2747    println!();
2748    let mut txt = String::new();
2749    for c in cipher.clone()
2750        { write!(txt, "{:02X} ", c); }
2751    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2752
2753    let mut recovered = vec![0; 55];
2754    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2755    print!("Ba =\t");
2756    for b in recovered.clone()
2757        { print!("{:02X} ", b); }
2758    println!();
2759    let mut txt = String::new();
2760    for c in recovered.clone()
2761        { write!(txt, "{:02X} ", c); }
2762    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2763
2764    let mut converted = String::new();
2765    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2766    
2767    println!("Bb =\t{}", converted);
2768    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2769    assert_eq!(converted, message);
2770    println!();
2771
2772    // Normal case for Rijndael-256-256
2773    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2774    print!("K =\t");
2775    for i in 0..32
2776        { print!("{:02X}", key[i]); }
2777    println!();
2778    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2779
2780    let message = "In the beginning God created the heavens and the earth.";
2781    println!("M =\t{}", message);
2782    let mut cipher = Vec::<u8>::new();
2783    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2784    print!("C =\t");
2785    for c in cipher.clone()
2786        { print!("{:02X} ", c); }
2787    println!();
2788    let mut txt = String::new();
2789    for c in cipher.clone()
2790        { write!(txt, "{:02X} ", c); }
2791    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2792
2793    let mut recovered = vec![0; 55];
2794    a_rijndael.decrypt_vec(&cipher, recovered.as_mut_ptr());
2795    print!("Ba =\t");
2796    for b in recovered.clone()
2797        { print!("{:02X} ", b); }
2798    println!();
2799    let mut txt = String::new();
2800    for c in recovered.clone()
2801        { write!(txt, "{:02X} ", c); }
2802    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2803
2804    let mut converted = String::new();
2805    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2806    
2807    println!("Bb =\t{}", converted);
2808    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2809    assert_eq!(converted, message);
2810    println!();
2811
2812    // Normal case for Rijndael-512-512 for post-quantum
2813    use cryptocol::number::SharedArrays;
2814    use cryptocol::hash::SHA3_512;
2815    let mut sha3 = SHA3_512::new();
2816    sha3.absorb_str("Post-quantum");
2817    let key: [u8; 64] = sha3.get_hash_value_in_array();
2818    print!("K =\t");
2819    for i in 0..64
2820        { print!("{:02X}", key[i]); }
2821    println!();
2822    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2823    let message = "In the beginning God created the heavens and the earth.";
2824    println!("M =\t{}", message);
2825    let mut cipher = Vec::<u8>::new();
2826    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2827    print!("C =\t");
2828    for c in cipher.clone()
2829        { print!("{:02X} ", c); }
2830    println!();
2831    let mut txt = String::new();
2832    for c in cipher.clone()
2833        { write!(txt, "{:02X} ", c); }
2834    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2835
2836    let mut recovered = vec![0; 55];
2837    a_rijndael.decrypt_vec(&cipher, recovered.as_mut_ptr());
2838    print!("Ba =\t");
2839    for b in recovered.clone()
2840        { print!("{:02X} ", b); }
2841    println!();
2842    let mut txt = String::new();
2843    for c in recovered.clone()
2844        { write!(txt, "{:02X} ", c); }
2845    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2846
2847    let mut converted = String::new();
2848    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2849    
2850    println!("Bb =\t{}", converted);
2851    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2852    assert_eq!(converted, message);
2853    println!("-------------------------------");
2854}
2855
2856fn aes_decrypt_vec_with_padding_iso_ecb_into_vec()
2857{
2858    println!("aes_decrypt_vec_with_padding_iso_ecb_into_vec()");
2859    use std::io::Write;
2860    use std::fmt::Write as _;
2861    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2862
2863    // Normal case for AES-128
2864    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2865    println!("K =\t{:#016X}", key);
2866    let mut a_aes = AES_128::new_with_key_u128(key);
2867
2868    let message = "In the beginning God created the heavens and the earth.";
2869    println!("M =\t{}", message);
2870    let mut cipher = Vec::<u8>::new();
2871    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2872    print!("C =\t");
2873    for c in cipher.clone()
2874        { print!("{:02X} ", c); }
2875    println!();
2876    let mut txt = String::new();
2877    for c in cipher.clone()
2878        { write!(txt, "{:02X} ", c); }
2879    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2880
2881    let mut recovered = Vec::<u8>::new();
2882    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2883    print!("Ba =\t");
2884    for b in recovered.clone()
2885        { print!("{:02X} ", b); }
2886    println!();
2887    let mut txt = String::new();
2888    for c in recovered.clone()
2889        { write!(txt, "{:02X} ", c); }
2890    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2891
2892    let mut converted = String::new();
2893    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2894    
2895    println!("Bb =\t{}", converted);
2896    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2897    assert_eq!(converted, message);
2898    println!();
2899
2900    // Normal case for AES-192
2901    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2902    print!("K =\t");
2903    for i in 0..24
2904        { print!("{:02X}", key[i]); }
2905    println!();
2906    let mut a_aes = AES_192::new_with_key(&key);
2907
2908    let message = "In the beginning God created the heavens and the earth.";
2909    println!("M =\t{}", message);
2910    let mut cipher = Vec::<u8>::new();
2911    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2912    print!("C =\t");
2913    for c in cipher.clone()
2914        { print!("{:02X} ", c); }
2915    println!();
2916    let mut txt = String::new();
2917    for c in cipher.clone()
2918        { write!(txt, "{:02X} ", c); }
2919    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2920
2921    let mut recovered = Vec::<u8>::new();
2922    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2923    print!("Ba =\t");
2924    for b in recovered.clone()
2925        { print!("{:02X} ", b); }
2926    println!();
2927    let mut txt = String::new();
2928    for c in recovered.clone()
2929        { write!(txt, "{:02X} ", c); }
2930    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2931
2932    let mut converted = String::new();
2933    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2934    
2935    println!("Bb =\t{}", converted);
2936    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2937    assert_eq!(converted, message);
2938    println!();
2939
2940    // Normal case for AES-256
2941    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2942    print!("K =\t");
2943    for i in 0..32
2944        { print!("{:02X}", key[i]); }
2945    println!();
2946    let mut a_aes = AES_256::new_with_key(&key);
2947
2948    let message = "In the beginning God created the heavens and the earth.";
2949    println!("M =\t{}", message);
2950    let mut cipher = Vec::<u8>::new();
2951    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2952    print!("C =\t");
2953    for c in cipher.clone()
2954        { print!("{:02X} ", c); }
2955    println!();
2956    let mut txt = String::new();
2957    for c in cipher.clone()
2958        { write!(txt, "{:02X} ", c); }
2959    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2960
2961    let mut recovered = Vec::<u8>::new();
2962    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2963    print!("Ba =\t");
2964    for b in recovered.clone()
2965        { print!("{:02X} ", b); }
2966    println!();
2967    let mut txt = String::new();
2968    for c in recovered.clone()
2969        { write!(txt, "{:02X} ", c); }
2970    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2971
2972    let mut converted = String::new();
2973    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2974    
2975    println!("Bb =\t{}", converted);
2976    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2977    assert_eq!(converted, message);
2978    println!();
2979
2980    // Normal case for Rijndael-256-256
2981    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2982    print!("K =\t");
2983    for i in 0..32
2984        { print!("{:02X}", key[i]); }
2985    println!();
2986    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2987
2988    let message = "In the beginning God created the heavens and the earth.";
2989    println!("M =\t{}", message);
2990    let mut cipher = Vec::<u8>::new();
2991    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2992    print!("C =\t");
2993    for c in cipher.clone()
2994        { print!("{:02X} ", c); }
2995    println!();
2996    let mut txt = String::new();
2997    for c in cipher.clone()
2998        { write!(txt, "{:02X} ", c); }
2999    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3000
3001    let mut recovered = Vec::<u8>::new();
3002    a_rijndael.decrypt_vec_into_vec(&cipher, &mut recovered);
3003    print!("Ba =\t");
3004    for b in recovered.clone()
3005        { print!("{:02X} ", b); }
3006    println!();
3007    let mut txt = String::new();
3008    for c in recovered.clone()
3009        { write!(txt, "{:02X} ", c); }
3010    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3011
3012    let mut converted = String::new();
3013    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3014    
3015    println!("Bb =\t{}", converted);
3016    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3017    assert_eq!(converted, message);
3018    println!();
3019
3020    // Normal case for Rijndael-512-512 for post-quantum
3021    use cryptocol::number::SharedArrays;
3022    use cryptocol::hash::SHA3_512;
3023    let mut sha3 = SHA3_512::new();
3024    sha3.absorb_str("Post-quantum");
3025    let key: [u8; 64] = sha3.get_hash_value_in_array();
3026    print!("K =\t");
3027    for i in 0..64
3028        { print!("{:02X}", key[i]); }
3029    println!();
3030    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3031
3032    let message = "In the beginning God created the heavens and the earth.";
3033    println!("M =\t{}", message);
3034    let mut cipher = Vec::<u8>::new();
3035    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3036    print!("C =\t");
3037    for c in cipher.clone()
3038        { print!("{:02X} ", c); }
3039    println!();
3040    let mut txt = String::new();
3041    for c in cipher.clone()
3042        { write!(txt, "{:02X} ", c); }
3043    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3044    
3045    let mut recovered = Vec::<u8>::new();
3046    a_rijndael.decrypt_vec_into_vec(&cipher, &mut recovered);
3047    print!("Ba =\t");
3048    for b in recovered.clone()
3049        { print!("{:02X} ", b); }
3050    println!();
3051    let mut txt = String::new();
3052    for c in recovered.clone()
3053        { write!(txt, "{:02X} ", c); }
3054    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3055
3056    let mut converted = String::new();
3057    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3058    
3059    println!("Bb =\t{}", converted);
3060    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3061    assert_eq!(converted, message);
3062    println!("-------------------------------");
3063}
3064
3065fn aes_decrypt_vec_with_padding_iso_ecb_into_array()
3066{
3067    println!("aes_decrypt_vec_with_padding_iso_ecb_into_array()");
3068    use std::io::Write;
3069    use std::fmt::Write as _;
3070    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3071
3072    // Normal case for AES-128
3073    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3074    println!("K =\t{:#016X}", key);
3075    let mut a_aes = AES_128::new_with_key_u128(key);
3076
3077    let message = "In the beginning God created the heavens and the earth.";
3078    println!("M =\t{}", message);
3079    let mut cipher = Vec::<u8>::new();
3080    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3081    print!("C =\t");
3082    for c in cipher.clone()
3083        { print!("{:02X} ", c); }
3084    println!();
3085    let mut txt = String::new();
3086    for c in cipher.clone()
3087        { write!(txt, "{:02X} ", c); }
3088    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3089
3090    let mut recovered = [0; 64];
3091    let len = a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3092    print!("Ba =\t");
3093    for b in recovered.clone()
3094        { print!("{:02X} ", b); }
3095    println!();
3096    let mut txt = String::new();
3097    for c in recovered.clone()
3098        { write!(txt, "{:02X} ", c); }
3099    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3100
3101    let mut converted = String::new();
3102    unsafe { converted.as_mut_vec() }.write(&recovered);
3103    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3104    println!("Bb =\t{}", converted);
3105    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3106    assert_eq!(converted, message);
3107    println!();
3108
3109    // Normal case for AES-192
3110    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3111    print!("K =\t");
3112    for i in 0..24
3113        { print!("{:02X}", key[i]); }
3114    println!();
3115    let mut a_aes = AES_192::new_with_key(&key);
3116
3117    let message = "In the beginning God created the heavens and the earth.";
3118    println!("M =\t{}", message);
3119    let mut cipher = Vec::<u8>::new();
3120    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3121    print!("C =\t");
3122    for c in cipher.clone()
3123        { print!("{:02X} ", c); }
3124    println!();
3125    let mut txt = String::new();
3126    for c in cipher.clone()
3127        { write!(txt, "{:02X} ", c); }
3128    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3129
3130    let mut recovered = [0; 64];
3131    a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3132    print!("Ba =\t");
3133    for b in recovered.clone()
3134        { print!("{:02X} ", b); }
3135    println!();
3136    let mut txt = String::new();
3137    for c in recovered.clone()
3138        { write!(txt, "{:02X} ", c); }
3139    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3140
3141    let mut converted = String::new();
3142    unsafe { converted.as_mut_vec() }.write(&recovered);
3143    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3144    println!("Bb =\t{}", converted);
3145    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3146    assert_eq!(converted, message);
3147    println!();
3148
3149    // Normal case for AES-256
3150    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3151    print!("K =\t");
3152    for i in 0..32
3153        { print!("{:02X}", key[i]); }
3154    println!();
3155    let mut a_aes = AES_256::new_with_key(&key);
3156
3157    let message = "In the beginning God created the heavens and the earth.";
3158    println!("M =\t{}", message);
3159    let mut cipher = Vec::<u8>::new();
3160    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3161    print!("C =\t");
3162    for c in cipher.clone()
3163        { print!("{:02X} ", c); }
3164    println!();
3165    let mut txt = String::new();
3166    for c in cipher.clone()
3167        { write!(txt, "{:02X} ", c); }
3168    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3169
3170    let mut recovered = [0; 64];
3171    a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3172    print!("Ba =\t");
3173    for b in recovered.clone()
3174        { print!("{:02X} ", b); }
3175    println!();
3176    let mut txt = String::new();
3177    for c in recovered.clone()
3178        { write!(txt, "{:02X} ", c); }
3179    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3180
3181    let mut converted = String::new();
3182    unsafe { converted.as_mut_vec() }.write(&recovered);
3183    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3184    println!("Bb =\t{}", converted);
3185    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3186    assert_eq!(converted, message);
3187    println!();
3188
3189    // Normal case for Rijndael-256-256
3190    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3191    print!("K =\t");
3192    for i in 0..32
3193        { print!("{:02X}", key[i]); }
3194    println!();
3195    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3196
3197    let message = "In the beginning God created the heavens and the earth.";
3198    println!("M =\t{}", message);
3199    let mut cipher = Vec::<u8>::new();
3200    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3201    print!("C =\t");
3202    for c in cipher.clone()
3203        { print!("{:02X} ", c); }
3204    println!();
3205    let mut txt = String::new();
3206    for c in cipher.clone()
3207        { write!(txt, "{:02X} ", c); }
3208    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3209
3210    let mut recovered = [0; 64];
3211    a_rijndael.decrypt_vec_into_array(&cipher, &mut recovered);
3212    print!("Ba =\t");
3213    for b in recovered.clone()
3214        { print!("{:02X} ", b); }
3215    println!();
3216    let mut txt = String::new();
3217    for c in recovered.clone()
3218        { write!(txt, "{:02X} ", c); }
3219    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3220
3221    let mut converted = String::new();
3222    unsafe { converted.as_mut_vec() }.write(&recovered);
3223    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3224    println!("Bb =\t{}", converted);
3225    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3226    assert_eq!(converted, message);
3227    println!();
3228
3229    // Normal case for Rijndael-512-512 for post-quantum
3230    use cryptocol::number::SharedArrays;
3231    use cryptocol::hash::SHA3_512;
3232    let mut sha3 = SHA3_512::new();
3233    sha3.absorb_str("Post-quantum");
3234    let key: [u8; 64] = sha3.get_hash_value_in_array();
3235    print!("K =\t");
3236    for i in 0..64
3237        { print!("{:02X}", key[i]); }
3238    println!();
3239    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3240
3241    let message = "In the beginning God created the heavens and the earth.";
3242    println!("M =\t{}", message);
3243    let mut cipher = Vec::<u8>::new();
3244    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3245    print!("C =\t");
3246    for c in cipher.clone()
3247        { print!("{:02X} ", c); }
3248    println!();
3249    let mut txt = String::new();
3250    for c in cipher.clone()
3251        { write!(txt, "{:02X} ", c); }
3252    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3253    
3254    let mut recovered = [0; 64];
3255    a_rijndael.decrypt_vec_into_array(&cipher, &mut recovered);
3256    print!("Ba =\t");
3257    for b in recovered.clone()
3258        { print!("{:02X} ", b); }
3259    println!();
3260    let mut txt = String::new();
3261    for c in recovered.clone()
3262        { write!(txt, "{:02X} ", c); }
3263    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3264
3265    let mut converted = String::new();
3266    unsafe { converted.as_mut_vec() }.write(&recovered);
3267    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3268    println!("Bb =\t{}", converted);
3269    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3270    assert_eq!(converted, message);
3271    println!("-------------------------------");
3272}
3273
3274fn aes_decrypt_vec_with_padding_iso_ecb_into_string()
3275{
3276    println!("aes_decrypt_vec_with_padding_iso_ecb_into_string()");
3277    use std::io::Write;
3278    use std::fmt::Write as _;
3279    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3280
3281    // Normal case for AES-128
3282    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3283    println!("K =\t{:#016X}", key);
3284    let mut a_aes = AES_128::new_with_key_u128(key);
3285
3286    let message = "In the beginning God created the heavens and the earth.";
3287    println!("M =\t{}", message);
3288    let mut cipher = Vec::<u8>::new();
3289    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3290    print!("C =\t");
3291    for c in cipher.clone()
3292        { print!("{:02X} ", c); }
3293    println!();
3294    let mut txt = String::new();
3295    for c in cipher.clone()
3296        { write!(txt, "{:02X} ", c); }
3297    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3298
3299    let mut converted= String::new();
3300    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3301    println!("B =\t{}", converted);
3302    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3303    assert_eq!(converted, message);
3304    println!();
3305
3306    // Normal case for AES-192
3307    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3308    print!("K =\t");
3309    for i in 0..24
3310        { print!("{:02X}", key[i]); }
3311    println!();
3312    let mut a_aes = AES_192::new_with_key(&key);
3313
3314    let message = "In the beginning God created the heavens and the earth.";
3315    println!("M =\t{}", message);
3316    let mut cipher = Vec::<u8>::new();
3317    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3318    print!("C =\t");
3319    for c in cipher.clone()
3320        { print!("{:02X} ", c); }
3321    println!();
3322    let mut txt = String::new();
3323    for c in cipher.clone()
3324        { write!(txt, "{:02X} ", c); }
3325    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3326
3327    let mut converted= String::new();
3328    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3329    println!("B =\t{}", converted);
3330    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3331    assert_eq!(converted, message);
3332    println!();
3333
3334    // Normal case for AES-256
3335    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3336    print!("K =\t");
3337    for i in 0..32
3338        { print!("{:02X}", key[i]); }
3339    println!();
3340    let mut a_aes = AES_256::new_with_key(&key);
3341
3342    let message = "In the beginning God created the heavens and the earth.";
3343    println!("M =\t{}", message);
3344    let mut cipher = Vec::<u8>::new();
3345    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3346    print!("C =\t");
3347    for c in cipher.clone()
3348        { print!("{:02X} ", c); }
3349    println!();
3350    let mut txt = String::new();
3351    for c in cipher.clone()
3352        { write!(txt, "{:02X} ", c); }
3353    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3354
3355    let mut converted= String::new();
3356    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3357    println!("B =\t{}", converted);
3358    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3359    assert_eq!(converted, message);
3360    println!();
3361
3362    // Normal case for Rijndael-256-256
3363    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3364    print!("K =\t");
3365    for i in 0..32
3366        { print!("{:02X}", key[i]); }
3367    println!();
3368    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3369
3370    let message = "In the beginning God created the heavens and the earth.";
3371    println!("M =\t{}", message);
3372    let mut cipher = Vec::<u8>::new();
3373    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3374    print!("C =\t");
3375    for c in cipher.clone()
3376        { print!("{:02X} ", c); }
3377    println!();
3378    let mut txt = String::new();
3379    for c in cipher.clone()
3380        { write!(txt, "{:02X} ", c); }
3381    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3382
3383    let mut converted= String::new();
3384    a_rijndael.decrypt_vec_into_string(&cipher, &mut converted);
3385    println!("B =\t{}", converted);
3386    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3387    assert_eq!(converted, message);
3388    println!();
3389
3390    // Normal case for Rijndael-512-512 for post-quantum
3391    use cryptocol::number::SharedArrays;
3392    use cryptocol::hash::SHA3_512;
3393    let mut sha3 = SHA3_512::new();
3394    sha3.absorb_str("Post-quantum");
3395    let key: [u8; 64] = sha3.get_hash_value_in_array();
3396    print!("K =\t");
3397    for i in 0..64
3398        { print!("{:02X}", key[i]); }
3399    println!();
3400    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3401
3402    let message = "In the beginning God created the heavens and the earth.";
3403    println!("M =\t{}", message);
3404    let mut cipher = Vec::<u8>::new();
3405    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3406    print!("C =\t");
3407    for c in cipher.clone()
3408        { print!("{:02X} ", c); }
3409    println!();
3410    let mut txt = String::new();
3411    for c in cipher.clone()
3412        { write!(txt, "{:02X} ", c); }
3413    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3414    
3415    let mut converted= String::new();
3416    a_rijndael.decrypt_vec_into_string(&cipher, &mut converted);
3417    println!("B =\t{}", converted);
3418    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3419    assert_eq!(converted, message);
3420    println!("-------------------------------");
3421}
examples/des_ecb_iso_examples.rs (line 760)
745fn des_encrypt_str_with_padding_iso_ecb_into_vec()
746{
747    println!("des_encrypt_str_with_padding_iso_ecb_into_vec()");
748    use std::io::Write;
749    use std::fmt::Write as _;
750    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
751
752    // Normal case
753    let key = 0x_1234567890ABCDEF_u64;
754    println!("K =\t{:#016X}", key);
755    let mut a_des = DES::new_with_key_u64(key);
756
757    let message = "In the beginning God created the heavens and the earth.";
758    println!("M =\t{}", message);
759    let mut cipher = Vec::<u8>::new();
760    a_des.encrypt_str_into_vec(&message, &mut cipher);
761    print!("C (16 rounds) =\t");
762    for c in cipher.clone()
763        { print!("{:02X} ", c); }
764    println!();
765    let mut txt = String::new();
766    for c in cipher.clone()
767        { write!(txt, "{:02X} ", c); }
768    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
769    println!();
770
771    // Expanded case for 128 rounds
772    let key = 0x_1234567890ABCDEF_u64;
773    println!("K =\t{:#016X}", key);
774    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
775
776    let message = "In the beginning God created the heavens and the earth.";
777    println!("M =\t{}", message);
778    let mut cipher = Vec::<u8>::new();
779    a_des.encrypt_str_into_vec(&message, &mut cipher);
780    print!("C (128 rounds) =\t");
781    for c in cipher.clone()
782        { print!("{:02X} ", c); }
783    println!();
784    let mut txt = String::new();
785    for c in cipher.clone()
786        { write!(txt, "{:02X} ", c); }
787    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
788    println!();
789
790    // Expanded case for 0 rounds which means that key is meaningless
791    let key1 = 0x_1234567890ABCDEF_u64;
792    let key2 = 0_u64;
793    println!("K =\t{:#016X}", key);
794    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
795    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
796
797    let message = "In the beginning God created the heavens and the earth.";
798    println!("M =\t{}", message);
799    let mut cipher1 = Vec::<u8>::new();
800    let mut cipher2 = Vec::<u8>::new();
801    c_des.encrypt_str_into_vec(&message, &mut cipher1);
802    d_des.encrypt_str_into_vec(&message, &mut cipher2);
803    print!("C (0 rounds) =\t");
804    for c in cipher1.clone()
805        { print!("{:02X} ", c); }
806    println!();
807    let mut txt = String::new();
808    for c in cipher1.clone()
809        { write!(txt, "{:02X} ", c); }
810    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
811    print!("D (0 rounds) =\t");
812    for c in cipher2.clone()
813        { print!("{:02X} ", c); }
814    println!();
815    let mut txt = String::new();
816    for c in cipher2.clone()
817        { write!(txt, "{:02X} ", c); }
818    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
819    println!();
820
821    // Normal case for the message of 0 bytes
822    let key = 0x_1234567890ABCDEF_u64;
823    println!("K =\t{:#016X}", key);
824    let mut a_des = DES::new_with_key_u64(key);
825
826    let message = "";
827    println!("M =\t{}", message);
828    let mut cipher = Vec::<u8>::new();
829    a_des.encrypt_str_into_vec(&message, &mut cipher);
830    print!("C =\t");
831    for c in cipher.clone()
832        { print!("{:02X} ", c); }
833    println!();
834    let mut txt = String::new();
835    for c in cipher.clone()
836        { write!(txt, "{:02X} ", c); }
837    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
838    println!();
839
840    // Normal case for the message shorter than 8 bytes
841    let key = 0x_1234567890ABCDEF_u64;
842    println!("K =\t{:#016X}", key);
843    let mut a_des = DES::new_with_key_u64(key);
844
845    let message = "7 bytes";
846    println!("M =\t{}", message);
847    let mut cipher = Vec::<u8>::new();
848    a_des.encrypt_str_into_vec(&message, &mut cipher);
849    print!("C =\t");
850    for c in cipher.clone()
851        { print!("{:02X} ", c); }
852    println!();
853    let mut txt = String::new();
854    for c in cipher.clone()
855        { write!(txt, "{:02X} ", c); }
856    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
857    println!();
858
859    // Normal case for the message of 8 bytes
860    let key = 0x_1234567890ABCDEF_u64;
861    println!("K =\t{:#016X}", key);
862    let mut a_des = DES::new_with_key_u64(key);
863
864    let message = "I am OK.";
865    println!("M =\t{}", message);
866    let mut cipher = Vec::<u8>::new();
867    a_des.encrypt_str_into_vec(&message, &mut cipher);
868    print!("C =\t");
869    for c in cipher.clone()
870        { print!("{:02X} ", c); }
871    println!();
872    let mut txt = String::new();
873    for c in cipher.clone()
874        { write!(txt, "{:02X} ", c); }
875    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
876    println!();
877
878    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
879    let key = 0x_1234567890ABCDEF_u64;
880    println!("K =\t{:#016X}", key);
881    let mut a_des = DES::new_with_key_u64(key);
882
883    let message = "PARK Youngho";
884    println!("M =\t{}", message);
885    let mut cipher = Vec::<u8>::new();
886    a_des.encrypt_str_into_vec(&message, &mut cipher);
887    print!("C =\t");
888    for c in cipher.clone()
889        { print!("{:02X} ", c); }
890    println!();
891    let mut txt = String::new();
892    for c in cipher.clone()
893        { write!(txt, "{:02X} ", c); }
894    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
895    println!();
896
897
898    // Normal case for the message of 16 bytes
899    let key = 0x_1234567890ABCDEF_u64;
900    println!("K =\t{:#016X}", key);
901    let mut a_des = DES::new_with_key_u64(key);
902
903    let message = "고맙습니다.";
904    println!("M =\t{}", message);
905    let mut cipher = Vec::<u8>::new();
906    a_des.encrypt_str_into_vec(&message, &mut cipher);
907    print!("C =\t");
908    for c in cipher.clone()
909        { print!("{:02X} ", c); }
910    println!();
911    let mut txt = String::new();
912    for c in cipher.clone()
913        { write!(txt, "{:02X} ", c); }
914    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
915    println!("-------------------------------");
916}
917
918fn des_encrypt_str_with_padding_iso_ecb_into_array()
919{
920    println!("des_encrypt_str_with_padding_iso_ecb_into_array()");
921    use std::io::Write;
922    use std::fmt::Write as _;
923    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
924
925    // Normal case
926    let key = 0x_1234567890ABCDEF_u64;
927    println!("K =\t{:#016X}", key);
928    let mut a_des = DES::new_with_key_u64(key);
929
930    let message = "In the beginning God created the heavens and the earth.";
931    println!("M =\t{}", message);
932    let mut cipher = [0_u8; 56];
933    a_des.encrypt_str_into_array(&message, &mut cipher);
934    print!("C (16 rounds) =\t");
935    for c in cipher.clone()
936        { print!("{:02X} ", c); }
937    println!();
938    let mut txt = String::new();
939    for c in cipher.clone()
940        { write!(txt, "{:02X} ", c); }
941    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
942    println!();
943
944    // Expanded case for 128 rounds
945    let key = 0x_1234567890ABCDEF_u64;
946    println!("K =\t{:#016X}", key);
947    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
948
949    let message = "In the beginning God created the heavens and the earth.";
950    println!("M =\t{}", message);
951    let mut cipher = [0_u8; 56];
952    a_des.encrypt_str_into_array(&message, &mut cipher);
953    print!("C (128 rounds) =\t");
954    for c in cipher.clone()
955        { print!("{:02X} ", c); }
956    println!();
957    let mut txt = String::new();
958    for c in cipher.clone()
959        { write!(txt, "{:02X} ", c); }
960    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
961    println!();
962
963    // Expanded case for 0 rounds which means that key is meaningless
964    let key1 = 0x_1234567890ABCDEF_u64;
965    let key2 = 0_u64;
966    println!("K =\t{:#016X}", key);
967    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
968    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
969
970    let message = "In the beginning God created the heavens and the earth.";
971    println!("M =\t{}", message);
972    let mut cipher1 = [0_u8; 56];
973    let mut cipher2 = [0_u8; 56];
974    c_des.encrypt_str_into_array(&message, &mut cipher1);
975    d_des.encrypt_str_into_array(&message, &mut cipher2);
976    print!("C (0 rounds) =\t");
977    for c in cipher1.clone()
978        { print!("{:02X} ", c); }
979    println!();
980    let mut txt = String::new();
981    for c in cipher1.clone()
982        { write!(txt, "{:02X} ", c); }
983    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
984    print!("D (0 rounds) =\t");
985    for c in cipher2.clone()
986        { print!("{:02X} ", c); }
987    println!();
988    let mut txt = String::new();
989    for c in cipher2.clone()
990        { write!(txt, "{:02X} ", c); }
991    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
992    println!();
993
994    // Normal case for the message of 0 bytes
995    let key = 0x_1234567890ABCDEF_u64;
996    println!("K =\t{:#016X}", key);
997    let mut a_des = DES::new_with_key_u64(key);
998
999    let message = "";
1000    println!("M =\t{}", message);
1001    let mut cipher = [0_u8; 8];
1002    a_des.encrypt_str_into_array(&message, &mut cipher);
1003    print!("C =\t");
1004    for c in cipher.clone()
1005        { print!("{:02X} ", c); }
1006    println!();
1007    let mut txt = String::new();
1008    for c in cipher.clone()
1009        { write!(txt, "{:02X} ", c); }
1010    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1011    println!();
1012
1013    // Normal case for the message shorter than 8 bytes
1014    let key = 0x_1234567890ABCDEF_u64;
1015    println!("K =\t{:#016X}", key);
1016    let mut a_des = DES::new_with_key_u64(key);
1017
1018    let message = "7 bytes";
1019    println!("M =\t{}", message);
1020    let mut cipher = [0_u8; 8];
1021    a_des.encrypt_str_into_array(&message, &mut cipher);
1022    print!("C =\t");
1023    for c in cipher.clone()
1024        { print!("{:02X} ", c); }
1025    println!();
1026    let mut txt = String::new();
1027    for c in cipher.clone()
1028        { write!(txt, "{:02X} ", c); }
1029    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1030    println!();
1031
1032    // Normal case for the message of 8 bytes
1033    let key = 0x_1234567890ABCDEF_u64;
1034    println!("K =\t{:#016X}", key);
1035    let mut a_des = DES::new_with_key_u64(key);
1036
1037    let message = "I am OK.";
1038    println!("M =\t{}", message);
1039    let mut cipher = [0_u8; 16];
1040    a_des.encrypt_str_into_array(&message, &mut cipher);
1041    print!("C =\t");
1042    for c in cipher.clone()
1043        { print!("{:02X} ", c); }
1044    println!();
1045    let mut txt = String::new();
1046    for c in cipher.clone()
1047        { write!(txt, "{:02X} ", c); }
1048    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1049    println!();
1050
1051    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1052    let key = 0x_1234567890ABCDEF_u64;
1053    println!("K =\t{:#016X}", key);
1054    let mut a_des = DES::new_with_key_u64(key);
1055
1056    let message = "PARK Youngho";
1057    println!("M =\t{}", message);
1058    let mut cipher = [0_u8; 16];
1059    a_des.encrypt_str_into_array(&message, &mut cipher);
1060    print!("C =\t");
1061    for c in cipher.clone()
1062        { print!("{:02X} ", c); }
1063    println!();
1064    let mut txt = String::new();
1065    for c in cipher.clone()
1066        { write!(txt, "{:02X} ", c); }
1067    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1068    println!();
1069
1070
1071    // Normal case for the message of 16 bytes
1072    let key = 0x_1234567890ABCDEF_u64;
1073    println!("K =\t{:#016X}", key);
1074    let mut a_des = DES::new_with_key_u64(key);
1075
1076    let message = "고맙습니다.";
1077    println!("M =\t{}", message);
1078    let mut cipher = [0_u8; 24];
1079    a_des.encrypt_str_into_array(&message, &mut cipher);
1080    print!("C =\t");
1081    for c in cipher.clone()
1082        { print!("{:02X} ", c); }
1083    println!();
1084    let mut txt = String::new();
1085    for c in cipher.clone()
1086        { write!(txt, "{:02X} ", c); }
1087    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1088    println!("-------------------------------");
1089}
1090
1091fn des_encrypt_string_with_padding_iso_ecb()
1092{
1093    println!("des_encrypt_string_with_padding_iso_ecb()");
1094    use std::io::Write;
1095    use std::fmt::Write as _;
1096    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1097
1098    // Normal case
1099    let key = 0x_1234567890ABCDEF_u64;
1100    println!("K =\t{:#016X}", key);
1101    let mut a_des = DES::new_with_key_u64(key);
1102
1103    let message = "In the beginning God created the heavens and the earth.".to_string();
1104    println!("M =\t{}", message);
1105    let mut cipher = [0_u8; 56];
1106    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1107    print!("C (16 rounds) =\t");
1108    for c in cipher.clone()
1109        { print!("{:02X} ", c); }
1110    println!();
1111    let mut txt = String::new();
1112    for c in cipher.clone()
1113        { write!(txt, "{:02X} ", c); }
1114    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1115    println!();
1116
1117    // Expanded case for 128 rounds
1118    let key = 0x_1234567890ABCDEF_u64;
1119    println!("K =\t{:#016X}", key);
1120    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1121
1122    let message = "In the beginning God created the heavens and the earth.".to_string();
1123    println!("M =\t{}", message);
1124    let mut cipher = [0_u8; 56];
1125    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1126    print!("C (128 rounds) =\t");
1127    for c in cipher.clone()
1128        { print!("{:02X} ", c); }
1129    println!();
1130    let mut txt = String::new();
1131    for c in cipher.clone()
1132        { write!(txt, "{:02X} ", c); }
1133    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1134    println!();
1135
1136    // Expanded case for 0 rounds which means that key is meaningless
1137    let key1 = 0x_1234567890ABCDEF_u64;
1138    let key2 = 0_u64;
1139    println!("K =\t{:#016X}", key);
1140    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1141    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1142
1143    let message = "In the beginning God created the heavens and the earth.".to_string();
1144    println!("M =\t{}", message);
1145    let mut cipher1 = [0_u8; 56];
1146    let mut cipher2 = [0_u8; 56];
1147    c_des.encrypt_string(&message, cipher1.as_mut_ptr());
1148    d_des.encrypt_string(&message, cipher2.as_mut_ptr());
1149    print!("C (0 rounds) =\t");
1150    for c in cipher1.clone()
1151        { print!("{:02X} ", c); }
1152    println!();
1153    let mut txt = String::new();
1154    for c in cipher1.clone()
1155        { write!(txt, "{:02X} ", c); }
1156    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1157    print!("D (0 rounds) =\t");
1158    for c in cipher2.clone()
1159        { print!("{:02X} ", c); }
1160    println!();
1161    let mut txt = String::new();
1162    for c in cipher2.clone()
1163        { write!(txt, "{:02X} ", c); }
1164    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1165    println!();
1166
1167    // Normal case for the message of 0 bytes
1168    let key = 0x_1234567890ABCDEF_u64;
1169    println!("K =\t{:#016X}", key);
1170    let mut a_des = DES::new_with_key_u64(key);
1171
1172    let message = "".to_string();
1173    println!("M =\t{}", message);
1174    let mut cipher = [0_u8; 8];
1175    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1176    print!("C =\t");
1177    for c in cipher.clone()
1178        { print!("{:02X} ", c); }
1179    println!();
1180    let mut txt = String::new();
1181    for c in cipher.clone()
1182        { write!(txt, "{:02X} ", c); }
1183    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1184    println!();
1185
1186    // Normal case for the message shorter than 8 bytes
1187    let key = 0x_1234567890ABCDEF_u64;
1188    println!("K =\t{:#016X}", key);
1189    let mut a_des = DES::new_with_key_u64(key);
1190
1191    let message = "7 bytes".to_string();
1192    println!("M =\t{}", message);
1193    let mut cipher = [0_u8; 8];
1194    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1195    print!("C =\t");
1196    for c in cipher.clone()
1197        { print!("{:02X} ", c); }
1198    println!();
1199    let mut txt = String::new();
1200    for c in cipher.clone()
1201        { write!(txt, "{:02X} ", c); }
1202    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1203    println!();
1204
1205    // Normal case for the message of 8 bytes
1206    let key = 0x_1234567890ABCDEF_u64;
1207    println!("K =\t{:#016X}", key);
1208    let mut a_des = DES::new_with_key_u64(key);
1209
1210    let message = "I am OK.".to_string();
1211    println!("M =\t{}", message);
1212    let mut cipher = [0_u8; 16];
1213    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1214    print!("C =\t");
1215    for c in cipher.clone()
1216        { print!("{:02X} ", c); }
1217    println!();
1218    let mut txt = String::new();
1219    for c in cipher.clone()
1220        { write!(txt, "{:02X} ", c); }
1221    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1222    println!();
1223
1224    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1225    let key = 0x_1234567890ABCDEF_u64;
1226    println!("K =\t{:#016X}", key);
1227    let mut a_des = DES::new_with_key_u64(key);
1228
1229    let message = "PARK Youngho".to_string();
1230    println!("M =\t{}", message);
1231    let mut cipher = [0_u8; 16];
1232    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1233    print!("C =\t");
1234    for c in cipher.clone()
1235        { print!("{:02X} ", c); }
1236    println!();
1237    let mut txt = String::new();
1238    for c in cipher.clone()
1239        { write!(txt, "{:02X} ", c); }
1240    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1241    println!();
1242
1243
1244    // Normal case for the message of 16 bytes
1245    let key = 0x_1234567890ABCDEF_u64;
1246    println!("K =\t{:#016X}", key);
1247    let mut a_des = DES::new_with_key_u64(key);
1248
1249    let message = "고맙습니다.".to_string();
1250    println!("M =\t{}", message);
1251    let mut cipher = [0_u8; 24];
1252    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1253    print!("C =\t");
1254    for c in cipher.clone()
1255        { print!("{:02X} ", c); }
1256    println!();
1257    let mut txt = String::new();
1258    for c in cipher.clone()
1259        { write!(txt, "{:02X} ", c); }
1260    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1261    println!("-------------------------------");
1262}
1263
1264fn des_encrypt_string_with_padding_iso_ecb_into_vec()
1265{
1266    println!("des_encrypt_string_with_padding_iso_ecb_into_vec()");
1267    use std::io::Write;
1268    use std::fmt::Write as _;
1269    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1270
1271    // Normal case
1272    let key = 0x_1234567890ABCDEF_u64;
1273    println!("K =\t{:#016X}", key);
1274    let mut a_des = DES::new_with_key_u64(key);
1275
1276    let message = "In the beginning God created the heavens and the earth.".to_string();
1277    println!("M =\t{}", message);
1278    let mut cipher = Vec::<u8>::new();
1279    a_des.encrypt_string_into_vec(&message, &mut cipher);
1280    print!("C (16 rounds) =\t");
1281    for c in cipher.clone()
1282        { print!("{:02X} ", c); }
1283    println!();
1284    let mut txt = String::new();
1285    for c in cipher.clone()
1286        { write!(txt, "{:02X} ", c); }
1287    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1288    println!();
1289
1290    // Expanded case for 128 rounds
1291    let key = 0x_1234567890ABCDEF_u64;
1292    println!("K =\t{:#016X}", key);
1293    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1294
1295    let message = "In the beginning God created the heavens and the earth.".to_string();
1296    println!("M =\t{}", message);
1297    let mut cipher = Vec::<u8>::new();
1298    a_des.encrypt_string_into_vec(&message, &mut cipher);
1299    print!("C (128 rounds) =\t");
1300    for c in cipher.clone()
1301        { print!("{:02X} ", c); }
1302    println!();
1303    let mut txt = String::new();
1304    for c in cipher.clone()
1305        { write!(txt, "{:02X} ", c); }
1306    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1307    println!();
1308
1309    // Expanded case for 0 rounds which means that key is meaningless
1310    let key1 = 0x_1234567890ABCDEF_u64;
1311    let key2 = 0_u64;
1312    println!("K =\t{:#016X}", key);
1313    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1314    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1315
1316    let message = "In the beginning God created the heavens and the earth.".to_string();
1317    println!("M =\t{}", message);
1318    let mut cipher1 = Vec::<u8>::new();
1319    let mut cipher2 = Vec::<u8>::new();
1320    c_des.encrypt_string_into_vec(&message, &mut cipher1);
1321    d_des.encrypt_string_into_vec(&message, &mut cipher2);
1322    print!("C (0 rounds) =\t");
1323    for c in cipher1.clone()
1324        { print!("{:02X} ", c); }
1325    println!();
1326    let mut txt = String::new();
1327    for c in cipher1.clone()
1328        { write!(txt, "{:02X} ", c); }
1329    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1330    print!("D (0 rounds) =\t");
1331    for c in cipher2.clone()
1332        { print!("{:02X} ", c); }
1333    println!();
1334    let mut txt = String::new();
1335    for c in cipher2.clone()
1336        { write!(txt, "{:02X} ", c); }
1337    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1338    println!();
1339
1340    // Normal case for the message of 0 bytes
1341    let key = 0x_1234567890ABCDEF_u64;
1342    println!("K =\t{:#016X}", key);
1343    let mut a_des = DES::new_with_key_u64(key);
1344
1345    let message = "".to_string();
1346    println!("M =\t{}", message);
1347    let mut cipher = Vec::<u8>::new();
1348    a_des.encrypt_string_into_vec(&message, &mut cipher);
1349    print!("C =\t");
1350    for c in cipher.clone()
1351        { print!("{:02X} ", c); }
1352    println!();
1353    let mut txt = String::new();
1354    for c in cipher.clone()
1355        { write!(txt, "{:02X} ", c); }
1356    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1357    println!();
1358
1359    // Normal case for the message shorter than 8 bytes
1360    let key = 0x_1234567890ABCDEF_u64;
1361    println!("K =\t{:#016X}", key);
1362    let mut a_des = DES::new_with_key_u64(key);
1363
1364    let message = "7 bytes".to_string();
1365    println!("M =\t{}", message);
1366    let mut cipher = Vec::<u8>::new();
1367    a_des.encrypt_string_into_vec(&message, &mut cipher);
1368    print!("C =\t");
1369    for c in cipher.clone()
1370        { print!("{:02X} ", c); }
1371    println!();
1372    let mut txt = String::new();
1373    for c in cipher.clone()
1374        { write!(txt, "{:02X} ", c); }
1375    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1376    println!();
1377
1378    // Normal case for the message of 8 bytes
1379    let key = 0x_1234567890ABCDEF_u64;
1380    println!("K =\t{:#016X}", key);
1381    let mut a_des = DES::new_with_key_u64(key);
1382
1383    let message = "I am OK.".to_string();
1384    println!("M =\t{}", message);
1385    let mut cipher = Vec::<u8>::new();
1386    a_des.encrypt_string_into_vec(&message, &mut cipher);
1387    print!("C =\t");
1388    for c in cipher.clone()
1389        { print!("{:02X} ", c); }
1390    println!();
1391    let mut txt = String::new();
1392    for c in cipher.clone()
1393        { write!(txt, "{:02X} ", c); }
1394    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1395    println!();
1396
1397    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1398    let key = 0x_1234567890ABCDEF_u64;
1399    println!("K =\t{:#016X}", key);
1400    let mut a_des = DES::new_with_key_u64(key);
1401
1402    let message = "PARK Youngho".to_string();
1403    println!("M =\t{}", message);
1404    let mut cipher = Vec::<u8>::new();
1405    a_des.encrypt_string_into_vec(&message, &mut cipher);
1406    print!("C =\t");
1407    for c in cipher.clone()
1408        { print!("{:02X} ", c); }
1409    println!();
1410    let mut txt = String::new();
1411    for c in cipher.clone()
1412        { write!(txt, "{:02X} ", c); }
1413    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1414    println!();
1415
1416
1417    // Normal case for the message of 16 bytes
1418    let key = 0x_1234567890ABCDEF_u64;
1419    println!("K =\t{:#016X}", key);
1420    let mut a_des = DES::new_with_key_u64(key);
1421
1422    let message = "고맙습니다.".to_string();
1423    println!("M =\t{}", message);
1424    let mut cipher = Vec::<u8>::new();
1425    a_des.encrypt_string_into_vec(&message, &mut cipher);
1426    print!("C =\t");
1427    for c in cipher.clone()
1428        { print!("{:02X} ", c); }
1429    println!();
1430    let mut txt = String::new();
1431    for c in cipher.clone()
1432        { write!(txt, "{:02X} ", c); }
1433    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1434    println!("-------------------------------");
1435}
1436
1437fn des_encrypt_string_with_padding_iso_ecb_into_array()
1438{
1439    println!("des_encrypt_string_with_padding_iso_ecb_into_array()");
1440    use std::io::Write;
1441    use std::fmt::Write as _;
1442    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1443
1444    // Normal case
1445    let key = 0x_1234567890ABCDEF_u64;
1446    println!("K =\t{:#016X}", key);
1447    let mut a_des = DES::new_with_key_u64(key);
1448
1449    let message = "In the beginning God created the heavens and the earth.".to_string();
1450    println!("M =\t{}", message);
1451    let mut cipher = [0_u8; 56];
1452    a_des.encrypt_string_into_array(&message, &mut cipher);
1453    print!("C (16 rounds) =\t");
1454    for c in cipher.clone()
1455        { print!("{:02X} ", c); }
1456    println!();
1457    let mut txt = String::new();
1458    for c in cipher.clone()
1459        { write!(txt, "{:02X} ", c); }
1460    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1461    println!();
1462
1463    // Expanded case for 128 rounds
1464    let key = 0x_1234567890ABCDEF_u64;
1465    println!("K =\t{:#016X}", key);
1466    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1467
1468    let message = "In the beginning God created the heavens and the earth.".to_string();
1469    println!("M =\t{}", message);
1470    let mut cipher = [0_u8; 56];
1471    a_des.encrypt_string_into_array(&message, &mut cipher);
1472    print!("C (128 rounds) =\t");
1473    for c in cipher.clone()
1474        { print!("{:02X} ", c); }
1475    println!();
1476    let mut txt = String::new();
1477    for c in cipher.clone()
1478        { write!(txt, "{:02X} ", c); }
1479    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1480    println!();
1481
1482    // Expanded case for 0 rounds which means that key is meaningless
1483    let key1 = 0x_1234567890ABCDEF_u64;
1484    let key2 = 0_u64;
1485    println!("K =\t{:#016X}", key);
1486    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1487    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1488
1489    let message = "In the beginning God created the heavens and the earth.".to_string();
1490    println!("M =\t{}", message);
1491    let mut cipher1 = [0_u8; 56];
1492    let mut cipher2 = [0_u8; 56];
1493    c_des.encrypt_string_into_array(&message, &mut cipher1);
1494    d_des.encrypt_string_into_array(&message, &mut cipher2);
1495    print!("C (0 rounds) =\t");
1496    for c in cipher1.clone()
1497        { print!("{:02X} ", c); }
1498    println!();
1499    let mut txt = String::new();
1500    for c in cipher1.clone()
1501        { write!(txt, "{:02X} ", c); }
1502    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1503    print!("D (0 rounds) =\t");
1504    for c in cipher2.clone()
1505        { print!("{:02X} ", c); }
1506    println!();
1507    let mut txt = String::new();
1508    for c in cipher2.clone()
1509        { write!(txt, "{:02X} ", c); }
1510    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1511    println!();
1512
1513    // Normal case for the message of 0 bytes
1514    let key = 0x_1234567890ABCDEF_u64;
1515    println!("K =\t{:#016X}", key);
1516    let mut a_des = DES::new_with_key_u64(key);
1517
1518    let message = "".to_string();
1519    println!("M =\t{}", message);
1520    let mut cipher = [0_u8; 8];
1521    a_des.encrypt_string_into_array(&message, &mut cipher);
1522    print!("C =\t");
1523    for c in cipher.clone()
1524        { print!("{:02X} ", c); }
1525    println!();
1526    let mut txt = String::new();
1527    for c in cipher.clone()
1528        { write!(txt, "{:02X} ", c); }
1529    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1530    println!();
1531
1532    // Normal case for the message shorter than 8 bytes
1533    let key = 0x_1234567890ABCDEF_u64;
1534    println!("K =\t{:#016X}", key);
1535    let mut a_des = DES::new_with_key_u64(key);
1536
1537    let message = "7 bytes".to_string();
1538    println!("M =\t{}", message);
1539    let mut cipher = [0_u8; 8];
1540    a_des.encrypt_string_into_array(&message, &mut cipher);
1541    print!("C =\t");
1542    for c in cipher.clone()
1543        { print!("{:02X} ", c); }
1544    println!();
1545    let mut txt = String::new();
1546    for c in cipher.clone()
1547        { write!(txt, "{:02X} ", c); }
1548    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1549    println!();
1550
1551    // Normal case for the message of 8 bytes
1552    let key = 0x_1234567890ABCDEF_u64;
1553    println!("K =\t{:#016X}", key);
1554    let mut a_des = DES::new_with_key_u64(key);
1555
1556    let message = "I am OK.".to_string();
1557    println!("M =\t{}", message);
1558    let mut cipher = [0_u8; 16];
1559    a_des.encrypt_string_into_array(&message, &mut cipher);
1560    print!("C =\t");
1561    for c in cipher.clone()
1562        { print!("{:02X} ", c); }
1563    println!();
1564    let mut txt = String::new();
1565    for c in cipher.clone()
1566        { write!(txt, "{:02X} ", c); }
1567    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1568    println!();
1569
1570    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1571    let key = 0x_1234567890ABCDEF_u64;
1572    println!("K =\t{:#016X}", key);
1573    let mut a_des = DES::new_with_key_u64(key);
1574
1575    let message = "PARK Youngho".to_string();
1576    println!("M =\t{}", message);
1577    let mut cipher = [0_u8; 16];
1578    a_des.encrypt_string_into_array(&message, &mut cipher);
1579    print!("C =\t");
1580    for c in cipher.clone()
1581        { print!("{:02X} ", c); }
1582    println!();
1583    let mut txt = String::new();
1584    for c in cipher.clone()
1585        { write!(txt, "{:02X} ", c); }
1586    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1587    println!();
1588
1589    // Normal case for the message of 16 bytes
1590    let key = 0x_1234567890ABCDEF_u64;
1591    println!("K =\t{:#016X}", key);
1592    let mut a_des = DES::new_with_key_u64(key);
1593
1594    let message = "고맙습니다.".to_string();
1595    println!("M =\t{}", message);
1596    let mut cipher = [0_u8; 24];
1597    a_des.encrypt_string_into_array(&message, &mut cipher);
1598    print!("C =\t");
1599    for c in cipher.clone()
1600        { print!("{:02X} ", c); }
1601    println!();
1602    let mut txt = String::new();
1603    for c in cipher.clone()
1604        { write!(txt, "{:02X} ", c); }
1605    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1606    println!("-------------------------------");
1607}
1608
1609fn des_encrypt_vec_with_padding_iso_ecb()
1610{
1611    println!("des_encrypt_vec_with_padding_iso_ecb()");
1612    use std::io::Write;
1613    use std::fmt::Write as _;
1614    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1615
1616    // Normal case
1617    let key = 0x_1234567890ABCDEF_u64;
1618    println!("K =\t{:#016X}", key);
1619    let mut a_des = DES::new_with_key_u64(key);
1620
1621    let message = "In the beginning God created the heavens and the earth.";
1622    println!("M =\t{}", message);
1623    let message = unsafe { message.to_string().as_mut_vec().clone() };
1624    let mut cipher = [0_u8; 56];
1625    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1626    print!("C (16 rounds) =\t");
1627    for c in cipher.clone()
1628        { print!("{:02X} ", c); }
1629    println!();
1630    let mut txt = String::new();
1631    for c in cipher.clone()
1632        { write!(txt, "{:02X} ", c); }
1633    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1634    println!();
1635
1636    // Expanded case for 128 rounds
1637    let key = 0x_1234567890ABCDEF_u64;
1638    println!("K =\t{:#016X}", key);
1639    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1640
1641    let message = "In the beginning God created the heavens and the earth.";
1642    println!("M =\t{}", message);
1643    let message = unsafe { message.to_string().as_mut_vec().clone() };
1644    let mut cipher = [0_u8; 56];
1645    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1646    print!("C (128 rounds) =\t");
1647    for c in cipher.clone()
1648        { print!("{:02X} ", c); }
1649    println!();
1650    let mut txt = String::new();
1651    for c in cipher.clone()
1652        { write!(txt, "{:02X} ", c); }
1653    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1654    println!();
1655
1656    // Expanded case for 0 rounds which means that key is meaningless
1657    let key1 = 0x_1234567890ABCDEF_u64;
1658    let key2 = 0_u64;
1659    println!("K1 =\t{:#016X}", key1);
1660    println!("K2 =\t{:#016X}", key2);
1661    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1662    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1663
1664    let message = "In the beginning God created the heavens and the earth.";
1665    println!("M =\t{}", message);
1666    let message = unsafe { message.to_string().as_mut_vec().clone() };
1667    let mut cipher1 = [0_u8; 56];
1668    let mut cipher2 = [0_u8; 56];
1669    c_des.encrypt_vec(&message, cipher1.as_mut_ptr());
1670    d_des.encrypt_vec(&message, cipher2.as_mut_ptr());
1671    print!("C (0 rounds) =\t");
1672    for c in cipher1.clone()
1673        { print!("{:02X} ", c); }
1674    println!();
1675    let mut txt = String::new();
1676    for c in cipher1.clone()
1677        { write!(txt, "{:02X} ", c); }
1678    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1679    print!("D (0 rounds) =\t");
1680    for c in cipher2.clone()
1681        { print!("{:02X} ", c); }
1682    println!();
1683    let mut txt = String::new();
1684    for c in cipher2.clone()
1685        { write!(txt, "{:02X} ", c); }
1686    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1687    println!();
1688
1689    // Normal case for the message of 0 bytes
1690    let key = 0x_1234567890ABCDEF_u64;
1691    println!("K =\t{:#016X}", key);
1692    let mut a_des = DES::new_with_key_u64(key);
1693
1694    let message = "";
1695    println!("M =\t{}", message);
1696    let message = unsafe { message.to_string().as_mut_vec().clone() };
1697    let mut cipher = [0_u8; 8];
1698    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1699    print!("C =\t");
1700    for c in cipher.clone()
1701        { print!("{:02X} ", c); }
1702    println!();
1703    let mut txt = String::new();
1704    for c in cipher.clone()
1705        { write!(txt, "{:02X} ", c); }
1706    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1707    println!();
1708
1709    // Normal case for the message shorter than 8 bytes
1710    let key = 0x_1234567890ABCDEF_u64;
1711    println!("K =\t{:#016X}", key);
1712    let mut a_des = DES::new_with_key_u64(key);
1713
1714    let message = "7 bytes";
1715    println!("M =\t{}", message);
1716    let message = unsafe { message.to_string().as_mut_vec().clone() };
1717    let mut cipher = [0_u8; 8];
1718    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1719    print!("C =\t");
1720    for c in cipher.clone()
1721        { print!("{:02X} ", c); }
1722    println!();
1723    let mut txt = String::new();
1724    for c in cipher.clone()
1725        { write!(txt, "{:02X} ", c); }
1726    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1727    println!();
1728
1729    // Normal case for the message of 8 bytes
1730    let key = 0x_1234567890ABCDEF_u64;
1731    println!("K =\t{:#016X}", key);
1732    let mut a_des = DES::new_with_key_u64(key);
1733
1734    let message = "I am OK.";
1735    println!("M =\t{}", message);
1736    let message = unsafe { message.to_string().as_mut_vec().clone() };
1737    let mut cipher = [0_u8; 16];
1738    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1739    print!("C =\t");
1740    for c in cipher.clone()
1741        { print!("{:02X} ", c); }
1742    println!();
1743    let mut txt = String::new();
1744    for c in cipher.clone()
1745        { write!(txt, "{:02X} ", c); }
1746    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1747    println!();
1748
1749    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1750    let key = 0x_1234567890ABCDEF_u64;
1751    println!("K =\t{:#016X}", key);
1752    let mut a_des = DES::new_with_key_u64(key);
1753
1754    let message = "PARK Youngho";
1755    println!("M =\t{}", message);
1756    let message = unsafe { message.to_string().as_mut_vec().clone() };
1757    let mut cipher = [0_u8; 16];
1758    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1759    print!("C =\t");
1760    for c in cipher.clone()
1761        { print!("{:02X} ", c); }
1762    println!();
1763    let mut txt = String::new();
1764    for c in cipher.clone()
1765        { write!(txt, "{:02X} ", c); }
1766    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1767    println!();
1768
1769
1770    // Normal case for the message of 16 bytes
1771    let key = 0x_1234567890ABCDEF_u64;
1772    println!("K =\t{:#016X}", key);
1773    let mut a_des = DES::new_with_key_u64(key);
1774
1775    let message = "고맙습니다.";
1776    println!("M =\t{}", message);
1777    let message = unsafe { message.to_string().as_mut_vec().clone() };
1778    let mut cipher = [0_u8; 24];
1779    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1780    print!("C =\t");
1781    for c in cipher.clone()
1782        { print!("{:02X} ", c); }
1783    println!();
1784    let mut txt = String::new();
1785    for c in cipher.clone()
1786        { write!(txt, "{:02X} ", c); }
1787    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1788    println!("-------------------------------");
1789}
1790
1791fn des_encrypt_vec_with_padding_iso_ecb_into_vec()
1792{
1793    println!("des_encrypt_vec_with_padding_iso_ecb_into_vec()");
1794    use std::io::Write;
1795    use std::fmt::Write as _;
1796    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1797
1798    // Normal case
1799    let key = 0x_1234567890ABCDEF_u64;
1800    println!("K =\t{:#016X}", key);
1801    let mut a_des = DES::new_with_key_u64(key);
1802
1803    let message = "In the beginning God created the heavens and the earth.";
1804    println!("M =\t{}", message);
1805    let message = unsafe { message.to_string().as_mut_vec().clone() };
1806    let mut cipher = Vec::<u8>::new();
1807    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1808    print!("C (16 rounds) =\t");
1809    for c in cipher.clone()
1810        { print!("{:02X} ", c); }
1811    println!();
1812    let mut txt = String::new();
1813    for c in cipher.clone()
1814        { write!(txt, "{:02X} ", c); }
1815    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1816    println!();
1817
1818    // Expanded case for 128 rounds
1819    let key = 0x_1234567890ABCDEF_u64;
1820    println!("K =\t{:#016X}", key);
1821    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1822
1823    let message = "In the beginning God created the heavens and the earth.";
1824    println!("M =\t{}", message);
1825    let message = unsafe { message.to_string().as_mut_vec().clone() };
1826    let mut cipher = Vec::<u8>::new();
1827    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1828    print!("C (128 rounds) =\t");
1829    for c in cipher.clone()
1830        { print!("{:02X} ", c); }
1831    println!();
1832    let mut txt = String::new();
1833    for c in cipher.clone()
1834        { write!(txt, "{:02X} ", c); }
1835    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1836    println!();
1837
1838    // Expanded case for 0 rounds which means that key is meaningless
1839    let key1 = 0x_1234567890ABCDEF_u64;
1840    let key2 = 0_u64;
1841    println!("K1 =\t{:#016X}", key1);
1842    println!("K2 =\t{:#016X}", key2);
1843    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1844    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1845
1846    let message = "In the beginning God created the heavens and the earth.";
1847    println!("M =\t{}", message);
1848    let message = unsafe { message.to_string().as_mut_vec().clone() };
1849
1850    let mut cipher1 = Vec::<u8>::new();
1851    let mut cipher2 = Vec::<u8>::new();
1852    c_des.encrypt_vec_into_vec(&message, &mut cipher1);
1853    d_des.encrypt_vec_into_vec(&message, &mut cipher2);
1854    print!("C (0 rounds) =\t");
1855    for c in cipher1.clone()
1856        { print!("{:02X} ", c); }
1857    println!();
1858    let mut txt = String::new();
1859    for c in cipher1.clone()
1860        { write!(txt, "{:02X} ", c); }
1861    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1862    print!("D (0 rounds) =\t");
1863    for c in cipher2.clone()
1864        { print!("{:02X} ", c); }
1865    println!();
1866    let mut txt = String::new();
1867    for c in cipher2.clone()
1868        { write!(txt, "{:02X} ", c); }
1869    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1870    println!();
1871
1872    // Normal case for the message of 0 bytes
1873    let key = 0x_1234567890ABCDEF_u64;
1874    println!("K =\t{:#016X}", key);
1875    let mut a_des = DES::new_with_key_u64(key);
1876
1877    let message = "";
1878    println!("M =\t{}", message);
1879    let message = unsafe { message.to_string().as_mut_vec().clone() };
1880    let mut cipher = Vec::<u8>::new();
1881    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1882    print!("C =\t");
1883    for c in cipher.clone()
1884        { print!("{:02X} ", c); }
1885    println!();
1886    let mut txt = String::new();
1887    for c in cipher.clone()
1888        { write!(txt, "{:02X} ", c); }
1889    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1890    println!();
1891
1892    // Normal case for the message shorter than 8 bytes
1893    let key = 0x_1234567890ABCDEF_u64;
1894    println!("K =\t{:#016X}", key);
1895    let mut a_des = DES::new_with_key_u64(key);
1896
1897    let message = "7 bytes";
1898    println!("M =\t{}", message);
1899    let message = unsafe { message.to_string().as_mut_vec().clone() };
1900    let mut cipher = Vec::<u8>::new();
1901    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1902    print!("C =\t");
1903    for c in cipher.clone()
1904        { print!("{:02X} ", c); }
1905    println!();
1906    let mut txt = String::new();
1907    for c in cipher.clone()
1908        { write!(txt, "{:02X} ", c); }
1909    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1910    println!();
1911
1912    // Normal case for the message of 8 bytes
1913    let key = 0x_1234567890ABCDEF_u64;
1914    println!("K =\t{:#016X}", key);
1915    let mut a_des = DES::new_with_key_u64(key);
1916
1917    let message = "I am OK.";
1918    println!("M =\t{}", message);
1919    let message = unsafe { message.to_string().as_mut_vec().clone() };
1920    let mut cipher = Vec::<u8>::new();
1921    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1922    print!("C =\t");
1923    for c in cipher.clone()
1924        { print!("{:02X} ", c); }
1925    println!();
1926    let mut txt = String::new();
1927    for c in cipher.clone()
1928        { write!(txt, "{:02X} ", c); }
1929    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1930    println!();
1931
1932    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1933    let key = 0x_1234567890ABCDEF_u64;
1934    println!("K =\t{:#016X}", key);
1935    let mut a_des = DES::new_with_key_u64(key);
1936
1937    let message = "PARK Youngho";
1938    println!("M =\t{}", message);
1939    let message = unsafe { message.to_string().as_mut_vec().clone() };
1940    let mut cipher = Vec::<u8>::new();
1941    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1942    print!("C =\t");
1943    for c in cipher.clone()
1944        { print!("{:02X} ", c); }
1945    println!();
1946    let mut txt = String::new();
1947    for c in cipher.clone()
1948        { write!(txt, "{:02X} ", c); }
1949    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1950    println!();
1951
1952
1953    // Normal case for the message of 16 bytes
1954    let key = 0x_1234567890ABCDEF_u64;
1955    println!("K =\t{:#016X}", key);
1956    let mut a_des = DES::new_with_key_u64(key);
1957
1958    let message = "고맙습니다.";
1959    println!("M =\t{}", message);
1960    let message = unsafe { message.to_string().as_mut_vec().clone() };
1961    let mut cipher = Vec::<u8>::new();
1962    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1963    print!("C =\t");
1964    for c in cipher.clone()
1965        { print!("{:02X} ", c); }
1966    println!();
1967    let mut txt = String::new();
1968    for c in cipher.clone()
1969        { write!(txt, "{:02X} ", c); }
1970    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1971    println!("-------------------------------");
1972}
1973
1974fn des_encrypt_vec_with_padding_iso_ecb_into_array()
1975{
1976    println!("des_encrypt_vec_with_padding_iso_ecb_into_array()");
1977    use std::io::Write;
1978    use std::fmt::Write as _;
1979    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1980
1981    // Normal case
1982    let key = 0x_1234567890ABCDEF_u64;
1983    println!("K =\t{:#016X}", key);
1984    let mut a_des = DES::new_with_key_u64(key);
1985
1986    let message = "In the beginning God created the heavens and the earth.";
1987    println!("M =\t{}", message);
1988    let message = unsafe { message.to_string().as_mut_vec().clone() };
1989    let mut cipher = [0_u8; 56];
1990    a_des.encrypt_vec_into_array(&message, &mut cipher);
1991    print!("C (16 rounds) =\t");
1992    for c in cipher.clone()
1993        { print!("{:02X} ", c); }
1994    println!();
1995    let mut txt = String::new();
1996    for c in cipher.clone()
1997        { write!(txt, "{:02X} ", c); }
1998    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1999    println!();
2000
2001    // Expanded case for 128 rounds
2002    let key = 0x_1234567890ABCDEF_u64;
2003    println!("K =\t{:#016X}", key);
2004    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2005
2006    let message = "In the beginning God created the heavens and the earth.";
2007    println!("M =\t{}", message);
2008    let message = unsafe { message.to_string().as_mut_vec().clone() };
2009    let mut cipher = [0_u8; 56];
2010    a_des.encrypt_vec_into_array(&message, &mut cipher);
2011    print!("C (128 rounds) =\t");
2012    for c in cipher.clone()
2013        { print!("{:02X} ", c); }
2014    println!();
2015    let mut txt = String::new();
2016    for c in cipher.clone()
2017        { write!(txt, "{:02X} ", c); }
2018    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2019    println!();
2020
2021    // Expanded case for 0 rounds which means that key is meaningless
2022    let key1 = 0x_1234567890ABCDEF_u64;
2023    let key2 = 0_u64;
2024    println!("K1 =\t{:#016X}", key1);
2025    println!("K2 =\t{:#016X}", key2);
2026    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2027    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2028
2029    let message = "In the beginning God created the heavens and the earth.";
2030    println!("M =\t{}", message);
2031    let message = unsafe { message.to_string().as_mut_vec().clone() };
2032    let mut cipher1 = [0_u8; 56];
2033    let mut cipher2 = [0_u8; 56];
2034    c_des.encrypt_vec_into_array(&message, &mut cipher1);
2035    d_des.encrypt_vec_into_array(&message, &mut cipher2);
2036    print!("C (0 rounds) =\t");
2037    for c in cipher1.clone()
2038        { print!("{:02X} ", c); }
2039    println!();
2040    let mut txt = String::new();
2041    for c in cipher1.clone()
2042        { write!(txt, "{:02X} ", c); }
2043    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2044    print!("D (0 rounds) =\t");
2045    for c in cipher2.clone()
2046        { print!("{:02X} ", c); }
2047    println!();
2048    let mut txt = String::new();
2049    for c in cipher2.clone()
2050        { write!(txt, "{:02X} ", c); }
2051    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2052    println!();
2053
2054    // Normal case for the message of 0 bytes
2055    let key = 0x_1234567890ABCDEF_u64;
2056    println!("K =\t{:#016X}", key);
2057    let mut a_des = DES::new_with_key_u64(key);
2058
2059    let message = "";
2060    println!("M =\t{}", message);
2061    let message = unsafe { message.to_string().as_mut_vec().clone() };
2062    let mut cipher = [0_u8; 8];
2063    a_des.encrypt_vec_into_array(&message, &mut cipher);
2064    print!("C =\t");
2065    for c in cipher.clone()
2066        { print!("{:02X} ", c); }
2067    println!();
2068    let mut txt = String::new();
2069    for c in cipher.clone()
2070        { write!(txt, "{:02X} ", c); }
2071    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2072    println!();
2073
2074    // Normal case for the message shorter than 8 bytes
2075    let key = 0x_1234567890ABCDEF_u64;
2076    println!("K =\t{:#016X}", key);
2077    let mut a_des = DES::new_with_key_u64(key);
2078
2079    let message = "7 bytes";
2080    println!("M =\t{}", message);
2081    let message = unsafe { message.to_string().as_mut_vec().clone() };
2082    let mut cipher = [0_u8; 8];
2083    a_des.encrypt_vec_into_array(&message, &mut cipher);
2084    print!("C =\t");
2085    for c in cipher.clone()
2086        { print!("{:02X} ", c); }
2087    println!();
2088    let mut txt = String::new();
2089    for c in cipher.clone()
2090        { write!(txt, "{:02X} ", c); }
2091    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2092    println!();
2093
2094    // Normal case for the message of 8 bytes
2095    let key = 0x_1234567890ABCDEF_u64;
2096    println!("K =\t{:#016X}", key);
2097    let mut a_des = DES::new_with_key_u64(key);
2098
2099    let message = "I am OK.";
2100    println!("M =\t{}", message);
2101    let message = unsafe { message.to_string().as_mut_vec().clone() };
2102    let mut cipher = [0_u8; 16];
2103    a_des.encrypt_vec_into_array(&message, &mut cipher);
2104    print!("C =\t");
2105    for c in cipher.clone()
2106        { print!("{:02X} ", c); }
2107    println!();
2108    let mut txt = String::new();
2109    for c in cipher.clone()
2110        { write!(txt, "{:02X} ", c); }
2111    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2112    println!();
2113
2114    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2115    let key = 0x_1234567890ABCDEF_u64;
2116    println!("K =\t{:#016X}", key);
2117    let mut a_des = DES::new_with_key_u64(key);
2118
2119    let message = "PARK Youngho";
2120    println!("M =\t{}", message);
2121    let message = unsafe { message.to_string().as_mut_vec().clone() };
2122    let mut cipher = [0_u8; 16];
2123    a_des.encrypt_vec_into_array(&message, &mut cipher);
2124    print!("C =\t");
2125    for c in cipher.clone()
2126        { print!("{:02X} ", c); }
2127    println!();
2128    let mut txt = String::new();
2129    for c in cipher.clone()
2130        { write!(txt, "{:02X} ", c); }
2131    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2132    println!();
2133
2134
2135    // Normal case for the message of 16 bytes
2136    let key = 0x_1234567890ABCDEF_u64;
2137    println!("K =\t{:#016X}", key);
2138    let mut a_des = DES::new_with_key_u64(key);
2139 
2140    let message = "고맙습니다.";
2141    println!("M =\t{}", message);
2142    let message = unsafe { message.to_string().as_mut_vec().clone() };
2143    let mut cipher = [0_u8; 24];
2144    a_des.encrypt_vec_into_array(&message, &mut cipher);
2145    print!("C =\t");
2146    for c in cipher.clone()
2147        { print!("{:02X} ", c); }
2148    println!();
2149    let mut txt = String::new();
2150    for c in cipher.clone()
2151        { write!(txt, "{:02X} ", c); }
2152    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2153    println!("-------------------------------");
2154}
2155
2156fn des_encrypt_array_with_padding_iso_ecb()
2157{
2158    println!("des_encrypt_array_with_padding_iso_ecb()");
2159    use std::io::Write;
2160    use std::fmt::Write as _;
2161    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2162
2163    // Normal case
2164    let key = 0x_1234567890ABCDEF_u64;
2165    println!("K =\t{:#016X}", key);
2166    let mut a_des = DES::new_with_key_u64(key);
2167
2168    let mes = "In the beginning God created the heavens and the earth.";
2169    println!("M =\t{}", mes);
2170    let mut message = [0_u8; 55];
2171    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2172    let mut cipher = [0_u8; 56];
2173    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2174    print!("C (16 rounds) =\t");
2175    for c in cipher.clone()
2176        { print!("{:02X} ", c); }
2177    println!();
2178    let mut txt = String::new();
2179    for c in cipher.clone()
2180        { write!(txt, "{:02X} ", c); }
2181    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2182    println!();
2183
2184    // Expanded case for 128 rounds
2185    let key = 0x_1234567890ABCDEF_u64;
2186    println!("K =\t{:#016X}", key);
2187    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2188
2189    let mes = "In the beginning God created the heavens and the earth.";
2190    println!("M =\t{}", mes);
2191    let mut message = [0_u8; 55];
2192    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2193    let mut cipher = [0_u8; 56];
2194    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2195    print!("C (128 rounds) =\t");
2196    for c in cipher.clone()
2197        { print!("{:02X} ", c); }
2198    println!();
2199    let mut txt = String::new();
2200    for c in cipher.clone()
2201        { write!(txt, "{:02X} ", c); }
2202    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2203    println!();
2204
2205    // Expanded case for 0 rounds which means that key is meaningless
2206    let key1 = 0x_1234567890ABCDEF_u64;
2207    let key2 = 0_u64;
2208    println!("K1 =\t{:#016X}", key1);
2209    println!("K2 =\t{:#016X}", key2);
2210    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2211    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2212
2213    let mes = "In the beginning God created the heavens and the earth.";
2214    println!("M =\t{}", mes);
2215    let mut message = [0_u8; 55];
2216    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2217    let mut cipher1 = [0_u8; 56];
2218    let mut cipher2 = [0_u8; 56];
2219    c_des.encrypt_array(&message, cipher1.as_mut_ptr());
2220    d_des.encrypt_array(&message, cipher2.as_mut_ptr());
2221    print!("C (0 rounds) =\t");
2222    for c in cipher1.clone()
2223        { print!("{:02X} ", c); }
2224    println!();
2225    let mut txt = String::new();
2226    for c in cipher1.clone()
2227        { write!(txt, "{:02X} ", c); }
2228    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2229    print!("D (0 rounds) =\t");
2230    for c in cipher2.clone()
2231        { print!("{:02X} ", c); }
2232    println!();
2233    let mut txt = String::new();
2234    for c in cipher2.clone()
2235        { write!(txt, "{:02X} ", c); }
2236    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2237    println!();
2238
2239    // Normal case for the message of 0 bytes
2240    let key = 0x_1234567890ABCDEF_u64;
2241    println!("K =\t{:#016X}", key);
2242    let mut a_des = DES::new_with_key_u64(key);
2243
2244    let mes = "";
2245    println!("M =\t{}", mes);
2246    let mut message = [0_u8; 0];
2247    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2248    let mut cipher = [0_u8; 8];
2249    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2250    print!("C =\t");
2251    for c in cipher.clone()
2252        { print!("{:02X} ", c); }
2253    println!();
2254    let mut txt = String::new();
2255    for c in cipher.clone()
2256        { write!(txt, "{:02X} ", c); }
2257    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2258    println!();
2259
2260    // Normal case for the message shorter than 8 bytes
2261    let key = 0x_1234567890ABCDEF_u64;
2262    println!("K =\t{:#016X}", key);
2263    let mut a_des = DES::new_with_key_u64(key);
2264
2265    let mes = "7 bytes";
2266    println!("M =\t{}", mes);
2267    let mut message = [0_u8; 7];
2268    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2269    let mut cipher = [0_u8; 8];
2270    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2271    print!("C =\t");
2272    for c in cipher.clone()
2273        { print!("{:02X} ", c); }
2274    println!();
2275    let mut txt = String::new();
2276    for c in cipher.clone()
2277        { write!(txt, "{:02X} ", c); }
2278    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2279    println!();
2280
2281    // Normal case for the message of 8 bytes
2282    let key = 0x_1234567890ABCDEF_u64;
2283    println!("K =\t{:#016X}", key);
2284    let mut a_des = DES::new_with_key_u64(key);
2285
2286    let mes = "I am OK.";
2287    println!("M =\t{}", mes);
2288    let mut message = [0_u8; 8];
2289    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2290    let mut cipher = [0_u8; 16];
2291    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2292    print!("C =\t");
2293    for c in cipher.clone()
2294        { print!("{:02X} ", c); }
2295    println!();
2296    let mut txt = String::new();
2297    for c in cipher.clone()
2298        { write!(txt, "{:02X} ", c); }
2299    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2300    println!();
2301
2302    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2303    let key = 0x_1234567890ABCDEF_u64;
2304    println!("K =\t{:#016X}", key);
2305    let mut a_des = DES::new_with_key_u64(key);
2306
2307    let mes = "PARK Youngho";
2308    println!("M =\t{}", mes);
2309    let mut message = [0_u8; 12];
2310    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2311    let mut cipher = [0_u8; 16];
2312    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2313    print!("C =\t");
2314    for c in cipher.clone()
2315        { print!("{:02X} ", c); }
2316    println!();
2317    let mut txt = String::new();
2318    for c in cipher.clone()
2319        { write!(txt, "{:02X} ", c); }
2320    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2321    println!();
2322
2323
2324    // Normal case for the message of 16 bytes
2325    let key = 0x_1234567890ABCDEF_u64;
2326    println!("K =\t{:#016X}", key);
2327    let mut a_des = DES::new_with_key_u64(key);
2328
2329    let mes = "고맙습니다.";
2330    println!("M =\t{}", mes);
2331    let mut message = [0_u8; 16];
2332    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2333    let mut cipher = [0_u8; 24];
2334    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2335    print!("C =\t");
2336    for c in cipher.clone()
2337        { print!("{:02X} ", c); }
2338    println!();
2339    let mut txt = String::new();
2340    for c in cipher.clone()
2341        { write!(txt, "{:02X} ", c); }
2342    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2343    println!("-------------------------------");
2344}
2345
2346fn des_encrypt_array_with_padding_iso_ecb_into_vec()
2347{
2348    println!("des_encrypt_array_with_padding_iso_ecb_into_vec()");
2349    use std::io::Write;
2350    use std::fmt::Write as _;
2351    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2352
2353    // Normal case
2354    let key = 0x_1234567890ABCDEF_u64;
2355    println!("K =\t{:#016X}", key);
2356    let mut a_des = DES::new_with_key_u64(key);
2357
2358    let mes = "In the beginning God created the heavens and the earth.";
2359    println!("M =\t{}", mes);
2360    let mut message = [0_u8; 55];
2361    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2362    let mut cipher = Vec::<u8>::new();
2363    a_des.encrypt_array_into_vec(&message, &mut cipher);
2364    print!("C (16 rounds) =\t");
2365    for c in cipher.clone()
2366        { print!("{:02X} ", c); }
2367    println!();
2368    let mut txt = String::new();
2369    for c in cipher.clone()
2370        { write!(txt, "{:02X} ", c); }
2371    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2372    println!();
2373
2374    // Expanded case for 128 rounds
2375    let key = 0x_1234567890ABCDEF_u64;
2376    println!("K =\t{:#016X}", key);
2377    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2378
2379    let mes = "In the beginning God created the heavens and the earth.";
2380    println!("M =\t{}", mes);
2381    let mut message = [0_u8; 55];
2382    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2383    let mut cipher = Vec::<u8>::new();
2384    a_des.encrypt_array_into_vec(&message, &mut cipher);
2385    print!("C (128 rounds) =\t");
2386    for c in cipher.clone()
2387        { print!("{:02X} ", c); }
2388    println!();
2389    let mut txt = String::new();
2390    for c in cipher.clone()
2391        { write!(txt, "{:02X} ", c); }
2392    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2393    println!();
2394
2395    // Expanded case for 0 rounds which means that key is meaningless
2396    let key1 = 0x_1234567890ABCDEF_u64;
2397    let key2 = 0_u64;
2398    println!("K1 =\t{:#016X}", key1);
2399    println!("K2 =\t{:#016X}", key2);
2400    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2401    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2402
2403    let mes = "In the beginning God created the heavens and the earth.";
2404    println!("M =\t{}", mes);
2405    let mut message = [0_u8; 55];
2406    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2407
2408    let mut cipher1 = Vec::<u8>::new();
2409    let mut cipher2 = Vec::<u8>::new();
2410    c_des.encrypt_array_into_vec(&message, &mut cipher1);
2411    d_des.encrypt_array_into_vec(&message, &mut cipher2);
2412    print!("C (0 rounds) =\t");
2413    for c in cipher1.clone()
2414        { print!("{:02X} ", c); }
2415    println!();
2416    let mut txt = String::new();
2417    for c in cipher1.clone()
2418        { write!(txt, "{:02X} ", c); }
2419    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2420    print!("D (0 rounds) =\t");
2421    for c in cipher2.clone()
2422        { print!("{:02X} ", c); }
2423    println!();
2424    let mut txt = String::new();
2425    for c in cipher2.clone()
2426        { write!(txt, "{:02X} ", c); }
2427    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2428    println!();
2429
2430    // Normal case for the message of 0 bytes
2431    let key = 0x_1234567890ABCDEF_u64;
2432    println!("K =\t{:#016X}", key);
2433    let mut a_des = DES::new_with_key_u64(key);
2434
2435    let mes = "";
2436    println!("M =\t{}", mes);
2437    let mut message = [0_u8; 0];
2438    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2439    let mut cipher = Vec::<u8>::new();
2440    a_des.encrypt_array_into_vec(&message, &mut cipher);
2441    print!("C =\t");
2442    for c in cipher.clone()
2443        { print!("{:02X} ", c); }
2444    println!();
2445    let mut txt = String::new();
2446    for c in cipher.clone()
2447        { write!(txt, "{:02X} ", c); }
2448    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2449    println!();
2450
2451    // Normal case for the message shorter than 8 bytes
2452    let key = 0x_1234567890ABCDEF_u64;
2453    println!("K =\t{:#016X}", key);
2454    let mut a_des = DES::new_with_key_u64(key);
2455
2456    let mes = "7 bytes";
2457    println!("M =\t{}", mes);
2458    let mut message = [0_u8; 7];
2459    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460    let mut cipher = Vec::<u8>::new();
2461    a_des.encrypt_array_into_vec(&message, &mut cipher);
2462    print!("C =\t");
2463    for c in cipher.clone()
2464        { print!("{:02X} ", c); }
2465    println!();
2466    let mut txt = String::new();
2467    for c in cipher.clone()
2468        { write!(txt, "{:02X} ", c); }
2469    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2470    println!();
2471
2472    // Normal case for the message of 8 bytes
2473    let key = 0x_1234567890ABCDEF_u64;
2474    println!("K =\t{:#016X}", key);
2475    let mut a_des = DES::new_with_key_u64(key);
2476
2477    let mes = "I am OK.";
2478    println!("M =\t{}", mes);
2479    let mut message = [0_u8; 8];
2480    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2481    let mut cipher = Vec::<u8>::new();
2482    a_des.encrypt_array_into_vec(&message, &mut cipher);
2483    print!("C =\t");
2484    for c in cipher.clone()
2485        { print!("{:02X} ", c); }
2486    println!();
2487    let mut txt = String::new();
2488    for c in cipher.clone()
2489        { write!(txt, "{:02X} ", c); }
2490    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2491    println!();
2492
2493    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2494    let key = 0x_1234567890ABCDEF_u64;
2495    println!("K =\t{:#016X}", key);
2496    let mut a_des = DES::new_with_key_u64(key);
2497
2498    let mes = "PARK Youngho";
2499    println!("M =\t{}", mes);
2500    let mut message = [0_u8; 12];
2501    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2502    let mut cipher = Vec::<u8>::new();
2503    a_des.encrypt_array_into_vec(&message, &mut cipher);
2504    print!("C =\t");
2505    for c in cipher.clone()
2506        { print!("{:02X} ", c); }
2507    println!();
2508    let mut txt = String::new();
2509    for c in cipher.clone()
2510        { write!(txt, "{:02X} ", c); }
2511    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2512    println!();
2513
2514
2515    // Normal case for the message of 16 bytes
2516    let key = 0x_1234567890ABCDEF_u64;
2517    println!("K =\t{:#016X}", key);
2518    let mut a_des = DES::new_with_key_u64(key);
2519
2520    let mes = "고맙습니다.";
2521    println!("M =\t{}", mes);
2522    let mut message = [0_u8; 16];
2523    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2524    let mut cipher = Vec::<u8>::new();
2525    a_des.encrypt_array_into_vec(&message, &mut cipher);
2526    print!("C =\t");
2527    for c in cipher.clone()
2528        { print!("{:02X} ", c); }
2529    println!();
2530    let mut txt = String::new();
2531    for c in cipher.clone()
2532        { write!(txt, "{:02X} ", c); }
2533    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2534    println!("-------------------------------");
2535}
2536
2537fn des_encrypt_array_with_padding_iso_ecb_into_array()
2538{
2539    println!("des_encrypt_array_with_padding_iso_ecb_into_array()");
2540    use std::io::Write;
2541    use std::fmt::Write as _;
2542    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2543
2544    // Normal case
2545    let key = 0x_1234567890ABCDEF_u64;
2546    println!("K =\t{:#016X}", key);
2547    let mut a_des = DES::new_with_key_u64(key);
2548
2549    let mes = "In the beginning God created the heavens and the earth.";
2550    println!("M =\t{}", mes);
2551    let mut message = [0_u8; 55];
2552    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2553    let mut cipher = [0_u8; 56];
2554    a_des.encrypt_array_into_array(&message, &mut cipher);
2555    for c in cipher.clone()
2556        { print!("{:02X} ", c); }
2557    println!();
2558    let mut txt = String::new();
2559    for c in cipher.clone()
2560        { write!(txt, "{:02X} ", c); }
2561    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2562    println!();
2563
2564    // Expanded case for 128 rounds
2565    let key = 0x_1234567890ABCDEF_u64;
2566    println!("K =\t{:#016X}", key);
2567    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2568
2569    let mes = "In the beginning God created the heavens and the earth.";
2570    println!("M =\t{}", mes);
2571    let mut message = [0_u8; 55];
2572    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2573    let mut cipher = [0_u8; 56];
2574    a_des.encrypt_array_into_array(&message, &mut cipher);
2575    print!("C (128 rounds) =\t");
2576    for c in cipher.clone()
2577        { print!("{:02X} ", c); }
2578    println!();
2579    let mut txt = String::new();
2580    for c in cipher.clone()
2581        { write!(txt, "{:02X} ", c); }
2582    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2583    println!();
2584
2585    // Expanded case for 0 rounds which means that key is meaningless
2586    let key1 = 0x_1234567890ABCDEF_u64;
2587    let key2 = 0_u64;
2588    println!("K1 =\t{:#016X}", key1);
2589    println!("K2 =\t{:#016X}", key2);
2590    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2591    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2592
2593    let mes = "In the beginning God created the heavens and the earth.";
2594    println!("M =\t{}", mes);
2595    let mut message = [0_u8; 55];
2596    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2597    let mut cipher1 = [0_u8; 56];
2598    let mut cipher2 = [0_u8; 56];
2599    c_des.encrypt_array_into_array(&message, &mut cipher1);
2600    d_des.encrypt_array_into_array(&message, &mut cipher2);
2601    print!("C (0 rounds) =\t");
2602    for c in cipher1.clone()
2603        { print!("{:02X} ", c); }
2604    println!();
2605    let mut txt = String::new();
2606    for c in cipher1.clone()
2607        { write!(txt, "{:02X} ", c); }
2608    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2609    print!("D (0 rounds) =\t");
2610    for c in cipher2.clone()
2611        { print!("{:02X} ", c); }
2612    println!();
2613    let mut txt = String::new();
2614    for c in cipher2.clone()
2615        { write!(txt, "{:02X} ", c); }
2616    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2617    println!();
2618
2619    // Normal case for the message of 0 bytes
2620    let key = 0x_1234567890ABCDEF_u64;
2621    println!("K =\t{:#016X}", key);
2622    let mut a_des = DES::new_with_key_u64(key);
2623
2624    let mes = "";
2625    println!("M =\t{}", mes);
2626    let mut message = [0_u8; 0];
2627    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2628    let mut cipher = [0_u8; 8];
2629    a_des.encrypt_array_into_array(&message, &mut cipher);
2630    print!("C =\t");
2631    for c in cipher.clone()
2632        { print!("{:02X} ", c); }
2633    println!();
2634    let mut txt = String::new();
2635    for c in cipher.clone()
2636        { write!(txt, "{:02X} ", c); }
2637    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2638    println!();
2639
2640    // Normal case for the message shorter than 8 bytes
2641    let key = 0x_1234567890ABCDEF_u64;
2642    println!("K =\t{:#016X}", key);
2643    let mut a_des = DES::new_with_key_u64(key);
2644
2645    let mes = "7 bytes";
2646    println!("M =\t{}", mes);
2647    let mut message = [0_u8; 7];
2648    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2649    let mut cipher = [0_u8; 8];
2650    a_des.encrypt_array_into_array(&message, &mut cipher);
2651    print!("C =\t");
2652    for c in cipher.clone()
2653        { print!("{:02X} ", c); }
2654    println!();
2655    let mut txt = String::new();
2656    for c in cipher.clone()
2657        { write!(txt, "{:02X} ", c); }
2658    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2659    println!();
2660
2661    // Normal case for the message of 8 bytes
2662    let key = 0x_1234567890ABCDEF_u64;
2663    println!("K =\t{:#016X}", key);
2664    let mut a_des = DES::new_with_key_u64(key);
2665
2666    let mes = "I am OK.";
2667    println!("M =\t{}", mes);
2668    let mut message = [0_u8; 8];
2669    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2670    let mut cipher = [0_u8; 16];
2671    a_des.encrypt_array_into_array(&message, &mut cipher);
2672    print!("C =\t");
2673    for c in cipher.clone()
2674        { print!("{:02X} ", c); }
2675    println!();
2676    let mut txt = String::new();
2677    for c in cipher.clone()
2678        { write!(txt, "{:02X} ", c); }
2679    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2680    println!();
2681
2682    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2683    let key = 0x_1234567890ABCDEF_u64;
2684    println!("K =\t{:#016X}", key);
2685    let mut a_des = DES::new_with_key_u64(key);
2686
2687    let mes = "PARK Youngho";
2688    println!("M =\t{}", mes);
2689    let mut message = [0_u8; 12];
2690    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2691    let mut cipher = [0_u8; 16];
2692    a_des.encrypt_array_into_array(&message, &mut cipher);
2693    print!("C =\t");
2694    for c in cipher.clone()
2695        { print!("{:02X} ", c); }
2696    println!();
2697    let mut txt = String::new();
2698    for c in cipher.clone()
2699        { write!(txt, "{:02X} ", c); }
2700    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2701    println!();
2702
2703
2704    // Normal case for the message of 16 bytes
2705    let key = 0x_1234567890ABCDEF_u64;
2706    println!("K =\t{:#016X}", key);
2707    let mut a_des = DES::new_with_key_u64(key);
2708 
2709    let mes = "고맙습니다.";
2710    println!("M =\t{}", mes);
2711    let mut message = [0_u8; 16];
2712    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2713    let mut cipher = [0_u8; 24];
2714    a_des.encrypt_array_into_array(&message, &mut cipher);
2715    print!("C =\t");
2716    for c in cipher.clone()
2717        { print!("{:02X} ", c); }
2718    println!();
2719    let mut txt = String::new();
2720    for c in cipher.clone()
2721        { write!(txt, "{:02X} ", c); }
2722    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2723    println!("-------------------------------");
2724}
2725
2726fn des_decrypt_with_padding_iso_ecb()
2727{
2728    println!("des_decrypt_with_padding_iso_ecb()");
2729    use std::io::Write;
2730    use std::fmt::Write as _;
2731    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2732
2733    // Normal case
2734    let key = 0x_1234567890ABCDEF_u64;
2735    println!("K =\t{:#016X}", key);
2736    let mut a_des = DES::new_with_key_u64(key);
2737
2738    let message = "In the beginning God created the heavens and the earth.";
2739    println!("M =\t{}", message);
2740    let mut cipher = Vec::<u8>::new();
2741    a_des.encrypt_str_into_vec(&message, &mut cipher);
2742    print!("C (16 rounds) =\t");
2743    for c in cipher.clone()
2744        { print!("{:02X} ", c); }
2745    println!();
2746    let mut txt = String::new();
2747    for c in cipher.clone()
2748        { write!(txt, "{:02X} ", c); }
2749    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2750
2751    let mut recovered = vec![0; 55];
2752    a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2753    print!("Ba (16 rounds) =\t");
2754    for b in recovered.clone()
2755        { print!("{:02X} ", b); }
2756    println!();
2757    let mut txt = String::new();
2758    for c in recovered.clone()
2759        { write!(txt, "{:02X} ", c); }
2760    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2761
2762    let mut converted = String::new();
2763    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2764    
2765    println!("Bb (16 rounds) =\t{}", converted);
2766    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2767    assert_eq!(converted, message);
2768    println!();
2769
2770    // Expanded case for 128 rounds
2771    let key = 0x_1234567890ABCDEF_u64;
2772    println!("K =\t{:#016X}", key);
2773    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2774
2775    let message = "In the beginning God created the heavens and the earth.";
2776    println!("M =\t{}", message);
2777    let mut cipher = Vec::<u8>::new();
2778    a_des.encrypt_str_into_vec(&message, &mut cipher);
2779    print!("C (128 rounds) =\t");
2780    for c in cipher.clone()
2781        { print!("{:02X} ", c); }
2782    println!();
2783    let mut txt = String::new();
2784    for c in cipher.clone()
2785        { write!(txt, "{:02X} ", c); }
2786    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2787
2788    let mut recovered = vec![0; 55];
2789    a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2790    print!("Ba (128 rounds) =\t");
2791    for b in recovered.clone()
2792        { print!("{:02X} ", b); }
2793    println!();
2794    let mut txt = String::new();
2795    for c in recovered.clone()
2796        { write!(txt, "{:02X} ", c); }
2797    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2798
2799    let mut converted = String::new();
2800    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2801    
2802    println!("Bb (128 rounds) =\t{}", converted);
2803    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2804    assert_eq!(converted, message);
2805    println!();
2806
2807    // Expanded case for 0 rounds which means that key is meaningless
2808    let key1 = 0x_1234567890ABCDEF_u64;
2809    let key2 = 0_u64;
2810    println!("K =\t{:#016X}", key);
2811    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2812    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2813
2814    let message = "In the beginning God created the heavens and the earth.";
2815    println!("M =\t{}", message);
2816    let mut cipher1 = Vec::<u8>::new();
2817    let mut cipher2 = Vec::<u8>::new();
2818    c_des.encrypt_str_into_vec(&message, &mut cipher1);
2819    d_des.encrypt_str_into_vec(&message, &mut cipher2);
2820    print!("C (0 rounds) =\t");
2821    for c in cipher1.clone()
2822        { print!("{:02X} ", c); }
2823    println!();
2824    let mut txt = String::new();
2825    for c in cipher1.clone()
2826        { write!(txt, "{:02X} ", c); }
2827    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2828    print!("D (0 rounds) =\t");
2829    for c in cipher2.clone()
2830        { print!("{:02X} ", c); }
2831    println!();
2832    let mut txt = String::new();
2833    for c in cipher2.clone()
2834        { write!(txt, "{:02X} ", c); }
2835    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2836
2837    let mut recovered1 = vec![0; 55];
2838    let mut recovered2 = vec![0; 55];
2839    c_des.decrypt(cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
2840    d_des.decrypt(cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
2841    print!("B1a (0 rounds) =\t");
2842    for b in recovered1.clone()
2843        { print!("{:02X} ", b); }
2844    println!();
2845    let mut txt = String::new();
2846    for c in recovered1.clone()
2847        { write!(txt, "{:02X} ", c); }
2848    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2849    print!("B2a (0 rounds) =\t");
2850    for b in recovered2.clone()
2851        { print!("{:02X} ", b); }
2852    println!();
2853    let mut txt = String::new();
2854    for c in recovered2.clone()
2855        { write!(txt, "{:02X} ", c); }
2856    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2857
2858    let mut converted1 = String::new();
2859    let mut converted2 = String::new();
2860    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
2861    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
2862    
2863    println!("B1b (0 rounds) =\t{}", converted1);
2864    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
2865    assert_eq!(converted1, message);
2866    println!("B2b (0 rounds) =\t{}", converted2);
2867    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
2868    assert_eq!(converted2, message);
2869    assert_eq!(converted1, converted1);
2870    println!();
2871
2872    // Normal case for the message of 0 bytes
2873    let key = 0x_1234567890ABCDEF_u64;
2874    println!("K =\t{:#016X}", key);
2875    let mut a_des = DES::new_with_key_u64(key);
2876
2877    let message = "";
2878    println!("M =\t{}", message);
2879    let mut cipher = Vec::<u8>::new();
2880    a_des.encrypt_str_into_vec(&message, &mut cipher);
2881    print!("C =\t");
2882    for c in cipher.clone()
2883        { print!("{:02X} ", c); }
2884    println!();
2885    let mut txt = String::new();
2886    for c in cipher.clone()
2887        { write!(txt, "{:02X} ", c); }
2888    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2889
2890    let mut recovered = vec![0; 8];
2891    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2892    print!("Ba =\t");
2893    for b in recovered.clone()
2894        { print!("{:02X} ", b); }
2895    println!();
2896    let mut txt = String::new();
2897    for c in recovered.clone()
2898        { write!(txt, "{:02X} ", c); }
2899    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2900
2901    let mut converted = String::new();
2902    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2903    converted.truncate(len as usize);
2904    
2905    println!("Bb =\t{}", converted);
2906    assert_eq!(converted, "");
2907    assert_eq!(converted, message);
2908    println!();
2909
2910    // Normal case for the message shorter than 8 bytes
2911    let key = 0x_1234567890ABCDEF_u64;
2912    println!("K =\t{:#016X}", key);
2913    let mut a_des = DES::new_with_key_u64(key);
2914
2915    let message = "7 bytes";
2916    println!("M =\t{}", message);
2917    let mut cipher = Vec::<u8>::new();
2918    a_des.encrypt_str_into_vec(&message, &mut cipher);
2919    print!("C =\t");
2920    for c in cipher.clone()
2921        { print!("{:02X} ", c); }
2922    println!();
2923    let mut txt = String::new();
2924    for c in cipher.clone()
2925        { write!(txt, "{:02X} ", c); }
2926    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2927    
2928    let mut recovered = vec![0; 8];
2929    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2930    print!("Ba =\t");
2931    for b in recovered.clone()
2932        { print!("{:02X} ", b); }
2933    println!();
2934    let mut txt = String::new();
2935    for c in recovered.clone()
2936        { write!(txt, "{:02X} ", c); }
2937    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
2938
2939    let mut converted = String::new();
2940    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2941    converted.truncate(len as usize);
2942
2943    println!("Bb =\t{}", converted);
2944    assert_eq!(converted, "7 bytes");
2945    assert_eq!(converted, message);
2946    println!();
2947
2948    // Normal case for the message of 8 bytes
2949    let key = 0x_1234567890ABCDEF_u64;
2950    println!("K =\t{:#016X}", key);
2951    let mut a_des = DES::new_with_key_u64(key);
2952
2953    let message = "I am OK.";
2954    println!("M =\t{}", message);
2955    let mut cipher = Vec::<u8>::new();
2956    a_des.encrypt_str_into_vec(&message, &mut cipher);
2957    print!("C =\t");
2958    for c in cipher.clone()
2959        { print!("{:02X} ", c); }
2960    println!();
2961    let mut txt = String::new();
2962    for c in cipher.clone()
2963        { write!(txt, "{:02X} ", c); }
2964    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2965    
2966    let mut recovered = vec![0; 16];
2967    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2968    print!("Ba =\t");
2969    for b in recovered.clone()
2970        { print!("{:02X} ", b); }
2971    println!();
2972    let mut txt = String::new();
2973    for c in recovered.clone()
2974        { write!(txt, "{:02X} ", c); }
2975    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
2976
2977    let mut converted = String::new();
2978    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2979    converted.truncate(len as usize);
2980    
2981    println!("Bb =\t{}", converted);
2982    assert_eq!(converted, "I am OK.");
2983    assert_eq!(converted, message);
2984    println!();
2985
2986    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2987    let key = 0x_1234567890ABCDEF_u64;
2988    println!("K =\t{:#016X}", key);
2989    let mut a_des = DES::new_with_key_u64(key);
2990
2991    let message = "PARK Youngho";
2992    println!("M =\t{}", message);
2993    let mut cipher = Vec::<u8>::new();
2994    a_des.encrypt_str_into_vec(&message, &mut cipher);
2995    print!("C =\t");
2996    for c in cipher.clone()
2997        { print!("{:02X} ", c); }
2998    println!();
2999    let mut txt = String::new();
3000    for c in cipher.clone()
3001        { write!(txt, "{:02X} ", c); }
3002    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3003
3004    let mut recovered = vec![0; 16];
3005    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3006    print!("Ba =\t");
3007    for b in recovered.clone()
3008        { print!("{:02X} ", b); }
3009    println!();
3010    let mut txt = String::new();
3011    for c in recovered.clone()
3012        { write!(txt, "{:02X} ", c); }
3013    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3014
3015    let mut converted = String::new();
3016    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3017    converted.truncate(len as usize);
3018    
3019    println!("Bb =\t{}", converted);
3020    assert_eq!(converted, "PARK Youngho");
3021    assert_eq!(converted, message);
3022    println!();
3023
3024
3025    // Normal case for the message of 16 bytes
3026    let key = 0x_1234567890ABCDEF_u64;
3027    println!("K =\t{:#016X}", key);
3028    let mut a_des = DES::new_with_key_u64(key);
3029
3030    let message = "고맙습니다.";
3031    println!("M =\t{}", message);
3032    let mut cipher = Vec::<u8>::new();
3033    a_des.encrypt_str_into_vec(&message, &mut cipher);
3034    print!("C =\t");
3035    for c in cipher.clone()
3036        { print!("{:02X} ", c); }
3037    println!();
3038    let mut txt = String::new();
3039    for c in cipher.clone()
3040        { write!(txt, "{:02X} ", c); }
3041    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3042
3043    let mut recovered = vec![0; 24];
3044    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3045    print!("Ba =\t");
3046    for b in recovered.clone()
3047        { print!("{:02X} ", b); }
3048    println!();
3049    let mut txt = String::new();
3050    for c in recovered.clone()
3051        { write!(txt, "{:02X} ", c); }
3052    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3053
3054    let mut converted = String::new();
3055    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3056    converted.truncate(len as usize);
3057    
3058    println!("Bb =\t{}", converted);
3059    assert_eq!(converted, "고맙습니다.");
3060    assert_eq!(converted, message);
3061    println!("-------------------------------");
3062}
3063
3064fn des_decrypt_with_padding_iso_ecb_into_vec()
3065{
3066    println!("des_decrypt_with_padding_iso_ecb_into_vec()");
3067    use std::io::Write;
3068    use std::fmt::Write as _;
3069    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3070
3071    // Normal case
3072    let key = 0x_1234567890ABCDEF_u64;
3073    println!("K =\t{:#016X}", key);
3074    let mut a_des = DES::new_with_key_u64(key);
3075
3076    let message = "In the beginning God created the heavens and the earth.";
3077    println!("M =\t{}", message);
3078    let mut cipher = Vec::<u8>::new();
3079    a_des.encrypt_str_into_vec(&message, &mut cipher);
3080    print!("C (16 rounds) =\t");
3081    for c in cipher.clone()
3082        { print!("{:02X} ", c); }
3083    println!();
3084    let mut txt = String::new();
3085    for c in cipher.clone()
3086        { write!(txt, "{:02X} ", c); }
3087    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3088
3089    let mut recovered = Vec::<u8>::new();
3090    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3091    print!("Ba (16 rounds) =\t");
3092    for b in recovered.clone()
3093        { print!("{:02X} ", b); }
3094    println!();
3095    let mut txt = String::new();
3096    for c in recovered.clone()
3097        { write!(txt, "{:02X} ", c); }
3098    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3099
3100    let mut converted = String::new();
3101    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3102    
3103    println!("Bb (16 rounds) =\t{}", converted);
3104    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3105    assert_eq!(converted, message);
3106    println!();
3107
3108    // Expanded case for 128 rounds
3109    let key = 0x_1234567890ABCDEF_u64;
3110    println!("K =\t{:#016X}", key);
3111    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3112
3113    let message = "In the beginning God created the heavens and the earth.";
3114    println!("M =\t{}", message);
3115    let mut cipher = Vec::<u8>::new();
3116    a_des.encrypt_str_into_vec(&message, &mut cipher);
3117    print!("C (128 rounds) =\t");
3118    for c in cipher.clone()
3119        { print!("{:02X} ", c); }
3120    println!();
3121    let mut txt = String::new();
3122    for c in cipher.clone()
3123        { write!(txt, "{:02X} ", c); }
3124    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3125
3126    let mut recovered = Vec::<u8>::new();
3127    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3128    print!("Ba (128 rounds) =\t");
3129    for b in recovered.clone()
3130        { print!("{:02X} ", b); }
3131    println!();
3132    let mut txt = String::new();
3133    for c in recovered.clone()
3134        { write!(txt, "{:02X} ", c); }
3135    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3136
3137    let mut converted = String::new();
3138    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139    
3140    println!("Bb (128 rounds) =\t{}", converted);
3141    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3142    assert_eq!(converted, message);
3143    println!();
3144
3145    // Expanded case for 0 rounds which means that key is meaningless
3146    let key1 = 0x_1234567890ABCDEF_u64;
3147    let key2 = 0_u64;
3148    println!("K =\t{:#016X}", key);
3149    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3150    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3151
3152    let message = "In the beginning God created the heavens and the earth.";
3153    println!("M =\t{}", message);
3154    let mut cipher1 = Vec::<u8>::new();
3155    let mut cipher2 = Vec::<u8>::new();
3156    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3157    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3158    print!("C (0 rounds) =\t");
3159    for c in cipher1.clone()
3160        { print!("{:02X} ", c); }
3161    println!();
3162    let mut txt = String::new();
3163    for c in cipher1.clone()
3164        { write!(txt, "{:02X} ", c); }
3165    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3166    print!("D (0 rounds) =\t");
3167    for c in cipher2.clone()
3168        { print!("{:02X} ", c); }
3169    println!();
3170    let mut txt = String::new();
3171    for c in cipher2.clone()
3172        { write!(txt, "{:02X} ", c); }
3173    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3174
3175    let mut recovered1 = Vec::<u8>::new();
3176    let mut recovered2 = Vec::<u8>::new();
3177    c_des.decrypt_into_vec(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3178    d_des.decrypt_into_vec(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3179    print!("B1a (0 rounds) =\t");
3180    for b in recovered1.clone()
3181        { print!("{:02X} ", b); }
3182    println!();
3183    let mut txt = String::new();
3184    for c in recovered1.clone()
3185        { write!(txt, "{:02X} ", c); }
3186    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3187    print!("B2a (0 rounds) =\t");
3188    for b in recovered2.clone()
3189        { print!("{:02X} ", b); }
3190    println!();
3191    let mut txt = String::new();
3192    for c in recovered2.clone()
3193        { write!(txt, "{:02X} ", c); }
3194    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3195
3196    let mut converted1 = String::new();
3197    let mut converted2 = String::new();
3198    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3199    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3200    
3201    println!("B1b (0 rounds) =\t{}", converted1);
3202    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3203    assert_eq!(converted1, message);
3204    println!("B2b (0 rounds) =\t{}", converted2);
3205    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3206    assert_eq!(converted2, message);
3207    assert_eq!(converted1, converted1);
3208    println!();
3209
3210    // Normal case for the message of 0 bytes
3211    let key = 0x_1234567890ABCDEF_u64;
3212    println!("K =\t{:#016X}", key);
3213    let mut a_des = DES::new_with_key_u64(key);
3214
3215    let message = "";
3216    println!("M =\t{}", message);
3217    let mut cipher = Vec::<u8>::new();
3218    a_des.encrypt_str_into_vec(&message, &mut cipher);
3219    print!("C =\t");
3220    for c in cipher.clone()
3221        { print!("{:02X} ", c); }
3222    println!();
3223    let mut txt = String::new();
3224    for c in cipher.clone()
3225        { write!(txt, "{:02X} ", c); }
3226    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3227
3228    let mut recovered = Vec::<u8>::new();
3229    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3230    print!("Ba =\t");
3231    for b in recovered.clone()
3232        { print!("{:02X} ", b); }
3233    println!();
3234    let mut txt = String::new();
3235    for c in recovered.clone()
3236        { write!(txt, "{:02X} ", c); }
3237    assert_eq!(txt, "");
3238
3239    let mut converted = String::new();
3240    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3241    
3242    println!("Bb =\t{}", converted);
3243    assert_eq!(converted, "");
3244    assert_eq!(converted, message);
3245    println!();
3246
3247    // Normal case for the message shorter than 8 bytes
3248    let key = 0x_1234567890ABCDEF_u64;
3249    println!("K =\t{:#016X}", key);
3250    let mut a_des = DES::new_with_key_u64(key);
3251
3252    let message = "7 bytes";
3253    println!("M =\t{}", message);
3254    let mut cipher = Vec::<u8>::new();
3255    a_des.encrypt_str_into_vec(&message, &mut cipher);
3256    print!("C =\t");
3257    for c in cipher.clone()
3258        { print!("{:02X} ", c); }
3259    println!();
3260    let mut txt = String::new();
3261    for c in cipher.clone()
3262        { write!(txt, "{:02X} ", c); }
3263    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3264    
3265    let mut recovered = Vec::<u8>::new();
3266    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3267    print!("Ba =\t");
3268    for b in recovered.clone()
3269        { print!("{:02X} ", b); }
3270    println!();
3271    let mut txt = String::new();
3272    for c in recovered.clone()
3273        { write!(txt, "{:02X} ", c); }
3274    assert_eq!(txt, "37 20 62 79 74 65 73 ");
3275
3276    let mut converted = String::new();
3277    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3278    
3279    println!("Bb =\t{}", converted);
3280    assert_eq!(converted, "7 bytes");
3281    assert_eq!(converted, message);
3282    println!();
3283
3284    // Normal case for the message of 8 bytes
3285    let key = 0x_1234567890ABCDEF_u64;
3286    println!("K =\t{:#016X}", key);
3287    let mut a_des = DES::new_with_key_u64(key);
3288
3289    let message = "I am OK.";
3290    println!("M =\t{}", message);
3291    let mut cipher = Vec::<u8>::new();
3292    a_des.encrypt_str_into_vec(&message, &mut cipher);
3293    print!("C =\t");
3294    for c in cipher.clone()
3295        { print!("{:02X} ", c); }
3296    println!();
3297    let mut txt = String::new();
3298    for c in cipher.clone()
3299        { write!(txt, "{:02X} ", c); }
3300    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3301    
3302    let mut recovered = Vec::<u8>::new();
3303    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3304    print!("Ba =\t");
3305    for b in recovered.clone()
3306        { print!("{:02X} ", b); }
3307    println!();
3308    let mut txt = String::new();
3309    for c in recovered.clone()
3310        { write!(txt, "{:02X} ", c); }
3311    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3312
3313    let mut converted = String::new();
3314    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3315    
3316    println!("Bb =\t{}", converted);
3317    assert_eq!(converted, "I am OK.");
3318    assert_eq!(converted, message);
3319    println!();
3320
3321    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3322    let key = 0x_1234567890ABCDEF_u64;
3323    println!("K =\t{:#016X}", key);
3324    let mut a_des = DES::new_with_key_u64(key);
3325
3326    let message = "PARK Youngho";
3327    println!("M =\t{}", message);
3328    let mut cipher = Vec::<u8>::new();
3329    a_des.encrypt_str_into_vec(&message, &mut cipher);
3330    print!("C =\t");
3331    for c in cipher.clone()
3332        { print!("{:02X} ", c); }
3333    println!();
3334    let mut txt = String::new();
3335    for c in cipher.clone()
3336        { write!(txt, "{:02X} ", c); }
3337    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3338
3339    let mut recovered = Vec::<u8>::new();
3340    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3341    print!("Ba =\t");
3342    for b in recovered.clone()
3343        { print!("{:02X} ", b); }
3344    println!();
3345    let mut txt = String::new();
3346    for c in recovered.clone()
3347        { write!(txt, "{:02X} ", c); }
3348    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3349
3350    let mut converted = String::new();
3351    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3352    
3353    println!("Bb =\t{}", converted);
3354    assert_eq!(converted, "PARK Youngho");
3355    assert_eq!(converted, message);
3356    println!();
3357
3358    // Normal case for the message of 16 bytes
3359    let key = 0x_1234567890ABCDEF_u64;
3360    println!("K =\t{:#016X}", key);
3361    let mut a_des = DES::new_with_key_u64(key);
3362
3363    let message = "고맙습니다.";
3364    println!("M =\t{}", message);
3365    let mut cipher = Vec::<u8>::new();
3366    a_des.encrypt_str_into_vec(&message, &mut cipher);
3367    print!("C =\t");
3368    for c in cipher.clone()
3369        { print!("{:02X} ", c); }
3370    println!();
3371    let mut txt = String::new();
3372    for c in cipher.clone()
3373        { write!(txt, "{:02X} ", c); }
3374    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3375
3376    let mut recovered = Vec::<u8>::new();
3377    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3378    print!("Ba =\t");
3379    for b in recovered.clone()
3380        { print!("{:02X} ", b); }
3381    println!();
3382    let mut txt = String::new();
3383    for c in recovered.clone()
3384        { write!(txt, "{:02X} ", c); }
3385    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3386
3387    let mut converted = String::new();
3388    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3389    
3390    println!("Bb =\t{}", converted);
3391    assert_eq!(converted, "고맙습니다.");
3392    assert_eq!(converted, message);
3393    println!("-------------------------------");
3394}
3395
3396fn des_decrypt_with_padding_iso_ecb_into_array()
3397{
3398    println!("des_decrypt_with_padding_iso_ecb_into_array()");
3399    use std::io::Write;
3400    use std::fmt::Write as _;
3401    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3402
3403    // Normal case
3404    let key = 0x_1234567890ABCDEF_u64;
3405    println!("K =\t{:#016X}", key);
3406    let mut a_des = DES::new_with_key_u64(key);
3407
3408    let message = "In the beginning God created the heavens and the earth.";
3409    println!("M =\t{}", message);
3410    let mut cipher = Vec::<u8>::new();
3411    a_des.encrypt_str_into_vec(&message, &mut cipher);
3412    print!("C (16 rounds) =\t");
3413    for c in cipher.clone()
3414        { print!("{:02X} ", c); }
3415    println!();
3416    let mut txt = String::new();
3417    for c in cipher.clone()
3418        { write!(txt, "{:02X} ", c); }
3419    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3420
3421    let mut recovered = [0u8; 56];
3422    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3423    print!("Ba (16 rounds) =\t");
3424    for b in recovered.clone()
3425        { print!("{:02X} ", b); }
3426    println!();
3427    let mut txt = String::new();
3428    for c in recovered.clone()
3429        { write!(txt, "{:02X} ", c); }
3430    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3431
3432    let mut converted = String::new();
3433    unsafe { converted.as_mut_vec() }.write(&recovered);
3434    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3435    println!("Bb (16 rounds) =\t{}", converted);
3436    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3437    assert_eq!(converted, message);
3438    println!();
3439
3440    // Expanded case for 128 rounds
3441    let key = 0x_1234567890ABCDEF_u64;
3442    println!("K =\t{:#016X}", key);
3443    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3444
3445    let message = "In the beginning God created the heavens and the earth.";
3446    println!("M =\t{}", message);
3447    let mut cipher = Vec::<u8>::new();
3448    a_des.encrypt_str_into_vec(&message, &mut cipher);
3449    print!("C (128 rounds) =\t");
3450    for c in cipher.clone()
3451        { print!("{:02X} ", c); }
3452    println!();
3453    let mut txt = String::new();
3454    for c in cipher.clone()
3455        { write!(txt, "{:02X} ", c); }
3456    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3457
3458    let mut recovered = [0u8; 56];
3459    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3460    print!("Ba (16 rounds) =\t");
3461    for b in recovered.clone()
3462        { print!("{:02X} ", b); }
3463    println!();
3464    let mut txt = String::new();
3465    for c in recovered.clone()
3466        { write!(txt, "{:02X} ", c); }
3467    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3468
3469    let mut converted = String::new();
3470    unsafe { converted.as_mut_vec() }.write(&recovered);
3471    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3472    println!("Bb (16 rounds) =\t{}", converted);
3473    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3474    assert_eq!(converted, message);
3475    println!();
3476
3477    // Expanded case for 0 rounds which means that key is meaningless
3478    let key1 = 0x_1234567890ABCDEF_u64;
3479    let key2 = 0_u64;
3480    println!("K =\t{:#016X}", key);
3481    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3482    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3483
3484    let message = "In the beginning God created the heavens and the earth.";
3485    println!("M =\t{}", message);
3486    let mut cipher1 = Vec::<u8>::new();
3487    let mut cipher2 = Vec::<u8>::new();
3488    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3489    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3490    print!("C (0 rounds) =\t");
3491    for c in cipher1.clone()
3492        { print!("{:02X} ", c); }
3493    println!();
3494    let mut txt = String::new();
3495    for c in cipher1.clone()
3496        { write!(txt, "{:02X} ", c); }
3497    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3498    print!("D (0 rounds) =\t");
3499    for c in cipher2.clone()
3500        { print!("{:02X} ", c); }
3501    println!();
3502    let mut txt = String::new();
3503    for c in cipher2.clone()
3504        { write!(txt, "{:02X} ", c); }
3505    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3506
3507    let mut recovered1 = [0u8; 56];
3508    let mut recovered2 = [0u8; 56];
3509    let len1 = c_des.decrypt_into_array(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3510    let len2 = d_des.decrypt_into_array(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3511    print!("B1a (0 rounds) =\t");
3512    for b in recovered1.clone()
3513        { print!("{:02X} ", b); }
3514    println!();
3515    let mut txt = String::new();
3516    for c in recovered1.clone()
3517        { write!(txt, "{:02X} ", c); }
3518    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3519    print!("B2a (0 rounds) =\t");
3520    for b in recovered2.clone()
3521        { print!("{:02X} ", b); }
3522    println!();
3523    let mut txt = String::new();
3524    for c in recovered.clone()
3525        { write!(txt, "{:02X} ", c); }
3526    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3527
3528    let mut converted1 = String::new();
3529    let mut converted2 = String::new();
3530    unsafe { converted1.as_mut_vec() }.write(&recovered1);
3531    unsafe { converted2.as_mut_vec() }.write(&recovered2);
3532    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3533    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3534    println!("B1b (0 rounds) =\t{}", converted1);
3535    println!("B2b (0 rounds) =\t{}", converted2);
3536    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3537    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3538    assert_eq!(converted1, message);
3539    assert_eq!(converted2, message);
3540    assert_eq!(converted1, converted2);
3541    println!();
3542
3543    // Normal case for the message of 0 bytes
3544    let key = 0x_1234567890ABCDEF_u64;
3545    println!("K =\t{:#016X}", key);
3546    let mut a_des = DES::new_with_key_u64(key);
3547
3548    let message = "";
3549    println!("M =\t{}", message);
3550    let mut cipher = Vec::<u8>::new();
3551    a_des.encrypt_str_into_vec(&message, &mut cipher);
3552    print!("C =\t");
3553    for c in cipher.clone()
3554        { print!("{:02X} ", c); }
3555    println!();
3556    let mut txt = String::new();
3557    for c in cipher.clone()
3558        { write!(txt, "{:02X} ", c); }
3559    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3560
3561    let mut recovered = [0u8; 8];
3562    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3563
3564    print!("Ba =\t");
3565    for b in recovered.clone()
3566        { print!("{:02X} ", b); }
3567    println!();
3568    let mut txt = String::new();
3569    for c in recovered.clone()
3570        { write!(txt, "{:02X} ", c); }
3571    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3572
3573    let mut converted = String::new();
3574    unsafe { converted.as_mut_vec() }.write(&recovered);
3575    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3576    println!("Bb =\t{}", converted);
3577    assert_eq!(converted, "");
3578    assert_eq!(converted, message);
3579    println!();
3580
3581    // Normal case for the message shorter than 8 bytes
3582    let key = 0x_1234567890ABCDEF_u64;
3583    println!("K =\t{:#016X}", key);
3584    let mut a_des = DES::new_with_key_u64(key);
3585
3586    let message = "7 bytes";
3587    println!("M =\t{}", message);
3588    let mut cipher = Vec::<u8>::new();
3589    a_des.encrypt_str_into_vec(&message, &mut cipher);
3590    print!("C =\t");
3591    for c in cipher.clone()
3592        { print!("{:02X} ", c); }
3593    println!();
3594    let mut txt = String::new();
3595    for c in cipher.clone()
3596        { write!(txt, "{:02X} ", c); }
3597    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3598
3599    let mut recovered = [0u8; 8];
3600    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3601
3602    print!("Ba =\t");
3603    for b in recovered.clone()
3604        { print!("{:02X} ", b); }
3605    println!();
3606    let mut txt = String::new();
3607    for c in recovered.clone()
3608        { write!(txt, "{:02X} ", c); }
3609    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3610
3611    let mut converted = String::new();
3612    unsafe { converted.as_mut_vec() }.write(&recovered);
3613    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3614    println!("Bb =\t{}", converted);
3615    assert_eq!(converted, "7 bytes");
3616    assert_eq!(converted, message);
3617    println!();
3618
3619    // Normal case for the message of 8 bytes
3620    let key = 0x_1234567890ABCDEF_u64;
3621    println!("K =\t{:#016X}", key);
3622    let mut a_des = DES::new_with_key_u64(key);
3623
3624    let message = "I am OK.";
3625    println!("M =\t{}", message);
3626    let mut cipher = Vec::<u8>::new();
3627    a_des.encrypt_str_into_vec(&message, &mut cipher);
3628    print!("C =\t");
3629    for c in cipher.clone()
3630        { print!("{:02X} ", c); }
3631    println!();
3632    let mut txt = String::new();
3633    for c in cipher.clone()
3634        { write!(txt, "{:02X} ", c); }
3635    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3636
3637    let mut recovered = [0u8; 16];
3638    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3639
3640    print!("Ba =\t");
3641    for b in recovered.clone()
3642        { print!("{:02X} ", b); }
3643    println!();
3644    let mut txt = String::new();
3645    for c in recovered.clone()
3646        { write!(txt, "{:02X} ", c); }
3647    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3648
3649    let mut converted = String::new();
3650    unsafe { converted.as_mut_vec() }.write(&recovered);
3651    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3652    println!("Bb =\t{}", converted);
3653    assert_eq!(converted, "I am OK.");
3654    assert_eq!(converted, message);
3655    println!();
3656
3657    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3658    let key = 0x_1234567890ABCDEF_u64;
3659    println!("K =\t{:#016X}", key);
3660    let mut a_des = DES::new_with_key_u64(key);
3661
3662    let message = "PARK Youngho";
3663    println!("M =\t{}", message);
3664    let mut cipher = Vec::<u8>::new();
3665    a_des.encrypt_str_into_vec(&message, &mut cipher);
3666    print!("C =\t");
3667    for c in cipher.clone()
3668        { print!("{:02X} ", c); }
3669    println!();
3670    let mut txt = String::new();
3671    for c in cipher.clone()
3672        { write!(txt, "{:02X} ", c); }
3673    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3674
3675    let mut recovered = [0u8; 16];
3676    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3677
3678    print!("Ba =\t");
3679    for b in recovered.clone()
3680        { print!("{:02X} ", b); }
3681    println!();
3682    let mut txt = String::new();
3683    for c in recovered.clone()
3684        { write!(txt, "{:02X} ", c); }
3685    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3686
3687    let mut converted = String::new();
3688    unsafe { converted.as_mut_vec() }.write(&recovered);
3689    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3690    println!("Bb =\t{}", converted);
3691    assert_eq!(converted, "PARK Youngho");
3692    assert_eq!(converted, message);
3693    println!();
3694
3695    // Normal case for the message of 16 bytes
3696    let key = 0x_1234567890ABCDEF_u64;
3697    println!("K =\t{:#016X}", key);
3698    let mut a_des = DES::new_with_key_u64(key);
3699
3700    let message = "고맙습니다.";
3701    println!("M =\t{}", message);
3702    let mut cipher = Vec::<u8>::new();
3703    a_des.encrypt_str_into_vec(&message, &mut cipher);
3704    print!("C =\t");
3705    for c in cipher.clone()
3706        { print!("{:02X} ", c); }
3707    println!();
3708    let mut txt = String::new();
3709    for c in cipher.clone()
3710        { write!(txt, "{:02X} ", c); }
3711    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3712
3713    let mut recovered = [0u8; 24];
3714    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3715
3716    print!("Ba =\t");
3717    for b in recovered.clone()
3718        { print!("{:02X} ", b); }
3719    println!();
3720    let mut txt = String::new();
3721    for c in recovered.clone()
3722        { write!(txt, "{:02X} ", c); }
3723    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3724
3725    let mut converted = String::new();
3726    unsafe { converted.as_mut_vec() }.write(&recovered);
3727    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3728    println!("Bb =\t{}", converted);
3729    assert_eq!(converted, "고맙습니다.");
3730    assert_eq!(converted, message);
3731    println!("-------------------------------");
3732}
3733
3734fn des_decrypt_with_padding_iso_ecb_into_string()
3735{
3736    println!("des_decrypt_with_padding_iso_ecb_into_string()");
3737    use std::io::Write;
3738    use std::fmt::Write as _;
3739    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3740
3741    // Normal case
3742    let key = 0x_1234567890ABCDEF_u64;
3743    println!("K =\t{:#016X}", key);
3744    let mut a_des = DES::new_with_key_u64(key);
3745
3746    let message = "In the beginning God created the heavens and the earth.";
3747    println!("M =\t{}", message);
3748    let mut cipher = Vec::<u8>::new();
3749    a_des.encrypt_str_into_vec(&message, &mut cipher);
3750    print!("C (16 rounds) =\t");
3751    for c in cipher.clone()
3752        { print!("{:02X} ", c); }
3753    println!();
3754    let mut txt = String::new();
3755    for c in cipher.clone()
3756        { write!(txt, "{:02X} ", c); }
3757    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3758
3759    let mut recovered = String::new();
3760    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3761    println!("B (16 rounds) =\t{}", recovered);
3762    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3763    assert_eq!(recovered, message);
3764    println!();
3765
3766    // Expanded case for 128 rounds
3767    let key = 0x_1234567890ABCDEF_u64;
3768    println!("K =\t{:#016X}", key);
3769    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3770
3771    let message = "In the beginning God created the heavens and the earth.";
3772    println!("M =\t{}", message);
3773    let mut cipher = Vec::<u8>::new();
3774    a_des.encrypt_str_into_vec(&message, &mut cipher);
3775    print!("C (128 rounds) =\t");
3776    for c in cipher.clone()
3777        { print!("{:02X} ", c); }
3778    println!();
3779    let mut txt = String::new();
3780    for c in cipher.clone()
3781        { write!(txt, "{:02X} ", c); }
3782    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3783
3784    let mut recovered = String::new();
3785    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3786    println!("B (128 rounds) =\t{}", recovered);
3787    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3788    assert_eq!(recovered, message);
3789    println!();
3790
3791    // Expanded case for 0 rounds which means that key is meaningless
3792    let key1 = 0x_1234567890ABCDEF_u64;
3793    let key2 = 0_u64;
3794    println!("K =\t{:#016X}", key);
3795    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3796    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3797
3798    let message = "In the beginning God created the heavens and the earth.";
3799    println!("M =\t{}", message);
3800    let mut cipher1 = Vec::<u8>::new();
3801    let mut cipher2 = Vec::<u8>::new();
3802    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3803    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3804    print!("C (0 rounds) =\t");
3805    for c in cipher1.clone()
3806        { print!("{:02X} ", c); }
3807    println!();
3808    let mut txt = String::new();
3809    for c in cipher1.clone()
3810        { write!(txt, "{:02X} ", c); }
3811    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3812    print!("D (0 rounds) =\t");
3813    for c in cipher2.clone()
3814        { print!("{:02X} ", c); }
3815    println!();
3816    let mut txt = String::new();
3817    for c in cipher2.clone()
3818        { write!(txt, "{:02X} ", c); }
3819    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3820
3821    let mut recovered1 = String::new();
3822    let mut recovered2 = String::new();
3823    c_des.decrypt_into_string(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3824    d_des.decrypt_into_string(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3825    println!("B1 (0 rounds) =\t{}", recovered1);
3826    println!("B2 (0 rounds) =\t{}", recovered2);
3827    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
3828    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
3829    assert_eq!(recovered1, message);
3830    assert_eq!(recovered2, message);
3831    assert_eq!(recovered1, recovered2);
3832    println!();
3833
3834    // Normal case for the message of 0 bytes
3835    let key = 0x_1234567890ABCDEF_u64;
3836    println!("K =\t{:#016X}", key);
3837    let mut a_des = DES::new_with_key_u64(key);
3838
3839    let message = "";
3840    println!("M =\t{}", message);
3841    let mut cipher = Vec::<u8>::new();
3842    a_des.encrypt_str_into_vec(&message, &mut cipher);
3843    print!("C =\t");
3844    for c in cipher.clone()
3845        { print!("{:02X} ", c); }
3846    println!();
3847    let mut txt = String::new();
3848    for c in cipher.clone()
3849        { write!(txt, "{:02X} ", c); }
3850    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3851
3852    let mut recovered = String::new();
3853    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3854    println!("B =\t{}", recovered);
3855    assert_eq!(recovered, "");
3856    assert_eq!(recovered, message);
3857    println!();
3858
3859    // Normal case for the message shorter than 8 bytes
3860    let key = 0x_1234567890ABCDEF_u64;
3861    println!("K =\t{:#016X}", key);
3862    let mut a_des = DES::new_with_key_u64(key);
3863
3864    let message = "7 bytes";
3865    println!("M =\t{}", message);
3866    let mut cipher = Vec::<u8>::new();
3867    a_des.encrypt_str_into_vec(&message, &mut cipher);
3868    print!("C =\t");
3869    for c in cipher.clone()
3870        { print!("{:02X} ", c); }
3871    println!();
3872    let mut txt = String::new();
3873    for c in cipher.clone()
3874        { write!(txt, "{:02X} ", c); }
3875    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3876
3877    let mut recovered = String::new();
3878    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3879    println!("B =\t{}", recovered);
3880    assert_eq!(recovered, "7 bytes");
3881    assert_eq!(recovered, message);
3882    println!();
3883
3884    // Normal case for the message of 8 bytes
3885    let key = 0x_1234567890ABCDEF_u64;
3886    println!("K =\t{:#016X}", key);
3887    let mut a_des = DES::new_with_key_u64(key);
3888
3889    let message = "I am OK.";
3890    println!("M =\t{}", message);
3891    let mut cipher = Vec::<u8>::new();
3892    a_des.encrypt_str_into_vec(&message, &mut cipher);
3893    print!("C =\t");
3894    for c in cipher.clone()
3895        { print!("{:02X} ", c); }
3896    println!();
3897    let mut txt = String::new();
3898    for c in cipher.clone()
3899        { write!(txt, "{:02X} ", c); }
3900    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3901
3902    let mut recovered = String::new();
3903    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3904    println!("B =\t{}", recovered);
3905    assert_eq!(recovered, "I am OK.");
3906    assert_eq!(recovered, message);
3907    println!();
3908
3909    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3910    let key = 0x_1234567890ABCDEF_u64;
3911    println!("K =\t{:#016X}", key);
3912    let mut a_des = DES::new_with_key_u64(key);
3913
3914    let message = "PARK Youngho";
3915    println!("M =\t{}", message);
3916    let mut cipher = Vec::<u8>::new();
3917    a_des.encrypt_str_into_vec(&message, &mut cipher);
3918    print!("C =\t");
3919    for c in cipher.clone()
3920        { print!("{:02X} ", c); }
3921    println!();
3922    let mut txt = String::new();
3923    for c in cipher.clone()
3924        { write!(txt, "{:02X} ", c); }
3925    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3926
3927    let mut recovered = String::new();
3928    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3929    println!("B =\t{}", recovered);
3930    assert_eq!(recovered, "PARK Youngho");
3931    assert_eq!(recovered, message);
3932    println!();
3933
3934    // Normal case for the message of 16 bytes
3935    let key = 0x_1234567890ABCDEF_u64;
3936    println!("K =\t{:#016X}", key);
3937    let mut a_des = DES::new_with_key_u64(key);
3938
3939    let message = "고맙습니다.";
3940    println!("M =\t{}", message);
3941    let mut cipher = Vec::<u8>::new();
3942    a_des.encrypt_str_into_vec(&message, &mut cipher);
3943    print!("C =\t");
3944    for c in cipher.clone()
3945        { print!("{:02X} ", c); }
3946    println!();
3947    let mut txt = String::new();
3948    for c in cipher.clone()
3949        { write!(txt, "{:02X} ", c); }
3950    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3951
3952    let mut recovered = String::new();
3953    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3954    println!("B =\t{}", recovered);
3955    assert_eq!(recovered, "고맙습니다.");
3956    assert_eq!(recovered, message);
3957    println!("-------------------------------");
3958}
3959
3960fn des_decrypt_vec_with_padding_iso_ecb()
3961{
3962    println!("des_decrypt_vec_with_padding_iso_ecb()");
3963    use std::io::Write;
3964    use std::fmt::Write as _;
3965    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3966
3967    // Normal case
3968    let key = 0x_1234567890ABCDEF_u64;
3969    println!("K =\t{:#016X}", key);
3970    let mut a_des = DES::new_with_key_u64(key);
3971
3972    let message = "In the beginning God created the heavens and the earth.";
3973    println!("M =\t{}", message);
3974    let mut cipher = Vec::<u8>::new();
3975    a_des.encrypt_str_into_vec(&message, &mut cipher);
3976    print!("C (16 rounds) =\t");
3977    for c in cipher.clone()
3978        { print!("{:02X} ", c); }
3979    println!();
3980    let mut txt = String::new();
3981    for c in cipher.clone()
3982        { write!(txt, "{:02X} ", c); }
3983    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3984
3985    let mut recovered = vec![0; 55];
3986    a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
3987    print!("Ba (16 rounds) =\t");
3988    for b in recovered.clone()
3989        { print!("{:02X} ", b); }
3990    println!();
3991    let mut txt = String::new();
3992    for c in recovered.clone()
3993        { write!(txt, "{:02X} ", c); }
3994    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3995
3996    let mut converted = String::new();
3997    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3998    
3999    println!("Bb (16 rounds) =\t{}", converted);
4000    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4001    assert_eq!(converted, message);
4002    println!();
4003
4004    // Expanded case for 128 rounds
4005    let key = 0x_1234567890ABCDEF_u64;
4006    println!("K =\t{:#016X}", key);
4007    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4008
4009    let message = "In the beginning God created the heavens and the earth.";
4010    println!("M =\t{}", message);
4011    let mut cipher = Vec::<u8>::new();
4012    a_des.encrypt_str_into_vec(&message, &mut cipher);
4013    print!("C (128 rounds) =\t");
4014    for c in cipher.clone()
4015        { print!("{:02X} ", c); }
4016    println!();
4017    let mut txt = String::new();
4018    for c in cipher.clone()
4019        { write!(txt, "{:02X} ", c); }
4020    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4021
4022    let mut recovered = vec![0; 55];
4023    a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4024    print!("Ba (128 rounds) =\t");
4025    for b in recovered.clone()
4026        { print!("{:02X} ", b); }
4027    println!();
4028    let mut txt = String::new();
4029    for c in recovered.clone()
4030        { write!(txt, "{:02X} ", c); }
4031    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4032
4033    let mut converted = String::new();
4034    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4035    
4036    println!("Bb (128 rounds) =\t{}", converted);
4037    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4038    assert_eq!(converted, message);
4039    println!();
4040
4041    // Expanded case for 0 rounds which means that key is meaningless
4042    let key1 = 0x_1234567890ABCDEF_u64;
4043    let key2 = 0_u64;
4044    println!("K =\t{:#016X}", key);
4045    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4046    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4047
4048    let message = "In the beginning God created the heavens and the earth.";
4049    println!("M =\t{}", message);
4050    let mut cipher1 = Vec::<u8>::new();
4051    let mut cipher2 = Vec::<u8>::new();
4052    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4053    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4054    print!("C (0 rounds) =\t");
4055    for c in cipher1.clone()
4056        { print!("{:02X} ", c); }
4057    println!();
4058    let mut txt = String::new();
4059    for c in cipher1.clone()
4060        { write!(txt, "{:02X} ", c); }
4061    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4062    print!("D (0 rounds) =\t");
4063    for c in cipher2.clone()
4064        { print!("{:02X} ", c); }
4065    println!();
4066    let mut txt = String::new();
4067    for c in cipher2.clone()
4068        { write!(txt, "{:02X} ", c); }
4069    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4070
4071    let mut recovered1 = vec![0; 55];
4072    let mut recovered2 = vec![0; 55];
4073    c_des.decrypt_vec(&cipher1, recovered1.as_mut_ptr());
4074    d_des.decrypt_vec(&cipher2, recovered2.as_mut_ptr());
4075    print!("B1a (0 rounds) =\t");
4076    for b in recovered1.clone()
4077        { print!("{:02X} ", b); }
4078    println!();
4079    let mut txt = String::new();
4080    for c in recovered1.clone()
4081        { write!(txt, "{:02X} ", c); }
4082    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4083    print!("B2a (0 rounds) =\t");
4084    for b in recovered2.clone()
4085        { print!("{:02X} ", b); }
4086    println!();
4087    let mut txt = String::new();
4088    for c in recovered2.clone()
4089        { write!(txt, "{:02X} ", c); }
4090    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4091
4092    let mut converted1 = String::new();
4093    let mut converted2 = String::new();
4094    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4095    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4096    
4097    println!("B1b (0 rounds) =\t{}", converted1);
4098    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4099    assert_eq!(converted1, message);
4100    println!("B2b (0 rounds) =\t{}", converted2);
4101    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4102    assert_eq!(converted2, message);
4103    assert_eq!(converted1, converted1);
4104    println!();
4105
4106    // Normal case for the message of 0 bytes
4107    let key = 0x_1234567890ABCDEF_u64;
4108    println!("K =\t{:#016X}", key);
4109    let mut a_des = DES::new_with_key_u64(key);
4110
4111    let message = "";
4112    println!("M =\t{}", message);
4113    let mut cipher = Vec::<u8>::new();
4114    a_des.encrypt_str_into_vec(&message, &mut cipher);
4115    print!("C =\t");
4116    for c in cipher.clone()
4117        { print!("{:02X} ", c); }
4118    println!();
4119    let mut txt = String::new();
4120    for c in cipher.clone()
4121        { write!(txt, "{:02X} ", c); }
4122    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4123
4124    let mut recovered = vec![0; 8];
4125    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4126    print!("Ba =\t");
4127    for b in recovered.clone()
4128        { print!("{:02X} ", b); }
4129    println!();
4130    let mut txt = String::new();
4131    for c in recovered.clone()
4132        { write!(txt, "{:02X} ", c); }
4133    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4134
4135    let mut converted = String::new();
4136    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4137    converted.truncate(len as usize);
4138    
4139    println!("Bb =\t{}", converted);
4140    assert_eq!(converted, "");
4141    assert_eq!(converted, message);
4142    println!();
4143
4144    // Normal case for the message shorter than 8 bytes
4145    let key = 0x_1234567890ABCDEF_u64;
4146    println!("K =\t{:#016X}", key);
4147    let mut a_des = DES::new_with_key_u64(key);
4148
4149    let message = "7 bytes";
4150    println!("M =\t{}", message);
4151    let mut cipher = Vec::<u8>::new();
4152    a_des.encrypt_str_into_vec(&message, &mut cipher);
4153    print!("C =\t");
4154    for c in cipher.clone()
4155        { print!("{:02X} ", c); }
4156    println!();
4157    let mut txt = String::new();
4158    for c in cipher.clone()
4159        { write!(txt, "{:02X} ", c); }
4160    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4161    
4162    let mut recovered = vec![0; 8];
4163    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4164    print!("Ba =\t");
4165    for b in recovered.clone()
4166        { print!("{:02X} ", b); }
4167    println!();
4168    let mut txt = String::new();
4169    for c in recovered.clone()
4170        { write!(txt, "{:02X} ", c); }
4171    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4172
4173    let mut converted = String::new();
4174    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4175    converted.truncate(len as usize);
4176
4177    println!("Bb =\t{}", converted);
4178    assert_eq!(converted, "7 bytes");
4179    assert_eq!(converted, message);
4180    println!();
4181
4182    // Normal case for the message of 8 bytes
4183    let key = 0x_1234567890ABCDEF_u64;
4184    println!("K =\t{:#016X}", key);
4185    let mut a_des = DES::new_with_key_u64(key);
4186
4187    let message = "I am OK.";
4188    println!("M =\t{}", message);
4189    let mut cipher = Vec::<u8>::new();
4190    a_des.encrypt_str_into_vec(&message, &mut cipher);
4191    print!("C =\t");
4192    for c in cipher.clone()
4193        { print!("{:02X} ", c); }
4194    println!();
4195    let mut txt = String::new();
4196    for c in cipher.clone()
4197        { write!(txt, "{:02X} ", c); }
4198    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4199    
4200    let mut recovered = vec![0; 16];
4201    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4202    print!("Ba =\t");
4203    for b in recovered.clone()
4204        { print!("{:02X} ", b); }
4205    println!();
4206    let mut txt = String::new();
4207    for c in recovered.clone()
4208        { write!(txt, "{:02X} ", c); }
4209    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4210
4211    let mut converted = String::new();
4212    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4213    converted.truncate(len as usize);
4214    
4215    println!("Bb =\t{}", converted);
4216    assert_eq!(converted, "I am OK.");
4217    assert_eq!(converted, message);
4218    println!();
4219
4220    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4221    let key = 0x_1234567890ABCDEF_u64;
4222    println!("K =\t{:#016X}", key);
4223    let mut a_des = DES::new_with_key_u64(key);
4224
4225    let message = "PARK Youngho";
4226    println!("M =\t{}", message);
4227    let mut cipher = Vec::<u8>::new();
4228    a_des.encrypt_str_into_vec(&message, &mut cipher);
4229    print!("C =\t");
4230    for c in cipher.clone()
4231        { print!("{:02X} ", c); }
4232    println!();
4233    let mut txt = String::new();
4234    for c in cipher.clone()
4235        { write!(txt, "{:02X} ", c); }
4236    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4237
4238    let mut recovered = vec![0; 16];
4239    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4240    print!("Ba =\t");
4241    for b in recovered.clone()
4242        { print!("{:02X} ", b); }
4243    println!();
4244    let mut txt = String::new();
4245    for c in recovered.clone()
4246        { write!(txt, "{:02X} ", c); }
4247    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4248
4249    let mut converted = String::new();
4250    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4251    converted.truncate(len as usize);
4252    
4253    println!("Bb =\t{}", converted);
4254    assert_eq!(converted, "PARK Youngho");
4255    assert_eq!(converted, message);
4256    println!();
4257
4258    // Normal case for the message of 16 bytes
4259    let key = 0x_1234567890ABCDEF_u64;
4260    println!("K =\t{:#016X}", key);
4261    let mut a_des = DES::new_with_key_u64(key);
4262
4263    let message = "고맙습니다.";
4264    println!("M =\t{}", message);
4265    let mut cipher = Vec::<u8>::new();
4266    a_des.encrypt_str_into_vec(&message, &mut cipher);
4267    print!("C =\t");
4268    for c in cipher.clone()
4269        { print!("{:02X} ", c); }
4270    println!();
4271    let mut txt = String::new();
4272    for c in cipher.clone()
4273        { write!(txt, "{:02X} ", c); }
4274    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4275
4276    let mut recovered = vec![0; 24];
4277    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4278    print!("Ba =\t");
4279    for b in recovered.clone()
4280        { print!("{:02X} ", b); }
4281    println!();
4282    let mut txt = String::new();
4283    for c in recovered.clone()
4284        { write!(txt, "{:02X} ", c); }
4285    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4286
4287    let mut converted = String::new();
4288    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4289    converted.truncate(len as usize);
4290    
4291    println!("Bb =\t{}", converted);
4292    assert_eq!(converted, "고맙습니다.");
4293    assert_eq!(converted, message);
4294    println!("-------------------------------");
4295}
4296
4297fn des_decrypt_vec_with_padding_iso_ecb_into_vec()
4298{
4299    println!("des_decrypt_vec_with_padding_iso_ecb_into_vec()");
4300    use std::io::Write;
4301    use std::fmt::Write as _;
4302    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4303
4304    // Normal case
4305    let key = 0x_1234567890ABCDEF_u64;
4306    println!("K =\t{:#016X}", key);
4307    let mut a_des = DES::new_with_key_u64(key);
4308
4309    let message = "In the beginning God created the heavens and the earth.";
4310    println!("M =\t{}", message);
4311    let mut cipher = Vec::<u8>::new();
4312    a_des.encrypt_str_into_vec(&message, &mut cipher);
4313    print!("C (16 rounds) =\t");
4314    for c in cipher.clone()
4315        { print!("{:02X} ", c); }
4316    println!();
4317    let mut txt = String::new();
4318    for c in cipher.clone()
4319        { write!(txt, "{:02X} ", c); }
4320    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4321
4322    let mut recovered = Vec::<u8>::new();
4323    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4324    print!("Ba (16 rounds) =\t");
4325    for b in recovered.clone()
4326        { print!("{:02X} ", b); }
4327    println!();
4328    let mut txt = String::new();
4329    for c in recovered.clone()
4330        { write!(txt, "{:02X} ", c); }
4331    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4332
4333    let mut converted = String::new();
4334    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4335    
4336    println!("Bb (16 rounds) =\t{}", converted);
4337    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4338    assert_eq!(converted, message);
4339    println!();
4340
4341    // Expanded case for 128 rounds
4342    let key = 0x_1234567890ABCDEF_u64;
4343    println!("K =\t{:#016X}", key);
4344    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4345
4346    let message = "In the beginning God created the heavens and the earth.";
4347    println!("M =\t{}", message);
4348    let mut cipher = Vec::<u8>::new();
4349    a_des.encrypt_str_into_vec(&message, &mut cipher);
4350    print!("C (128 rounds) =\t");
4351    for c in cipher.clone()
4352        { print!("{:02X} ", c); }
4353    println!();
4354    let mut txt = String::new();
4355    for c in cipher.clone()
4356        { write!(txt, "{:02X} ", c); }
4357    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4358
4359    let mut recovered = Vec::<u8>::new();
4360    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4361    print!("Ba (128 rounds) =\t");
4362    for b in recovered.clone()
4363        { print!("{:02X} ", b); }
4364    println!();
4365    let mut txt = String::new();
4366    for c in recovered.clone()
4367        { write!(txt, "{:02X} ", c); }
4368    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4369
4370    let mut converted = String::new();
4371    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4372    
4373    println!("Bb (128 rounds) =\t{}", converted);
4374    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4375    assert_eq!(converted, message);
4376    println!();
4377
4378    // Expanded case for 0 rounds which means that key is meaningless
4379    let key1 = 0x_1234567890ABCDEF_u64;
4380    let key2 = 0_u64;
4381    println!("K =\t{:#016X}", key);
4382    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4383    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4384
4385    let message = "In the beginning God created the heavens and the earth.";
4386    println!("M =\t{}", message);
4387    let mut cipher1 = Vec::<u8>::new();
4388    let mut cipher2 = Vec::<u8>::new();
4389    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4390    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4391    print!("C (0 rounds) =\t");
4392    for c in cipher1.clone()
4393        { print!("{:02X} ", c); }
4394    println!();
4395    let mut txt = String::new();
4396    for c in cipher1.clone()
4397        { write!(txt, "{:02X} ", c); }
4398    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4399    print!("D (0 rounds) =\t");
4400    for c in cipher2.clone()
4401        { print!("{:02X} ", c); }
4402    println!();
4403    let mut txt = String::new();
4404    for c in cipher2.clone()
4405        { write!(txt, "{:02X} ", c); }
4406    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4407
4408    let mut recovered1 = Vec::<u8>::new();
4409    let mut recovered2 = Vec::<u8>::new();
4410    c_des.decrypt_vec_into_vec(&cipher1, &mut recovered1);
4411    d_des.decrypt_vec_into_vec(&cipher2, &mut recovered2);
4412    print!("B1a (0 rounds) =\t");
4413    for b in recovered1.clone()
4414        { print!("{:02X} ", b); }
4415    println!();
4416    let mut txt = String::new();
4417    for c in recovered1.clone()
4418        { write!(txt, "{:02X} ", c); }
4419    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4420    print!("B2a (0 rounds) =\t");
4421    for b in recovered2.clone()
4422        { print!("{:02X} ", b); }
4423    println!();
4424    let mut txt = String::new();
4425    for c in recovered2.clone()
4426        { write!(txt, "{:02X} ", c); }
4427    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4428
4429    let mut converted1 = String::new();
4430    let mut converted2 = String::new();
4431    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4432    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4433    
4434    println!("B1b (0 rounds) =\t{}", converted1);
4435    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4436    assert_eq!(converted1, message);
4437    println!("B2b (0 rounds) =\t{}", converted2);
4438    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4439    assert_eq!(converted2, message);
4440    assert_eq!(converted1, converted1);
4441    println!();
4442
4443    // Normal case for the message of 0 bytes
4444    let key = 0x_1234567890ABCDEF_u64;
4445    println!("K =\t{:#016X}", key);
4446    let mut a_des = DES::new_with_key_u64(key);
4447
4448    let message = "";
4449    println!("M =\t{}", message);
4450    let mut cipher = Vec::<u8>::new();
4451    a_des.encrypt_str_into_vec(&message, &mut cipher);
4452    print!("C =\t");
4453    for c in cipher.clone()
4454        { print!("{:02X} ", c); }
4455    println!();
4456    let mut txt = String::new();
4457    for c in cipher.clone()
4458        { write!(txt, "{:02X} ", c); }
4459    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4460
4461    let mut recovered = Vec::<u8>::new();
4462    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4463    print!("Ba =\t");
4464    for b in recovered.clone()
4465        { print!("{:02X} ", b); }
4466    println!();
4467    let mut txt = String::new();
4468    for c in recovered.clone()
4469        { write!(txt, "{:02X} ", c); }
4470    assert_eq!(txt, "");
4471
4472    let mut converted = String::new();
4473    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4474    
4475    println!("Bb =\t{}", converted);
4476    assert_eq!(converted, "");
4477    assert_eq!(converted, message);
4478    println!();
4479
4480    // Normal case for the message shorter than 8 bytes
4481    let key = 0x_1234567890ABCDEF_u64;
4482    println!("K =\t{:#016X}", key);
4483    let mut a_des = DES::new_with_key_u64(key);
4484
4485    let message = "7 bytes";
4486    println!("M =\t{}", message);
4487    let mut cipher = Vec::<u8>::new();
4488    a_des.encrypt_str_into_vec(&message, &mut cipher);
4489    print!("C =\t");
4490    for c in cipher.clone()
4491        { print!("{:02X} ", c); }
4492    println!();
4493    let mut txt = String::new();
4494    for c in cipher.clone()
4495        { write!(txt, "{:02X} ", c); }
4496    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4497    
4498    let mut recovered = Vec::<u8>::new();
4499    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4500    print!("Ba =\t");
4501    for b in recovered.clone()
4502        { print!("{:02X} ", b); }
4503    println!();
4504    let mut txt = String::new();
4505    for c in recovered.clone()
4506        { write!(txt, "{:02X} ", c); }
4507    assert_eq!(txt, "37 20 62 79 74 65 73 ");
4508
4509    let mut converted = String::new();
4510    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4511    
4512    println!("Bb =\t{}", converted);
4513    assert_eq!(converted, "7 bytes");
4514    assert_eq!(converted, message);
4515    println!();
4516
4517    // Normal case for the message of 8 bytes
4518    let key = 0x_1234567890ABCDEF_u64;
4519    println!("K =\t{:#016X}", key);
4520    let mut a_des = DES::new_with_key_u64(key);
4521
4522    let message = "I am OK.";
4523    println!("M =\t{}", message);
4524    let mut cipher = Vec::<u8>::new();
4525    a_des.encrypt_str_into_vec(&message, &mut cipher);
4526    print!("C =\t");
4527    for c in cipher.clone()
4528        { print!("{:02X} ", c); }
4529    println!();
4530    let mut txt = String::new();
4531    for c in cipher.clone()
4532        { write!(txt, "{:02X} ", c); }
4533    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4534    
4535    let mut recovered = Vec::<u8>::new();
4536    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4537    print!("Ba =\t");
4538    for b in recovered.clone()
4539        { print!("{:02X} ", b); }
4540    println!();
4541    let mut txt = String::new();
4542    for c in recovered.clone()
4543        { write!(txt, "{:02X} ", c); }
4544    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4545
4546    let mut converted = String::new();
4547    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4548    
4549    println!("Bb =\t{}", converted);
4550    assert_eq!(converted, "I am OK.");
4551    assert_eq!(converted, message);
4552    println!();
4553
4554    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4555    let key = 0x_1234567890ABCDEF_u64;
4556    println!("K =\t{:#016X}", key);
4557    let mut a_des = DES::new_with_key_u64(key);
4558
4559    let message = "PARK Youngho";
4560    println!("M =\t{}", message);
4561    let mut cipher = Vec::<u8>::new();
4562    a_des.encrypt_str_into_vec(&message, &mut cipher);
4563    print!("C =\t");
4564    for c in cipher.clone()
4565        { print!("{:02X} ", c); }
4566    println!();
4567    let mut txt = String::new();
4568    for c in cipher.clone()
4569        { write!(txt, "{:02X} ", c); }
4570    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4571
4572    let mut recovered = Vec::<u8>::new();
4573    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4574    print!("Ba =\t");
4575    for b in recovered.clone()
4576        { print!("{:02X} ", b); }
4577    println!();
4578    let mut txt = String::new();
4579    for c in recovered.clone()
4580        { write!(txt, "{:02X} ", c); }
4581    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4582
4583    let mut converted = String::new();
4584    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4585    
4586    println!("Bb =\t{}", converted);
4587    assert_eq!(converted, "PARK Youngho");
4588    assert_eq!(converted, message);
4589    println!();
4590
4591    // Normal case for the message of 16 bytes
4592    let key = 0x_1234567890ABCDEF_u64;
4593    println!("K =\t{:#016X}", key);
4594    let mut a_des = DES::new_with_key_u64(key);
4595
4596    let message = "고맙습니다.";
4597    println!("M =\t{}", message);
4598    let mut cipher = Vec::<u8>::new();
4599    a_des.encrypt_str_into_vec(&message, &mut cipher);
4600    print!("C =\t");
4601    for c in cipher.clone()
4602        { print!("{:02X} ", c); }
4603    println!();
4604    let mut txt = String::new();
4605    for c in cipher.clone()
4606        { write!(txt, "{:02X} ", c); }
4607    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4608
4609    let mut recovered = Vec::<u8>::new();
4610    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4611    print!("Ba =\t");
4612    for b in recovered.clone()
4613        { print!("{:02X} ", b); }
4614    println!();
4615    let mut txt = String::new();
4616    for c in recovered.clone()
4617        { write!(txt, "{:02X} ", c); }
4618    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4619
4620    let mut converted = String::new();
4621    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4622    
4623    println!("Bb =\t{}", converted);
4624    assert_eq!(converted, "고맙습니다.");
4625    assert_eq!(converted, message);
4626    println!("-------------------------------");
4627}
4628
4629fn des_decrypt_vec_with_padding_iso_ecb_into_array()
4630{
4631    println!("des_decrypt_vec_with_padding_iso_ecb_into_array()");
4632    use std::io::Write;
4633    use std::fmt::Write as _;
4634    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4635
4636    // Normal case
4637    let key = 0x_1234567890ABCDEF_u64;
4638    println!("K =\t{:#016X}", key);
4639    let mut a_des = DES::new_with_key_u64(key);
4640
4641    let message = "In the beginning God created the heavens and the earth.";
4642    println!("M =\t{}", message);
4643    let mut cipher = Vec::<u8>::new();
4644    a_des.encrypt_str_into_vec(&message, &mut cipher);
4645    print!("C (16 rounds) =\t");
4646    for c in cipher.clone()
4647        { print!("{:02X} ", c); }
4648    println!();
4649    let mut txt = String::new();
4650    for c in cipher.clone()
4651        { write!(txt, "{:02X} ", c); }
4652    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4653
4654    let mut recovered = [0u8; 56];
4655    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4656    print!("Ba (16 rounds) =\t");
4657    for b in recovered.clone()
4658        { print!("{:02X} ", b); }
4659    println!();
4660    let mut txt = String::new();
4661    for c in recovered.clone()
4662        { write!(txt, "{:02X} ", c); }
4663    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4664
4665    let mut converted = String::new();
4666    unsafe { converted.as_mut_vec() }.write(&recovered);
4667    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4668    println!("Bb (16 rounds) =\t{}", converted);
4669    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4670    assert_eq!(converted, message);
4671    println!();
4672
4673    // Expanded case for 128 rounds
4674    let key = 0x_1234567890ABCDEF_u64;
4675    println!("K =\t{:#016X}", key);
4676    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4677
4678    let message = "In the beginning God created the heavens and the earth.";
4679    println!("M =\t{}", message);
4680    let mut cipher = Vec::<u8>::new();
4681    a_des.encrypt_str_into_vec(&message, &mut cipher);
4682    print!("C (128 rounds) =\t");
4683    for c in cipher.clone()
4684        { print!("{:02X} ", c); }
4685    println!();
4686    let mut txt = String::new();
4687    for c in cipher.clone()
4688        { write!(txt, "{:02X} ", c); }
4689    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4690
4691    let mut recovered = [0u8; 56];
4692    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4693    print!("Ba (16 rounds) =\t");
4694    for b in recovered.clone()
4695        { print!("{:02X} ", b); }
4696    println!();
4697    let mut txt = String::new();
4698    for c in recovered.clone()
4699        { write!(txt, "{:02X} ", c); }
4700    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4701
4702    let mut converted = String::new();
4703    unsafe { converted.as_mut_vec() }.write(&recovered);
4704    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4705    println!("Bb (16 rounds) =\t{}", converted);
4706    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4707    assert_eq!(converted, message);
4708    println!();
4709
4710    // Expanded case for 0 rounds which means that key is meaningless
4711    let key1 = 0x_1234567890ABCDEF_u64;
4712    let key2 = 0_u64;
4713    println!("K =\t{:#016X}", key);
4714    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4715    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4716
4717    let message = "In the beginning God created the heavens and the earth.";
4718    println!("M =\t{}", message);
4719    let mut cipher1 = Vec::<u8>::new();
4720    let mut cipher2 = Vec::<u8>::new();
4721    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4722    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4723    print!("C (0 rounds) =\t");
4724    for c in cipher1.clone()
4725        { print!("{:02X} ", c); }
4726    println!();
4727    let mut txt = String::new();
4728    for c in cipher1.clone()
4729        { write!(txt, "{:02X} ", c); }
4730    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4731    print!("D (0 rounds) =\t");
4732    for c in cipher2.clone()
4733        { print!("{:02X} ", c); }
4734    println!();
4735    let mut txt = String::new();
4736    for c in cipher2.clone()
4737        { write!(txt, "{:02X} ", c); }
4738    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4739
4740    let mut recovered1 = [0u8; 56];
4741    let mut recovered2 = [0u8; 56];
4742    let len1 = c_des.decrypt_vec_into_array(&cipher1, &mut recovered1);
4743    let len2 = d_des.decrypt_vec_into_array(&cipher2, &mut recovered2);
4744    print!("B1a (0 rounds) =\t");
4745    for b in recovered1.clone()
4746        { print!("{:02X} ", b); }
4747    println!();
4748    let mut txt = String::new();
4749    for c in recovered1.clone()
4750        { write!(txt, "{:02X} ", c); }
4751    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4752    print!("B2a (0 rounds) =\t");
4753    for b in recovered2.clone()
4754        { print!("{:02X} ", b); }
4755    println!();
4756    let mut txt = String::new();
4757    for c in recovered.clone()
4758        { write!(txt, "{:02X} ", c); }
4759    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4760
4761    let mut converted1 = String::new();
4762    let mut converted2 = String::new();
4763    unsafe { converted1.as_mut_vec() }.write(&recovered1);
4764    unsafe { converted2.as_mut_vec() }.write(&recovered2);
4765    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
4766    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
4767    println!("B1b (0 rounds) =\t{}", converted1);
4768    println!("B2b (0 rounds) =\t{}", converted2);
4769    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4770    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4771    assert_eq!(converted1, message);
4772    assert_eq!(converted2, message);
4773    assert_eq!(converted1, converted2);
4774    println!();
4775
4776    // Normal case for the message of 0 bytes
4777    let key = 0x_1234567890ABCDEF_u64;
4778    println!("K =\t{:#016X}", key);
4779    let mut a_des = DES::new_with_key_u64(key);
4780
4781    let message = "";
4782    println!("M =\t{}", message);
4783    let mut cipher = Vec::<u8>::new();
4784    a_des.encrypt_str_into_vec(&message, &mut cipher);
4785    print!("C =\t");
4786    for c in cipher.clone()
4787        { print!("{:02X} ", c); }
4788    println!();
4789    let mut txt = String::new();
4790    for c in cipher.clone()
4791        { write!(txt, "{:02X} ", c); }
4792    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4793
4794    let mut recovered = [0u8; 8];
4795    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4796
4797    print!("Ba =\t");
4798    for b in recovered.clone()
4799        { print!("{:02X} ", b); }
4800    println!();
4801    let mut txt = String::new();
4802    for c in recovered.clone()
4803        { write!(txt, "{:02X} ", c); }
4804    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4805
4806    let mut converted = String::new();
4807    unsafe { converted.as_mut_vec() }.write(&recovered);
4808    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4809    println!("Bb =\t{}", converted);
4810    assert_eq!(converted, "");
4811    assert_eq!(converted, message);
4812    println!();
4813
4814    // Normal case for the message shorter than 8 bytes
4815    let key = 0x_1234567890ABCDEF_u64;
4816    println!("K =\t{:#016X}", key);
4817    let mut a_des = DES::new_with_key_u64(key);
4818
4819    let message = "7 bytes";
4820    println!("M =\t{}", message);
4821    let mut cipher = Vec::<u8>::new();
4822    a_des.encrypt_str_into_vec(&message, &mut cipher);
4823    print!("C =\t");
4824    for c in cipher.clone()
4825        { print!("{:02X} ", c); }
4826    println!();
4827    let mut txt = String::new();
4828    for c in cipher.clone()
4829        { write!(txt, "{:02X} ", c); }
4830    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4831
4832    let mut recovered = [0u8; 8];
4833    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4834
4835    print!("Ba =\t");
4836    for b in recovered.clone()
4837        { print!("{:02X} ", b); }
4838    println!();
4839    let mut txt = String::new();
4840    for c in recovered.clone()
4841        { write!(txt, "{:02X} ", c); }
4842    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4843
4844    let mut converted = String::new();
4845    unsafe { converted.as_mut_vec() }.write(&recovered);
4846    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4847    println!("Bb =\t{}", converted);
4848    assert_eq!(converted, "7 bytes");
4849    assert_eq!(converted, message);
4850    println!();
4851
4852    // Normal case for the message of 8 bytes
4853    let key = 0x_1234567890ABCDEF_u64;
4854    println!("K =\t{:#016X}", key);
4855    let mut a_des = DES::new_with_key_u64(key);
4856
4857    let message = "I am OK.";
4858    println!("M =\t{}", message);
4859    let mut cipher = Vec::<u8>::new();
4860    a_des.encrypt_str_into_vec(&message, &mut cipher);
4861    print!("C =\t");
4862    for c in cipher.clone()
4863        { print!("{:02X} ", c); }
4864    println!();
4865    let mut txt = String::new();
4866    for c in cipher.clone()
4867        { write!(txt, "{:02X} ", c); }
4868    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4869
4870    let mut recovered = [0u8; 16];
4871    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4872
4873    print!("Ba =\t");
4874    for b in recovered.clone()
4875        { print!("{:02X} ", b); }
4876    println!();
4877    let mut txt = String::new();
4878    for c in recovered.clone()
4879        { write!(txt, "{:02X} ", c); }
4880    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4881
4882    let mut converted = String::new();
4883    unsafe { converted.as_mut_vec() }.write(&recovered);
4884    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4885    println!("Bb =\t{}", converted);
4886    assert_eq!(converted, "I am OK.");
4887    assert_eq!(converted, message);
4888    println!();
4889
4890    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4891    let key = 0x_1234567890ABCDEF_u64;
4892    println!("K =\t{:#016X}", key);
4893    let mut a_des = DES::new_with_key_u64(key);
4894
4895    let message = "PARK Youngho";
4896    println!("M =\t{}", message);
4897    let mut cipher = Vec::<u8>::new();
4898    a_des.encrypt_str_into_vec(&message, &mut cipher);
4899    print!("C =\t");
4900    for c in cipher.clone()
4901        { print!("{:02X} ", c); }
4902    println!();
4903    let mut txt = String::new();
4904    for c in cipher.clone()
4905        { write!(txt, "{:02X} ", c); }
4906    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4907
4908    let mut recovered = [0u8; 16];
4909    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4910
4911    print!("Ba =\t");
4912    for b in recovered.clone()
4913        { print!("{:02X} ", b); }
4914    println!();
4915    let mut txt = String::new();
4916    for c in recovered.clone()
4917        { write!(txt, "{:02X} ", c); }
4918    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4919
4920    let mut converted = String::new();
4921    unsafe { converted.as_mut_vec() }.write(&recovered);
4922    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4923    println!("Bb =\t{}", converted);
4924    assert_eq!(converted, "PARK Youngho");
4925    assert_eq!(converted, message);
4926    println!();
4927
4928    // Normal case for the message of 16 bytes
4929    let key = 0x_1234567890ABCDEF_u64;
4930    println!("K =\t{:#016X}", key);
4931    let mut a_des = DES::new_with_key_u64(key);
4932
4933    let message = "고맙습니다.";
4934    println!("M =\t{}", message);
4935    let mut cipher = Vec::<u8>::new();
4936    a_des.encrypt_str_into_vec(&message, &mut cipher);
4937    print!("C =\t");
4938    for c in cipher.clone()
4939        { print!("{:02X} ", c); }
4940    println!();
4941    let mut txt = String::new();
4942    for c in cipher.clone()
4943        { write!(txt, "{:02X} ", c); }
4944    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4945
4946    let mut recovered = [0u8; 24];
4947    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4948
4949    print!("Ba =\t");
4950    for b in recovered.clone()
4951        { print!("{:02X} ", b); }
4952    println!();
4953    let mut txt = String::new();
4954    for c in recovered.clone()
4955        { write!(txt, "{:02X} ", c); }
4956    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4957
4958    let mut converted = String::new();
4959    unsafe { converted.as_mut_vec() }.write(&recovered);
4960    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4961    println!("Bb =\t{}", converted);
4962    assert_eq!(converted, "고맙습니다.");
4963    assert_eq!(converted, message);
4964    println!("-------------------------------");
4965}
4966
4967fn des_decrypt_vec_with_padding_iso_ecb_into_string()
4968{
4969    println!("des_decrypt_vec_with_padding_iso_ecb_into_string()");
4970    use std::io::Write;
4971    use std::fmt::Write as _;
4972    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4973
4974    // Normal case
4975    let key = 0x_1234567890ABCDEF_u64;
4976    println!("K =\t{:#016X}", key);
4977    let mut a_des = DES::new_with_key_u64(key);
4978
4979    let message = "In the beginning God created the heavens and the earth.";
4980    println!("M =\t{}", message);
4981    let mut cipher = Vec::<u8>::new();
4982    a_des.encrypt_str_into_vec(&message, &mut cipher);
4983    print!("C (16 rounds) =\t");
4984    for c in cipher.clone()
4985        { print!("{:02X} ", c); }
4986    println!();
4987    let mut txt = String::new();
4988    for c in cipher.clone()
4989        { write!(txt, "{:02X} ", c); }
4990    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4991
4992    let mut recovered = String::new();
4993    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
4994    println!("B (16 rounds) =\t{}", recovered);
4995    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4996    assert_eq!(recovered, message);
4997    println!();
4998
4999    // Expanded case for 128 rounds
5000    let key = 0x_1234567890ABCDEF_u64;
5001    println!("K =\t{:#016X}", key);
5002    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5003
5004    let message = "In the beginning God created the heavens and the earth.";
5005    println!("M =\t{}", message);
5006    let mut cipher = Vec::<u8>::new();
5007    a_des.encrypt_str_into_vec(&message, &mut cipher);
5008    print!("C (128 rounds) =\t");
5009    for c in cipher.clone()
5010        { print!("{:02X} ", c); }
5011    println!();
5012    let mut txt = String::new();
5013    for c in cipher.clone()
5014        { write!(txt, "{:02X} ", c); }
5015    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5016
5017    let mut recovered = String::new();
5018    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5019    println!("B (128 rounds) =\t{}", recovered);
5020    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5021    assert_eq!(recovered, message);
5022    println!();
5023
5024    // Expanded case for 0 rounds which means that key is meaningless
5025    let key1 = 0x_1234567890ABCDEF_u64;
5026    let key2 = 0_u64;
5027    println!("K =\t{:#016X}", key);
5028    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5029    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5030
5031    let message = "In the beginning God created the heavens and the earth.";
5032    println!("M =\t{}", message);
5033    let mut cipher1 = Vec::<u8>::new();
5034    let mut cipher2 = Vec::<u8>::new();
5035    c_des.encrypt_str_into_vec(&message, &mut cipher1);
5036    d_des.encrypt_str_into_vec(&message, &mut cipher2);
5037    print!("C (0 rounds) =\t");
5038    for c in cipher1.clone()
5039        { print!("{:02X} ", c); }
5040    println!();
5041    let mut txt = String::new();
5042    for c in cipher1.clone()
5043        { write!(txt, "{:02X} ", c); }
5044    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5045    print!("D (0 rounds) =\t");
5046    for c in cipher2.clone()
5047        { print!("{:02X} ", c); }
5048    println!();
5049    let mut txt = String::new();
5050    for c in cipher2.clone()
5051        { write!(txt, "{:02X} ", c); }
5052    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5053
5054    let mut recovered1 = String::new();
5055    let mut recovered2 = String::new();
5056    c_des.decrypt_vec_into_string(&cipher1, &mut recovered1);
5057    d_des.decrypt_vec_into_string(&cipher2, &mut recovered2);
5058    println!("B1 (0 rounds) =\t{}", recovered1);
5059    println!("B2 (0 rounds) =\t{}", recovered2);
5060    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5061    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5062    assert_eq!(recovered1, message);
5063    assert_eq!(recovered2, message);
5064    assert_eq!(recovered1, recovered2);
5065    println!();
5066
5067    // Normal case for the message of 0 bytes
5068    let key = 0x_1234567890ABCDEF_u64;
5069    println!("K =\t{:#016X}", key);
5070    let mut a_des = DES::new_with_key_u64(key);
5071
5072    let message = "";
5073    println!("M =\t{}", message);
5074    let mut cipher = Vec::<u8>::new();
5075    a_des.encrypt_str_into_vec(&message, &mut cipher);
5076    print!("C =\t");
5077    for c in cipher.clone()
5078        { print!("{:02X} ", c); }
5079    println!();
5080    let mut txt = String::new();
5081    for c in cipher.clone()
5082        { write!(txt, "{:02X} ", c); }
5083    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5084
5085    let mut recovered = String::new();
5086    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5087    println!("B =\t{}", recovered);
5088    assert_eq!(recovered, "");
5089    assert_eq!(recovered, message);
5090    println!();
5091
5092    // Normal case for the message shorter than 8 bytes
5093    let key = 0x_1234567890ABCDEF_u64;
5094    println!("K =\t{:#016X}", key);
5095    let mut a_des = DES::new_with_key_u64(key);
5096
5097    let message = "7 bytes";
5098    println!("M =\t{}", message);
5099    let mut cipher = Vec::<u8>::new();
5100    a_des.encrypt_str_into_vec(&message, &mut cipher);
5101    print!("C =\t");
5102    for c in cipher.clone()
5103        { print!("{:02X} ", c); }
5104    println!();
5105    let mut txt = String::new();
5106    for c in cipher.clone()
5107        { write!(txt, "{:02X} ", c); }
5108    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5109
5110    let mut recovered = String::new();
5111    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5112    println!("B =\t{}", recovered);
5113    assert_eq!(recovered, "7 bytes");
5114    assert_eq!(recovered, message);
5115    println!();
5116
5117    // Normal case for the message of 8 bytes
5118    let key = 0x_1234567890ABCDEF_u64;
5119    println!("K =\t{:#016X}", key);
5120    let mut a_des = DES::new_with_key_u64(key);
5121
5122    let message = "I am OK.";
5123    println!("M =\t{}", message);
5124    let mut cipher = Vec::<u8>::new();
5125    a_des.encrypt_str_into_vec(&message, &mut cipher);
5126    print!("C =\t");
5127    for c in cipher.clone()
5128        { print!("{:02X} ", c); }
5129    println!();
5130    let mut txt = String::new();
5131    for c in cipher.clone()
5132        { write!(txt, "{:02X} ", c); }
5133    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5134
5135    let mut recovered = String::new();
5136    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5137    println!("B =\t{}", recovered);
5138    assert_eq!(recovered, "I am OK.");
5139    assert_eq!(recovered, message);
5140    println!();
5141
5142    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5143    let key = 0x_1234567890ABCDEF_u64;
5144    println!("K =\t{:#016X}", key);
5145    let mut a_des = DES::new_with_key_u64(key);
5146
5147    let message = "PARK Youngho";
5148    println!("M =\t{}", message);
5149    let mut cipher = Vec::<u8>::new();
5150    a_des.encrypt_str_into_vec(&message, &mut cipher);
5151    print!("C =\t");
5152    for c in cipher.clone()
5153        { print!("{:02X} ", c); }
5154    println!();
5155    let mut txt = String::new();
5156    for c in cipher.clone()
5157        { write!(txt, "{:02X} ", c); }
5158    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5159
5160    let mut recovered = String::new();
5161    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5162    println!("B =\t{}", recovered);
5163    assert_eq!(recovered, "PARK Youngho");
5164    assert_eq!(recovered, message);
5165    println!();
5166
5167    // Normal case for the message of 16 bytes
5168    let key = 0x_1234567890ABCDEF_u64;
5169    println!("K =\t{:#016X}", key);
5170    let mut a_des = DES::new_with_key_u64(key);
5171
5172    let message = "고맙습니다.";
5173    println!("M =\t{}", message);
5174    let mut cipher = Vec::<u8>::new();
5175    a_des.encrypt_str_into_vec(&message, &mut cipher);
5176    print!("C =\t");
5177    for c in cipher.clone()
5178        { print!("{:02X} ", c); }
5179    println!();
5180    let mut txt = String::new();
5181    for c in cipher.clone()
5182        { write!(txt, "{:02X} ", c); }
5183    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5184
5185    let mut recovered = String::new();
5186    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5187    println!("B =\t{}", recovered);
5188    assert_eq!(recovered, "고맙습니다.");
5189    assert_eq!(recovered, message);
5190    println!("-------------------------------");
5191}
Source

fn encrypt_str_into_array<U, const N: usize>( &mut self, message: &str, cipher: &mut [U; N], ) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data in a str object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in array [U; N].

§Arguments
  • message is an immutable reference to str object which is &str, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to an array [U; N] object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is a null string “”, only padding bytes will be encrypted, and stored in the array [U; N] object cipher.
  • If U::size_in_bytes() * N is less than message.len()’s next multiple of size_of::<T>(), this method does not perform encryption but returns zero.
  • If U::size_in_bytes() * N is equal to message.len()’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and returns the size of the ciphertext including padding bits in bytes.
  • If U::size_in_bytes() * N is greater than message.len()’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and then fills the rest of the elements of the array cipher with zeros, and returns the size of the ciphertext including padding bits in bytes.
  • The size of the area for ciphertext should be prepared to be (message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_str_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
let mut cipher = [0_u8; 64];
taes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
let mut cipher = [0_u8; 56];
tdes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 196)
183fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()
184{
185    println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()");
186    use std::io::Write;
187    use std::fmt::Write as _;
188    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
189
190    // TDES case
191    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
192                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
193                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194    let message = "In the beginning God created the heavens and the earth.";
195    let mut cipher = [0_u8; 56];
196    tdes.encrypt_str_into_array(&message, &mut cipher);
197    print!("C =\t");
198    for c in cipher.clone()
199        { print!("{:02X} ", c); }
200    println!();
201    let mut txt = String::new();
202    for c in cipher.clone()
203        { write!(txt, "{:02X} ", c); }
204    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
205    println!("-------------------------------");
206}
207
208fn bigcryptor64_encrypt_string_with_padding_iso_ecb()
209{
210    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb()");
211    use std::io::Write;
212    use std::fmt::Write as _;
213    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
214
215    // TDES case
216    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219    let message = "In the beginning God created the heavens and the earth.".to_string();
220    let mut cipher = [0_u8; 56];
221    tdes.encrypt_string(&message, cipher.as_mut_ptr());
222    print!("C =\t");
223    for c in cipher.clone()
224        { print!("{:02X} ", c); }
225    println!();
226    let mut txt = String::new();
227    for c in cipher.clone()
228        { write!(txt, "{:02X} ", c); }
229    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230    println!("-------------------------------");
231}
232
233fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()
234{
235    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()");
236    use std::io::Write;
237    use std::fmt::Write as _;
238    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
239
240    // TDES case
241    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244    let message = "In the beginning God created the heavens and the earth.".to_string();
245    let mut cipher = Vec::<u8>::new();
246    tdes.encrypt_string_into_vec(&message, &mut cipher);
247    print!("C =\t");
248    for c in cipher.clone()
249        { print!("{:02X} ", c); }
250    println!();
251    let mut txt = String::new();
252    for c in cipher.clone()
253        { write!(txt, "{:02X} ", c); }
254    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255    println!("-------------------------------");
256}
257
258fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()
259{
260    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()");
261    use std::io::Write;
262    use std::fmt::Write as _;
263    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
264
265    // TDES case
266    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269    let message = "In the beginning God created the heavens and the earth.".to_string();
270    let mut cipher = [0_u8; 56];
271    tdes.encrypt_string_into_array(&message, &mut cipher);
272    print!("C =\t");
273    for c in cipher.clone()
274        { print!("{:02X} ", c); }
275    println!();
276    let mut txt = String::new();
277    for c in cipher.clone()
278        { write!(txt, "{:02X} ", c); }
279    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280    println!("-------------------------------");
281}
282
283fn bigcryptor64_encrypt_vec_with_padding_iso_ecb()
284{
285    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb()");
286    use std::io::Write;
287    use std::fmt::Write as _;
288    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
289
290    // TDES case
291    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294    let message = "In the beginning God created the heavens and the earth.";
295    println!("M =\t{}", message);
296    let message = unsafe { message.to_string().as_mut_vec().clone() };
297    let mut cipher = [0_u8; 56];
298    tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299    print!("C =\t");
300    for c in cipher.clone()
301        { print!("{:02X} ", c); }
302    println!();
303    let mut txt = String::new();
304    for c in cipher.clone()
305        { write!(txt, "{:02X} ", c); }
306    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307    println!("-------------------------------");
308}
309
310fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()
311{
312    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()");
313    use std::io::Write;
314    use std::fmt::Write as _;
315    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
316
317    // TDES case
318    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321    let message = "In the beginning God created the heavens and the earth.";
322    println!("M =\t{}", message);
323    let message = unsafe { message.to_string().as_mut_vec().clone() };
324    let mut cipher = Vec::<u8>::new();
325    tdes.encrypt_vec_into_vec(&message, &mut cipher);
326    print!("C =\t");
327    for c in cipher.clone()
328        { print!("{:02X} ", c); }
329    println!();
330    let mut txt = String::new();
331    for c in cipher.clone()
332        { write!(txt, "{:02X} ", c); }
333    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334    println!("-------------------------------");
335}
336
337fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()
338{
339    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()");
340    use std::io::Write;
341    use std::fmt::Write as _;
342    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
343
344    // TDES case
345    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348    let message = "In the beginning God created the heavens and the earth.";
349    println!("M =\t{}", message);
350    let message = unsafe { message.to_string().as_mut_vec().clone() };
351    let mut cipher = [0_u8; 56];
352    tdes.encrypt_vec_into_array(&message, &mut cipher);
353    print!("C =\t");
354    for c in cipher.clone()
355        { print!("{:02X} ", c); }
356    println!();
357    let mut txt = String::new();
358    for c in cipher.clone()
359        { write!(txt, "{:02X} ", c); }
360    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361    println!("-------------------------------");
362}
363
364fn bigcryptor64_encrypt_array_with_padding_iso_ecb()
365{
366    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb()");
367    use std::io::Write;
368    use std::fmt::Write as _;
369    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
370
371    // TDES case
372    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375    let mes = "In the beginning God created the heavens and the earth.";
376    println!("M =\t{}", mes);
377    let mut message = [0_u8; 55];
378    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379    let mut cipher = [0_u8; 56];
380    tdes.encrypt_array(&message, cipher.as_mut_ptr());
381    print!("C =\t");
382    for c in cipher.clone()
383        { print!("{:02X} ", c); }
384    println!();
385    let mut txt = String::new();
386    for c in cipher.clone()
387        { write!(txt, "{:02X} ", c); }
388    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389    println!("-------------------------------");
390}
391
392fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()
393{
394    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()");
395    use std::io::Write;
396    use std::fmt::Write as _;
397    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
398
399    // TDES case
400    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403    let mes = "In the beginning God created the heavens and the earth.";
404    println!("M =\t{}", mes);
405    let mut message = [0_u8; 55];
406    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407    let mut cipher = Vec::<u8>::new();
408    tdes.encrypt_array_into_vec(&message, &mut cipher);
409    print!("C =\t");
410    for c in cipher.clone()
411        { print!("{:02X} ", c); }
412    println!();
413    let mut txt = String::new();
414    for c in cipher.clone()
415        { write!(txt, "{:02X} ", c); }
416    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417    println!("-------------------------------");
418}
419
420fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()
421{
422    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()");
423    use std::io::Write;
424    use std::fmt::Write as _;
425    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
426
427    // TDES case
428    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431    let mes = "In the beginning God created the heavens and the earth.";
432    println!("M =\t{}", mes);
433    let mut message = [0_u8; 55];
434    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435    let mut cipher = [0_u8; 56];
436    tdes.encrypt_array_into_array(&message, &mut cipher);
437    for c in cipher.clone()
438        { print!("{:02X} ", c); }
439    println!();
440    let mut txt = String::new();
441    for c in cipher.clone()
442        { write!(txt, "{:02X} ", c); }
443    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444    println!("-------------------------------");
445}
446
447fn bigcryptor64_decrypt_with_padding_iso_ecb()
448{
449    println!("bigcryptor64_decrypt_with_padding_iso_ecb()");
450    use std::io::Write;
451    use std::fmt::Write as _;
452    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
453
454    // TDES case
455    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
456                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
457                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
458    let message = "In the beginning God created the heavens and the earth.";
459    println!("M =\t{}", message);
460    let mut cipher = Vec::<u8>::new();
461    tdes.encrypt_str_into_vec(&message, &mut cipher);
462    print!("C =\t");
463    for c in cipher.clone()
464        { print!("{:02X} ", c); }
465    println!();
466    let mut txt = String::new();
467    for c in cipher.clone()
468        { write!(txt, "{:02X} ", c); }
469    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
470
471    let mut recovered = vec![0; 55];
472    tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
473    print!("Ba =\t");
474    for b in recovered.clone()
475        { print!("{:02X} ", b); }
476    println!();
477    let mut txt = String::new();
478    for c in recovered.clone()
479        { write!(txt, "{:02X} ", c); }
480    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
481
482    let mut converted = String::new();
483    unsafe { converted.as_mut_vec() }.append(&mut recovered);
484    
485    println!("Bb =\t{}", converted);
486    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
487    assert_eq!(converted, message);
488    println!("-------------------------------");
489}
490
491fn bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()
492{
493    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()");
494    use std::io::Write;
495    use std::fmt::Write as _;
496    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
497
498    // TDES case
499    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502    let message = "In the beginning God created the heavens and the earth.";
503    println!("M =\t{}", message);
504    let mut cipher = Vec::<u8>::new();
505    tdes.encrypt_str_into_vec(&message, &mut cipher);
506    print!("C =\t");
507    for c in cipher.clone()
508        { print!("{:02X} ", c); }
509    println!();
510    let mut txt = String::new();
511    for c in cipher.clone()
512        { write!(txt, "{:02X} ", c); }
513    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515    let mut recovered = Vec::<u8>::new();
516    tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517    print!("Ba =\t");
518    for b in recovered.clone()
519        { print!("{:02X} ", b); }
520    println!();
521    let mut txt = String::new();
522    for c in recovered.clone()
523        { write!(txt, "{:02X} ", c); }
524    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526    let mut converted = String::new();
527    unsafe { converted.as_mut_vec() }.append(&mut recovered);
528    
529    println!("Bb =\t{}", converted);
530    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531    assert_eq!(converted, message);
532    println!("-------------------------------");
533}
534
535fn bigcryptor64_decrypt_with_padding_iso_ecb_into_array()
536{
537    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_array()");
538    use std::io::Write;
539    use std::fmt::Write as _;
540    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
541
542    // TDES case
543    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
544                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
545                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
546    let message = "In the beginning God created the heavens and the earth.";
547    println!("M =\t{}", message);
548    let mut cipher = Vec::<u8>::new();
549    tdes.encrypt_str_into_vec(&message, &mut cipher);
550    print!("C =\t");
551    for c in cipher.clone()
552        { print!("{:02X} ", c); }
553    println!();
554    let mut txt = String::new();
555    for c in cipher.clone()
556        { write!(txt, "{:02X} ", c); }
557    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
558
559    let mut recovered = [0u8; 56];
560    let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
561    print!("Ba =\t");
562    for b in recovered.clone()
563        { print!("{:02X} ", b); }
564    println!();
565    let mut txt = String::new();
566    for c in recovered.clone()
567        { write!(txt, "{:02X} ", c); }
568    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
569
570    let mut converted = String::new();
571    unsafe { converted.as_mut_vec() }.write(&recovered);
572    unsafe { converted.as_mut_vec() }.truncate(len as usize);
573    println!("Bb =\t{}", converted);
574    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
575    assert_eq!(converted, message);
576    println!("-------------------------------");
577}
578
579fn bigcryptor64_decrypt_with_padding_iso_ecb_into_string()
580{
581    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_string()");
582    use std::io::Write;
583    use std::fmt::Write as _;
584    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
585
586    // TDES case
587    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590    let message = "In the beginning God created the heavens and the earth.";
591    println!("M =\t{}", message);
592    let mut cipher = Vec::<u8>::new();
593    tdes.encrypt_str_into_vec(&message, &mut cipher);
594    print!("C =\t");
595    for c in cipher.clone()
596        { print!("{:02X} ", c); }
597    println!();
598    let mut txt = String::new();
599    for c in cipher.clone()
600        { write!(txt, "{:02X} ", c); }
601    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603    let mut recovered = String::new();
604    tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605    println!("B =\t{}", recovered);
606    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607    assert_eq!(recovered, message);
608    println!("-------------------------------");
609}
610
611fn bigcryptor64_decrypt_vec_with_padding_iso_ecb()
612{
613    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb()");
614    use std::io::Write;
615    use std::fmt::Write as _;
616    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
617
618    // TDES case
619    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622    let message = "In the beginning God created the heavens and the earth.";
623    println!("M =\t{}", message);
624    let mut cipher = Vec::<u8>::new();
625    tdes.encrypt_str_into_vec(&message, &mut cipher);
626    print!("C =\t");
627    for c in cipher.clone()
628        { print!("{:02X} ", c); }
629    println!();
630    let mut txt = String::new();
631    for c in cipher.clone()
632        { write!(txt, "{:02X} ", c); }
633    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635    let mut recovered = vec![0; 55];
636    tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637    print!("Ba =\t");
638    for b in recovered.clone()
639        { print!("{:02X} ", b); }
640    println!();
641    let mut txt = String::new();
642    for c in recovered.clone()
643        { write!(txt, "{:02X} ", c); }
644    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646    let mut converted = String::new();
647    unsafe { converted.as_mut_vec() }.append(&mut recovered);
648    
649    println!("Bb =\t{}", converted);
650    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651    assert_eq!(converted, message);
652    println!("-------------------------------");
653}
654
655fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()
656{
657    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()");
658    use std::io::Write;
659    use std::fmt::Write as _;
660    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
661
662    // TDES case
663    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666    let message = "In the beginning God created the heavens and the earth.";
667    println!("M =\t{}", message);
668    let mut cipher = Vec::<u8>::new();
669    tdes.encrypt_str_into_vec(&message, &mut cipher);
670    print!("C =\t");
671    for c in cipher.clone()
672        { print!("{:02X} ", c); }
673    println!();
674    let mut txt = String::new();
675    for c in cipher.clone()
676        { write!(txt, "{:02X} ", c); }
677    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679    let mut recovered = Vec::<u8>::new();
680    tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681    print!("Ba =\t");
682    for b in recovered.clone()
683        { print!("{:02X} ", b); }
684    println!();
685    let mut txt = String::new();
686    for c in recovered.clone()
687        { write!(txt, "{:02X} ", c); }
688    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690    let mut converted = String::new();
691    unsafe { converted.as_mut_vec() }.append(&mut recovered);
692    
693    println!("Bb =\t{}", converted);
694    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695    assert_eq!(converted, message);
696    println!("-------------------------------");
697}
698
699fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()
700{
701    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()");
702    use std::io::Write;
703    use std::fmt::Write as _;
704    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
705
706    // TDES case
707    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710    let message = "In the beginning God created the heavens and the earth.";
711    println!("M =\t{}", message);
712    let mut cipher = Vec::<u8>::new();
713    tdes.encrypt_str_into_vec(&message, &mut cipher);
714    print!("C =\t");
715    for c in cipher.clone()
716        { print!("{:02X} ", c); }
717    println!();
718    let mut txt = String::new();
719    for c in cipher.clone()
720        { write!(txt, "{:02X} ", c); }
721    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723    let mut recovered = [0u8; 56];
724    let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725    print!("Ba =\t");
726    for b in recovered.clone()
727        { print!("{:02X} ", b); }
728    println!();
729    let mut txt = String::new();
730    for c in recovered.clone()
731        { write!(txt, "{:02X} ", c); }
732    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734    let mut converted = String::new();
735    unsafe { converted.as_mut_vec() }.write(&recovered);
736    unsafe { converted.as_mut_vec() }.truncate(len as usize);
737    println!("Bb =\t{}", converted);
738    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739    assert_eq!(converted, message);
740    println!("-------------------------------");
741}
742
743fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()
744{
745    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()");
746    use std::io::Write;
747    use std::fmt::Write as _;
748    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
749
750    // TDES case
751    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754    let message = "In the beginning God created the heavens and the earth.";
755    println!("M =\t{}", message);
756    let mut cipher = Vec::<u8>::new();
757    tdes.encrypt_str_into_vec(&message, &mut cipher);
758    print!("C =\t");
759    for c in cipher.clone()
760        { print!("{:02X} ", c); }
761    println!();
762    let mut txt = String::new();
763    for c in cipher.clone()
764        { write!(txt, "{:02X} ", c); }
765    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767    let mut recovered = String::new();
768    tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769    println!("B =\t{}", recovered);
770    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771    assert_eq!(recovered, message);
772    println!("-------------------------------");
773}
774
775fn bigcryptor64_decrypt_array_with_padding_iso_ecb()
776{
777    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb()");
778    use std::io::Write;
779    use std::fmt::Write as _;
780    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
781
782    // TDES case
783    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
784                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
785                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
786    let message = "In the beginning God created the heavens and the earth.";
787    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
788    tdes.encrypt_str_into_array(&message, &mut cipher);
789    print!("C =\t");
790    for c in cipher.clone()
791        { print!("{:02X} ", c); }
792    println!();
793    let mut txt = String::new();
794    for c in cipher.clone()
795        { write!(txt, "{:02X} ", c); }
796    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
797
798    let mut recovered = vec![0; 55];
799    let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
800    recovered.truncate(len as usize);
801    print!("Ba =\t");
802    for b in recovered.clone()
803        { print!("{:02X} ", b); }
804    println!();
805    let mut txt = String::new();
806    for c in recovered.clone()
807        { write!(txt, "{:02X} ", c); }
808    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
809
810    let mut converted = String::new();
811    unsafe { converted.as_mut_vec() }.append(&mut recovered);
812    
813    println!("Bb =\t{}", converted);
814    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
815    assert_eq!(converted, message);
816    println!("-------------------------------");
817}
818
819fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()
820{
821    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()");
822    use std::io::Write;
823    use std::fmt::Write as _;
824    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
825
826    // TDES case
827    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
828                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
829                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
830    let message = "In the beginning God created the heavens and the earth.";
831    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
832    tdes.encrypt_str_into_array(&message, &mut cipher);
833    print!("C =\t");
834    for c in cipher.clone()
835        { print!("{:02X} ", c); }
836    println!();
837    let mut txt = String::new();
838    for c in cipher.clone()
839        { write!(txt, "{:02X} ", c); }
840    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
841
842    let mut recovered = Vec::<u8>::new();
843    tdes.decrypt_array_into_vec(&cipher, &mut recovered);
844    print!("Ba =\t");
845    for b in recovered.clone()
846        { print!("{:02X} ", b); }
847    println!();
848    let mut txt = String::new();
849    for c in recovered.clone()
850        { write!(txt, "{:02X} ", c); }
851    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
852
853    let mut converted = String::new();
854    unsafe { converted.as_mut_vec() }.append(&mut recovered);
855    
856    println!("Bb =\t{}", converted);
857    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
858    assert_eq!(converted, message);
859    println!("-------------------------------");
860}
861
862fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()
863{
864    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()");
865    use std::io::Write;
866    use std::fmt::Write as _;
867    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
868
869    // TDES case
870    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
871                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
872                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
873    let message = "In the beginning God created the heavens and the earth.";
874    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
875    tdes.encrypt_str_into_array(&message, &mut cipher);
876    print!("C =\t");
877    for c in cipher.clone()
878        { print!("{:02X} ", c); }
879    println!();
880    let mut txt = String::new();
881    for c in cipher.clone()
882        { write!(txt, "{:02X} ", c); }
883    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
884
885    let mut recovered = [0u8; 56];
886    let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
887    print!("Ba =\t");
888    for b in recovered.clone()
889        { print!("{:02X} ", b); }
890    println!();
891    let mut txt = String::new();
892    for c in recovered.clone()
893        { write!(txt, "{:02X} ", c); }
894    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
895
896    let mut converted = String::new();
897    unsafe { converted.as_mut_vec() }.write(&recovered);
898    unsafe { converted.as_mut_vec() }.truncate(len as usize);
899    println!("Bb =\t{}", converted);
900    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
901    assert_eq!(converted, message);
902    println!("-------------------------------");
903}
904
905fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()
906{
907    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()");
908    use std::io::Write;
909    use std::fmt::Write as _;
910    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
911
912    // TDES case
913    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
914                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
915                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
916    let message = "In the beginning God created the heavens and the earth.";
917    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
918    tdes.encrypt_str_into_array(&message, &mut cipher);
919    print!("C =\t");
920    for c in cipher.clone()
921        { print!("{:02X} ", c); }
922    println!();
923    let mut txt = String::new();
924    for c in cipher.clone()
925        { write!(txt, "{:02X} ", c); }
926    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
927
928    let mut recovered = String::new();
929    tdes.decrypt_array_into_string(&cipher, &mut recovered);
930    println!("B =\t{}", recovered);
931    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
932    assert_eq!(recovered, message);
933    println!("-------------------------------");
934}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 208)
193fn bigcryptor128_encrypt_str_with_padding_iso_ecb_into_array()
194{
195    println!("bigcryptor128_encrypt_str_with_padding_iso_ecb_into_array()");
196    use std::io::Write;
197    use std::fmt::Write as _;
198    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
199
200    // TAES_128 case
201    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
202                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
203                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
204    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
205    println!("IV =	{:#034X}", iv);
206    let message = "In the beginning God created the heavens and the earth.";
207    let mut cipher = [0_u8; 64];
208    taes.encrypt_str_into_array(&message, &mut cipher);
209    print!("C =\t");
210    for c in cipher.clone()
211        { print!("{:02X} ", c); }
212    println!();
213    let mut txt = String::new();
214    for c in cipher.clone()
215        { write!(txt, "{:02X} ", c); }
216    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
217    println!("-------------------------------");
218}
219
220fn bigcryptor128_encrypt_string_with_padding_iso_ecb()
221{
222    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb()");
223    use std::io::Write;
224    use std::fmt::Write as _;
225    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
226
227    // TAES_128 case
228    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
229                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
230                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
231    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
232    println!("IV =	{:#034X}", iv);
233    let message = "In the beginning God created the heavens and the earth.".to_string();
234    let mut cipher = [0_u8; 64];
235    taes.encrypt_string(&message, cipher.as_mut_ptr());
236    print!("C =\t");
237    for c in cipher.clone()
238        { print!("{:02X} ", c); }
239    println!();
240    let mut txt = String::new();
241    for c in cipher.clone()
242        { write!(txt, "{:02X} ", c); }
243    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
244    println!("-------------------------------");
245}
246
247fn bigcryptor128_encrypt_string_with_padding_iso_ecb_into_vec()
248{
249    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb_into_vec()");
250    use std::io::Write;
251    use std::fmt::Write as _;
252    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
253
254    // TAES_128 case
255    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
256                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
257                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
258    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
259    println!("IV =	{:#034X}", iv);
260    let message = "In the beginning God created the heavens and the earth.".to_string();
261    let mut cipher = Vec::<u8>::new();
262    taes.encrypt_string_into_vec(&message, &mut cipher);
263    print!("C =\t");
264    for c in cipher.clone()
265        { print!("{:02X} ", c); }
266    println!();
267    let mut txt = String::new();
268    for c in cipher.clone()
269        { write!(txt, "{:02X} ", c); }
270    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
271    println!("-------------------------------");
272}
273
274fn bigcryptor128_encrypt_string_with_padding_iso_ecb_into_array()
275{
276    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb_into_array()");
277    use std::io::Write;
278    use std::fmt::Write as _;
279    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
280
281    // TAES_128 case
282    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
283                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
284                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
285    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
286    println!("IV =	{:#034X}", iv);
287    let message = "In the beginning God created the heavens and the earth.".to_string();
288    let mut cipher = [0_u8; 64];
289    taes.encrypt_string_into_array(&message, &mut cipher);
290    print!("C =\t");
291    for c in cipher.clone()
292        { print!("{:02X} ", c); }
293    println!();
294    let mut txt = String::new();
295    for c in cipher.clone()
296        { write!(txt, "{:02X} ", c); }
297    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
298    println!("-------------------------------");
299}
300
301fn bigcryptor128_encrypt_vec_with_padding_iso_ecb()
302{
303    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb()");
304    use std::io::Write;
305    use std::fmt::Write as _;
306    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
307
308    // TAES_128 case
309    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
310                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
311                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
312    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
313    println!("IV =	{:#034X}", iv);
314    let message = "In the beginning God created the heavens and the earth.";
315    println!("M =\t{}", message);
316    let message = unsafe { message.to_string().as_mut_vec().clone() };
317    let mut cipher = [0_u8; 64];
318    taes.encrypt_vec(&message, cipher.as_mut_ptr());
319    print!("C =\t");
320    for c in cipher.clone()
321        { print!("{:02X} ", c); }
322    println!();
323    let mut txt = String::new();
324    for c in cipher.clone()
325        { write!(txt, "{:02X} ", c); }
326    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
327    println!("-------------------------------");
328}
329
330fn bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_vec()
331{
332    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_vec()");
333    use std::io::Write;
334    use std::fmt::Write as _;
335    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
336
337    // TAES_128 case
338    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
339                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
340                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
341    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
342    println!("IV =	{:#034X}", iv);
343    let message = "In the beginning God created the heavens and the earth.";
344    println!("M =\t{}", message);
345    let message = unsafe { message.to_string().as_mut_vec().clone() };
346    let mut cipher = Vec::<u8>::new();
347    taes.encrypt_vec_into_vec(&message, &mut cipher);
348    print!("C =\t");
349    for c in cipher.clone()
350        { print!("{:02X} ", c); }
351    println!();
352    let mut txt = String::new();
353    for c in cipher.clone()
354        { write!(txt, "{:02X} ", c); }
355    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
356    println!("-------------------------------");
357}
358
359fn bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_array()
360{
361    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_array()");
362    use std::io::Write;
363    use std::fmt::Write as _;
364    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
365
366    // TAES_128 case
367    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
368                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
369                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
370    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
371    println!("IV =	{:#034X}", iv);
372    let message = "In the beginning God created the heavens and the earth.";
373    println!("M =\t{}", message);
374    let message = unsafe { message.to_string().as_mut_vec().clone() };
375    let mut cipher = [0_u8; 64];
376    taes.encrypt_vec_into_array(&message, &mut cipher);
377    print!("C =\t");
378    for c in cipher.clone()
379        { print!("{:02X} ", c); }
380    println!();
381    let mut txt = String::new();
382    for c in cipher.clone()
383        { write!(txt, "{:02X} ", c); }
384    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
385    println!("-------------------------------");
386}
387
388fn bigcryptor128_encrypt_array_with_padding_iso_ecb()
389{
390    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb()");
391    use std::io::Write;
392    use std::fmt::Write as _;
393    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
394
395    // TAES_128 case
396    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
397                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
398                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
399    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
400    println!("IV =	{:#034X}", iv);
401    let mes = "In the beginning God created the heavens and the earth.";
402    println!("M =\t{}", mes);
403    let mut message = [0_u8; 55];
404    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405    let mut cipher = [0_u8; 64];
406    taes.encrypt_array(&message, cipher.as_mut_ptr());
407    print!("C =\t");
408    for c in cipher.clone()
409        { print!("{:02X} ", c); }
410    println!();
411    let mut txt = String::new();
412    for c in cipher.clone()
413        { write!(txt, "{:02X} ", c); }
414    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
415    println!("-------------------------------");
416}
417
418fn bigcryptor128_encrypt_array_with_padding_iso_ecb_into_vec()
419{
420    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb_into_vec()");
421    use std::io::Write;
422    use std::fmt::Write as _;
423    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
424
425    // TAES_128 case
426    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
427                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
428                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
429    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
430    println!("IV =	{:#034X}", iv);
431    let mes = "In the beginning God created the heavens and the earth.";
432    println!("M =\t{}", mes);
433    let mut message = [0_u8; 55];
434    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435    let mut cipher = Vec::<u8>::new();
436    taes.encrypt_array_into_vec(&message, &mut cipher);
437    print!("C =\t");
438    for c in cipher.clone()
439        { print!("{:02X} ", c); }
440    println!();
441    let mut txt = String::new();
442    for c in cipher.clone()
443        { write!(txt, "{:02X} ", c); }
444    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
445    println!("-------------------------------");
446}
447
448fn bigcryptor128_encrypt_array_with_padding_iso_ecb_into_array()
449{
450    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb_into_array()");
451    use std::io::Write;
452    use std::fmt::Write as _;
453    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
454
455    // TAES_128 case
456    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
457                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
458                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
459    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
460    println!("IV =	{:#034X}", iv);
461    let mes = "In the beginning God created the heavens and the earth.";
462    println!("M =\t{}", mes);
463    let mut message = [0_u8; 55];
464    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465    let mut cipher = [0_u8; 64];
466    taes.encrypt_array_into_array(&message, &mut cipher);
467    for c in cipher.clone()
468        { print!("{:02X} ", c); }
469    println!();
470    let mut txt = String::new();
471    for c in cipher.clone()
472        { write!(txt, "{:02X} ", c); }
473    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
474    println!("-------------------------------");
475}
476
477fn bigcryptor128_decrypt_with_padding_iso_ecb()
478{
479    println!("bigcryptor128_decrypt_with_padding_iso_ecb()");
480    use std::io::Write;
481    use std::fmt::Write as _;
482    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
483
484    // TAES_128 case
485    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
486                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
487                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
488    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
489    println!("IV =	{:#034X}", iv);
490    let message = "In the beginning God created the heavens and the earth.";
491    println!("M =\t{}", message);
492    let mut cipher = Vec::<u8>::new();
493    taes.encrypt_str_into_vec(&message, &mut cipher);
494    print!("C =\t");
495    for c in cipher.clone()
496        { print!("{:02X} ", c); }
497    println!();
498    let mut txt = String::new();
499    for c in cipher.clone()
500        { write!(txt, "{:02X} ", c); }
501    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
502
503    let mut recovered = vec![0; 55];
504    taes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
505    print!("Ba =\t");
506    for b in recovered.clone()
507        { print!("{:02X} ", b); }
508    println!();
509    let mut txt = String::new();
510    for c in recovered.clone()
511        { write!(txt, "{:02X} ", c); }
512    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
513
514    let mut converted = String::new();
515    unsafe { converted.as_mut_vec() }.append(&mut recovered);
516    
517    println!("Bb =\t{}", converted);
518    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
519    assert_eq!(converted, message);
520    println!("-------------------------------");
521}
522
523fn bigcryptor128_decrypt_with_padding_iso_ecb_into_vec()
524{
525    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_vec()");
526    use std::io::Write;
527    use std::fmt::Write as _;
528    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
529
530    // TAES_128 case
531    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
532                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
533                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
534    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
535    println!("IV =	{:#034X}", iv);
536    let message = "In the beginning God created the heavens and the earth.";
537    println!("M =\t{}", message);
538    let mut cipher = Vec::<u8>::new();
539    taes.encrypt_str_into_vec(&message, &mut cipher);
540    print!("C =\t");
541    for c in cipher.clone()
542        { print!("{:02X} ", c); }
543    println!();
544    let mut txt = String::new();
545    for c in cipher.clone()
546        { write!(txt, "{:02X} ", c); }
547    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
548
549    let mut recovered = Vec::<u8>::new();
550    taes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551    print!("Ba =\t");
552    for b in recovered.clone()
553        { print!("{:02X} ", b); }
554    println!();
555    let mut txt = String::new();
556    for c in recovered.clone()
557        { write!(txt, "{:02X} ", c); }
558    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560    let mut converted = String::new();
561    unsafe { converted.as_mut_vec() }.append(&mut recovered);
562    
563    println!("Bb =\t{}", converted);
564    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565    assert_eq!(converted, message);
566    println!("-------------------------------");
567}
568
569fn bigcryptor128_decrypt_with_padding_iso_ecb_into_array()
570{
571    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_array()");
572    use std::io::Write;
573    use std::fmt::Write as _;
574    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
575
576    // TAES_128 case
577    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
578                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
579                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
580    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
581    println!("IV =	{:#034X}", iv);
582    let message = "In the beginning God created the heavens and the earth.";
583    println!("M =\t{}", message);
584    let mut cipher = Vec::<u8>::new();
585    taes.encrypt_str_into_vec(&message, &mut cipher);
586    print!("C =\t");
587    for c in cipher.clone()
588        { print!("{:02X} ", c); }
589    println!();
590    let mut txt = String::new();
591    for c in cipher.clone()
592        { write!(txt, "{:02X} ", c); }
593    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
594
595    let mut recovered = [0u8; 64];
596    let len = taes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
597    print!("Ba =\t");
598    for b in recovered.clone()
599        { print!("{:02X} ", b); }
600    println!();
601    let mut txt = String::new();
602    for c in recovered.clone()
603        { write!(txt, "{:02X} ", c); }
604    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
605
606    let mut converted = String::new();
607    unsafe { converted.as_mut_vec() }.write(&recovered);
608    unsafe { converted.as_mut_vec() }.truncate(len as usize);
609    println!("Bb =\t{}", converted);
610    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
611    assert_eq!(converted, message);
612    println!("-------------------------------");
613}
614
615fn bigcryptor128_decrypt_with_padding_iso_ecb_into_string()
616{
617    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_string()");
618    use std::io::Write;
619    use std::fmt::Write as _;
620    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
621
622    // TAES_128 case
623    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
624                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
625                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
626    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
627    println!("IV =	{:#034X}", iv);
628    let message = "In the beginning God created the heavens and the earth.";
629    println!("M =\t{}", message);
630    let mut cipher = Vec::<u8>::new();
631    taes.encrypt_str_into_vec(&message, &mut cipher);
632    print!("C =\t");
633    for c in cipher.clone()
634        { print!("{:02X} ", c); }
635    println!();
636    let mut txt = String::new();
637    for c in cipher.clone()
638        { write!(txt, "{:02X} ", c); }
639    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
640
641    let mut recovered = String::new();
642    taes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643    println!("B =\t{}", recovered);
644    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645    assert_eq!(recovered, message);
646    println!("-------------------------------");
647}
648
649fn bigcryptor128_decrypt_vec_with_padding_iso_ecb()
650{
651    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb()");
652    use std::io::Write;
653    use std::fmt::Write as _;
654    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
655
656    // TAES_128 case
657    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
658                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
659                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
660    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
661    println!("IV =	{:#034X}", iv);
662    let message = "In the beginning God created the heavens and the earth.";
663    println!("M =\t{}", message);
664    let mut cipher = Vec::<u8>::new();
665    taes.encrypt_str_into_vec(&message, &mut cipher);
666    print!("C =\t");
667    for c in cipher.clone()
668        { print!("{:02X} ", c); }
669    println!();
670    let mut txt = String::new();
671    for c in cipher.clone()
672        { write!(txt, "{:02X} ", c); }
673    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
674
675    let mut recovered = vec![0; 55];
676    taes.decrypt_vec(&cipher, recovered.as_mut_ptr());
677    print!("Ba =\t");
678    for b in recovered.clone()
679        { print!("{:02X} ", b); }
680    println!();
681    let mut txt = String::new();
682    for c in recovered.clone()
683        { write!(txt, "{:02X} ", c); }
684    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686    let mut converted = String::new();
687    unsafe { converted.as_mut_vec() }.append(&mut recovered);
688    
689    println!("Bb =\t{}", converted);
690    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691    assert_eq!(converted, message);
692    println!("-------------------------------");
693}
694
695fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_vec()
696{
697    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_vec()");
698    use std::io::Write;
699    use std::fmt::Write as _;
700    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
701
702    // TAES_128 case
703    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
704                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
705                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
706    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
707    println!("IV =	{:#034X}", iv);
708    let message = "In the beginning God created the heavens and the earth.";
709    println!("M =\t{}", message);
710    let mut cipher = Vec::<u8>::new();
711    taes.encrypt_str_into_vec(&message, &mut cipher);
712    print!("C =\t");
713    for c in cipher.clone()
714        { print!("{:02X} ", c); }
715    println!();
716    let mut txt = String::new();
717    for c in cipher.clone()
718        { write!(txt, "{:02X} ", c); }
719    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
720
721    let mut recovered = Vec::<u8>::new();
722    taes.decrypt_vec_into_vec(&cipher, &mut recovered);
723    print!("Ba =\t");
724    for b in recovered.clone()
725        { print!("{:02X} ", b); }
726    println!();
727    let mut txt = String::new();
728    for c in recovered.clone()
729        { write!(txt, "{:02X} ", c); }
730    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732    let mut converted = String::new();
733    unsafe { converted.as_mut_vec() }.append(&mut recovered);
734    
735    println!("Bb =\t{}", converted);
736    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737    assert_eq!(converted, message);
738    println!("-------------------------------");
739}
740
741fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_array()
742{
743    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_array()");
744    use std::io::Write;
745    use std::fmt::Write as _;
746    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
747
748    // TAES_128 case
749    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
750                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
751                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
752    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
753    println!("IV =	{:#034X}", iv);
754    let message = "In the beginning God created the heavens and the earth.";
755    println!("M =\t{}", message);
756    let mut cipher = Vec::<u8>::new();
757    taes.encrypt_str_into_vec(&message, &mut cipher);
758    print!("C =\t");
759    for c in cipher.clone()
760        { print!("{:02X} ", c); }
761    println!();
762    let mut txt = String::new();
763    for c in cipher.clone()
764        { write!(txt, "{:02X} ", c); }
765    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
766
767    let mut recovered = [0u8; 64];
768    let len = taes.decrypt_vec_into_array(&cipher, &mut recovered);
769    print!("Ba =\t");
770    for b in recovered.clone()
771        { print!("{:02X} ", b); }
772    println!();
773    let mut txt = String::new();
774    for c in recovered.clone()
775        { write!(txt, "{:02X} ", c); }
776    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
777
778    let mut converted = String::new();
779    unsafe { converted.as_mut_vec() }.write(&recovered);
780    unsafe { converted.as_mut_vec() }.truncate(len as usize);
781    println!("Bb =\t{}", converted);
782    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783    assert_eq!(converted, message);
784    println!("-------------------------------");
785}
786
787fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_string()
788{
789    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_string()");
790    use std::io::Write;
791    use std::fmt::Write as _;
792    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
793
794    // TAES_128 case
795    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
796                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
797                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
798    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
799    println!("IV =	{:#034X}", iv);
800    let message = "In the beginning God created the heavens and the earth.";
801    println!("M =\t{}", message);
802    let mut cipher = Vec::<u8>::new();
803    taes.encrypt_str_into_vec(&message, &mut cipher);
804    print!("C =\t");
805    for c in cipher.clone()
806        { print!("{:02X} ", c); }
807    println!();
808    let mut txt = String::new();
809    for c in cipher.clone()
810        { write!(txt, "{:02X} ", c); }
811    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
812
813    let mut recovered = String::new();
814    taes.decrypt_vec_into_string(&cipher, &mut recovered);
815    println!("B =\t{}", recovered);
816    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817    assert_eq!(recovered, message);
818    println!("-------------------------------");
819}
820
821fn bigcryptor128_decrypt_array_with_padding_iso_ecb()
822{
823    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb()");
824    use std::io::Write;
825    use std::fmt::Write as _;
826    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
827
828    // TAES_128 case
829    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
830                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
831                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
832    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
833    println!("IV =	{:#034X}", iv);
834    let message = "In the beginning God created the heavens and the earth.";
835        println!("M =\t{}", message);
836    let mut cipher = [0_u8; 64];
837    taes.encrypt_str_into_array(&message, &mut cipher);
838    print!("C =\t");
839    for c in cipher.clone()
840        { print!("{:02X} ", c); }
841    println!();
842    let mut txt = String::new();
843    for c in cipher.clone()
844        { write!(txt, "{:02X} ", c); }
845    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
846
847    let mut recovered = vec![0; 55];
848    let len = taes.decrypt_array(&cipher, recovered.as_mut_ptr());
849    recovered.truncate(len as usize);
850    print!("Ba =\t");
851    for b in recovered.clone()
852        { print!("{:02X} ", b); }
853    println!();
854    let mut txt = String::new();
855    for c in recovered.clone()
856        { write!(txt, "{:02X} ", c); }
857    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
858
859    let mut converted = String::new();
860    unsafe { converted.as_mut_vec() }.append(&mut recovered);
861    
862    println!("Bb =\t{}", converted);
863    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
864    assert_eq!(converted, message);
865    println!("-------------------------------");
866}
867
868fn bigcryptor128_decrypt_array_with_padding_iso_ecb_into_vec()
869{
870    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb_into_vec()");
871    use std::io::Write;
872    use std::fmt::Write as _;
873    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
874
875    // TAES_128 case
876    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
877                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
878                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
879    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
880    println!("IV =	{:#034X}", iv);
881    let message = "In the beginning God created the heavens and the earth.";
882    println!("M =\t{}", message);
883    let mut cipher = [0_u8; 64];
884    taes.encrypt_str_into_array(&message, &mut cipher);
885    print!("C =\t");
886    for c in cipher.clone()
887        { print!("{:02X} ", c); }
888    println!();
889    let mut txt = String::new();
890    for c in cipher.clone()
891        { write!(txt, "{:02X} ", c); }
892    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
893
894    let mut recovered = Vec::<u8>::new();
895    taes.decrypt_array_into_vec(&cipher, &mut recovered);
896    print!("Ba =\t");
897    for b in recovered.clone()
898        { print!("{:02X} ", b); }
899    println!();
900    let mut txt = String::new();
901    for c in recovered.clone()
902        { write!(txt, "{:02X} ", c); }
903    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
904
905    let mut converted = String::new();
906    unsafe { converted.as_mut_vec() }.append(&mut recovered);
907    
908    println!("Bb =\t{}", converted);
909    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
910    assert_eq!(converted, message);
911    println!("-------------------------------");
912}
913
914fn bigcryptor128_decrypt_array_with_padding_iso_ecb_into_array()
915{
916    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb_into_array()");
917    use std::io::Write;
918    use std::fmt::Write as _;
919    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
920
921    // TAES_128 case
922    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
923                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
924                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
925    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
926    println!("IV =	{:#034X}", iv);
927    let message = "In the beginning God created the heavens and the earth.";
928        println!("M =\t{}", message);
929    let mut cipher = [0_u8; 64];
930    taes.encrypt_str_into_array(&message, &mut cipher);
931    print!("C =\t");
932    for c in cipher.clone()
933        { print!("{:02X} ", c); }
934    println!();
935    let mut txt = String::new();
936    for c in cipher.clone()
937        { write!(txt, "{:02X} ", c); }
938    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
939
940    let mut recovered = [0u8; 64];
941    let len = taes.decrypt_array_into_array(&cipher, &mut recovered);
942    print!("Ba =\t");
943    for b in recovered.clone()
944        { print!("{:02X} ", b); }
945    println!();
946    let mut txt = String::new();
947    for c in recovered.clone()
948        { write!(txt, "{:02X} ", c); }
949    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
950
951    let mut converted = String::new();
952    unsafe { converted.as_mut_vec() }.write(&recovered);
953    unsafe { converted.as_mut_vec() }.truncate(len as usize);
954    println!("Bb =\t{}", converted);
955    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
956    assert_eq!(converted, message);
957    println!("-------------------------------");
958}
959
960fn bigcryptor128_decrypt_array_with_padding_iso_ecb_into_string()
961{
962    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb_into_string()");
963    use std::io::Write;
964    use std::fmt::Write as _;
965    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
966
967    // TAES_128 case
968    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
969                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
970                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
971    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
972    println!("IV =	{:#034X}", iv);
973    let message = "In the beginning God created the heavens and the earth.";
974    println!("M =\t{}", message);
975    let mut cipher = [0_u8; 64];
976    taes.encrypt_str_into_array(&message, &mut cipher);
977    print!("C =\t");
978    for c in cipher.clone()
979        { print!("{:02X} ", c); }
980    println!();
981    let mut txt = String::new();
982    for c in cipher.clone()
983        { write!(txt, "{:02X} ", c); }
984    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
985
986    let mut recovered = String::new();
987    taes.decrypt_array_into_string(&cipher, &mut recovered);
988    println!("B =\t{}", recovered);
989    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
990    assert_eq!(recovered, message);
991    println!("-------------------------------");
992}
examples/aes_ecb_iso_examples.rs (line 654)
639fn aes_encrypt_str_with_padding_iso_ecb_into_array()
640{
641    println!("aes_encrypt_str_with_padding_iso_ecb_into_array()");
642    use std::io::Write;
643    use std::fmt::Write as _;
644    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
645
646    // Normal case for AES-128
647    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
648    println!("K =\t{:#016X}", key);
649    let mut a_aes = AES_128::new_with_key_u128(key);
650
651    let message = "In the beginning God created the heavens and the earth.";
652    println!("M =\t{}", message);
653    let mut cipher = [0_u8; 64];
654    a_aes.encrypt_str_into_array(&message, &mut cipher);
655    print!("C =\t");
656    for c in cipher.clone()
657        { print!("{:02X} ", c); }
658    println!();
659    let mut txt = String::new();
660    for c in cipher.clone()
661        { write!(txt, "{:02X} ", c); }
662    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
663    println!();
664
665    // Normal case for AES-192
666    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
667    print!("K =\t");
668    for i in 0..24
669        { print!("{:02X}", key[i]); }
670    println!();
671    let mut a_aes = AES_192::new_with_key(&key);
672
673    let message = "In the beginning God created the heavens and the earth.";
674    println!("M =\t{}", message);
675    let mut cipher = [0_u8; 64];
676    a_aes.encrypt_str_into_array(&message, &mut cipher);
677    print!("C =\t");
678    for c in cipher.clone()
679        { print!("{:02X} ", c); }
680    println!();
681    let mut txt = String::new();
682    for c in cipher.clone()
683        { write!(txt, "{:02X} ", c); }
684    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
685    println!();
686
687    // Normal case for AES-256
688    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
689    print!("K =\t");
690    for i in 0..32
691        { print!("{:02X}", key[i]); }
692    println!();
693    let mut a_aes = AES_256::new_with_key(&key);
694
695    let message = "In the beginning God created the heavens and the earth.";
696    println!("M =\t{}", message);
697    let mut cipher = [0_u8; 64];
698    a_aes.encrypt_str_into_array(&message, &mut cipher);
699    print!("C =\t");
700    for c in cipher.clone()
701        { print!("{:02X} ", c); }
702    println!();
703    let mut txt = String::new();
704    for c in cipher.clone()
705        { write!(txt, "{:02X} ", c); }
706    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
707    println!();
708
709    // Normal case for Rijndael-256-256
710    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
711    print!("K =\t");
712    for i in 0..32
713        { print!("{:02X}", key[i]); }
714    println!();
715    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
716
717    let message = "In the beginning God created the heavens and the earth.";
718    println!("M =\t{}", message);
719    let mut cipher = [0_u8; 64];
720    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
721    print!("C =\t");
722    for c in cipher.clone()
723        { print!("{:02X} ", c); }
724    println!();
725    let mut txt = String::new();
726    for c in cipher.clone()
727        { write!(txt, "{:02X} ", c); }
728    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
729    println!();
730
731    // Normal case for Rijndael-512-512 for post-quantum
732    use cryptocol::number::SharedArrays;
733    use cryptocol::hash::SHA3_512;
734    let mut sha3 = SHA3_512::new();
735    sha3.absorb_str("Post-quantum");
736    let key: [u8; 64] = sha3.get_hash_value_in_array();
737    print!("K =\t");
738    for i in 0..64
739        { print!("{:02X}", key[i]); }
740    println!();
741    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
742    let message = "In the beginning God created the heavens and the earth.";
743    println!("M =\t{}", message);
744    let mut cipher = [0_u8; 64];
745    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
746    print!("C =\t");
747    for c in cipher.clone()
748        { print!("{:02X} ", c); }
749    println!();
750    let mut txt = String::new();
751    for c in cipher.clone()
752        { write!(txt, "{:02X} ", c); }
753    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
754    println!("-------------------------------");
755}
756
757fn aes_encrypt_string_with_padding_iso_ecb()
758{
759    println!("aes_encrypt_string_with_padding_iso_ecb()");
760    use std::io::Write;
761    use std::fmt::Write as _;
762    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
763
764    // Normal case for AES-128
765    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
766    println!("K =\t{:#016X}", key);
767    let mut a_aes = AES_128::new_with_key_u128(key);
768
769    let message = "In the beginning God created the heavens and the earth.".to_string();
770    println!("M =\t{}", message);
771    let mut cipher = [0_u8; 64];
772    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
773    print!("C =\t");
774    for c in cipher.clone()
775        { print!("{:02X} ", c); }
776    println!();
777    let mut txt = String::new();
778    for c in cipher.clone()
779        { write!(txt, "{:02X} ", c); }
780    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
781    println!();
782
783    // Normal case for AES-192
784    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
785    print!("K =\t");
786    for i in 0..24
787        { print!("{:02X}", key[i]); }
788    println!();
789    let mut a_aes = AES_192::new_with_key(&key);
790
791    let message = "In the beginning God created the heavens and the earth.".to_string();
792    println!("M =\t{}", message);
793    let mut cipher = [0_u8; 64];
794    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
795    print!("C =\t");
796    for c in cipher.clone()
797        { print!("{:02X} ", c); }
798    println!();
799    let mut txt = String::new();
800    for c in cipher.clone()
801        { write!(txt, "{:02X} ", c); }
802    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
803    println!();
804
805    // Normal case for AES-256
806    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
807    print!("K =\t");
808    for i in 0..32
809        { print!("{:02X}", key[i]); }
810    println!();
811    let mut a_aes = AES_256::new_with_key(&key);
812
813    let message = "In the beginning God created the heavens and the earth.".to_string();
814    println!("M =\t{}", message);
815    let mut cipher = [0_u8; 64];
816    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
817    print!("C =\t");
818    for c in cipher.clone()
819        { print!("{:02X} ", c); }
820    println!();
821    let mut txt = String::new();
822    for c in cipher.clone()
823        { write!(txt, "{:02X} ", c); }
824    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
825    println!();
826
827    // Normal case for Rijndael-256-256
828    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
829    print!("K =\t");
830    for i in 0..32
831        { print!("{:02X}", key[i]); }
832    println!();
833    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
834
835    let message = "In the beginning God created the heavens and the earth.".to_string();
836    println!("M =\t{}", message);
837    let mut cipher = [0_u8; 64];
838    a_rijndael.encrypt_string(&message, cipher.as_mut_ptr());
839    print!("C =\t");
840    for c in cipher.clone()
841        { print!("{:02X} ", c); }
842    println!();
843    let mut txt = String::new();
844    for c in cipher.clone()
845        { write!(txt, "{:02X} ", c); }
846    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
847    println!();
848
849    // Normal case for Rijndael-512-512 for post-quantum
850    use cryptocol::number::SharedArrays;
851    use cryptocol::hash::SHA3_512;
852    let mut sha3 = SHA3_512::new();
853    sha3.absorb_str("Post-quantum");
854    let key: [u8; 64] = sha3.get_hash_value_in_array();
855    print!("K =\t");
856    for i in 0..64
857        { print!("{:02X}", key[i]); }
858    println!();
859    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
860
861    let message = "In the beginning God created the heavens and the earth.".to_string();
862    println!("M =\t{}", message);
863    let mut cipher = [0_u8; 64];
864    a_rijndael.encrypt_string(&message, cipher.as_mut_ptr());
865    print!("C =\t");
866    for c in cipher.clone()
867        { print!("{:02X} ", c); }
868    println!();
869    let mut txt = String::new();
870    for c in cipher.clone()
871        { write!(txt, "{:02X} ", c); }
872    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
873    println!("-------------------------------");
874}
875
876fn aes_encrypt_string_with_padding_iso_ecb_into_vec()
877{
878    println!("aes_encrypt_string_with_padding_iso_ecb_into_vec()");
879    use std::io::Write;
880    use std::fmt::Write as _;
881    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
882
883    // Normal case for AES-128
884    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
885    println!("K =\t{:#016X}", key);
886    let mut a_aes = AES_128::new_with_key_u128(key);
887
888    let message = "In the beginning God created the heavens and the earth.".to_string();
889    println!("M =\t{}", message);
890    let mut cipher = Vec::<u8>::new();
891    a_aes.encrypt_string_into_vec(&message, &mut cipher);
892    print!("C =\t");
893    for c in cipher.clone()
894        { print!("{:02X} ", c); }
895    println!();
896    let mut txt = String::new();
897    for c in cipher.clone()
898        { write!(txt, "{:02X} ", c); }
899    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
900    println!();
901
902    // Normal case for AES-192
903    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
904    print!("K =\t");
905    for i in 0..24
906        { print!("{:02X}", key[i]); }
907    println!();
908    let mut a_aes = AES_192::new_with_key(&key);
909
910    let message = "In the beginning God created the heavens and the earth.".to_string();
911    println!("M =\t{}", message);
912    let mut cipher = Vec::<u8>::new();
913    a_aes.encrypt_string_into_vec(&message, &mut cipher);
914    print!("C =\t");
915    for c in cipher.clone()
916        { print!("{:02X} ", c); }
917    println!();
918    let mut txt = String::new();
919    for c in cipher.clone()
920        { write!(txt, "{:02X} ", c); }
921    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
922    println!();
923
924    // Normal case for AES-256
925    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
926    print!("K =\t");
927    for i in 0..32
928        { print!("{:02X}", key[i]); }
929    println!();
930    let mut a_aes = AES_256::new_with_key(&key);
931
932    let message = "In the beginning God created the heavens and the earth.".to_string();
933    println!("M =\t{}", message);
934    let mut cipher = Vec::<u8>::new();
935    a_aes.encrypt_string_into_vec(&message, &mut cipher);
936    print!("C =\t");
937    for c in cipher.clone()
938        { print!("{:02X} ", c); }
939    println!();
940    let mut txt = String::new();
941    for c in cipher.clone()
942        { write!(txt, "{:02X} ", c); }
943    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
944    println!();
945
946    // Normal case for Rijndael-256-256
947    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
948    print!("K =\t");
949    for i in 0..32
950        { print!("{:02X}", key[i]); }
951    println!();
952    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
953
954    let message = "In the beginning God created the heavens and the earth.".to_string();
955    println!("M =\t{}", message);
956    let mut cipher = Vec::<u8>::new();
957    a_rijndael.encrypt_string_into_vec(&message, &mut cipher);
958    print!("C =\t");
959    for c in cipher.clone()
960        { print!("{:02X} ", c); }
961    println!();
962    let mut txt = String::new();
963    for c in cipher.clone()
964        { write!(txt, "{:02X} ", c); }
965    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
966    println!();
967
968    // Normal case for Rijndael-512-512 for post-quantum
969    use cryptocol::number::SharedArrays;
970    use cryptocol::hash::SHA3_512;
971    let mut sha3 = SHA3_512::new();
972    sha3.absorb_str("Post-quantum");
973    let key: [u8; 64] = sha3.get_hash_value_in_array();
974    print!("K =\t");
975    for i in 0..64
976        { print!("{:02X}", key[i]); }
977    println!();
978    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
979    let message = "In the beginning God created the heavens and the earth.".to_string();
980    println!("M =\t{}", message);
981    let mut cipher = Vec::<u8>::new();
982    a_rijndael.encrypt_string_into_vec(&message, &mut cipher);
983    print!("C =\t");
984    for c in cipher.clone()
985        { print!("{:02X} ", c); }
986    println!();
987    let mut txt = String::new();
988    for c in cipher.clone()
989        { write!(txt, "{:02X} ", c); }
990    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
991    println!("-------------------------------");
992}
993
994fn aes_encrypt_string_with_padding_iso_ecb_into_array()
995{
996    println!("aes_encrypt_string_with_padding_iso_ecb_into_array()");
997    use std::io::Write;
998    use std::fmt::Write as _;
999    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1000
1001    // Normal case for AES-128
1002    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1003    println!("K =\t{:#016X}", key);
1004    let mut a_aes = AES_128::new_with_key_u128(key);
1005
1006    let message = "In the beginning God created the heavens and the earth.".to_string();
1007    println!("M =\t{}", message);
1008    let mut cipher = [0_u8; 64];
1009    a_aes.encrypt_string_into_array(&message, &mut cipher);
1010    print!("C =\t");
1011    for c in cipher.clone()
1012        { print!("{:02X} ", c); }
1013    println!();
1014    let mut txt = String::new();
1015    for c in cipher.clone()
1016        { write!(txt, "{:02X} ", c); }
1017    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1018    println!();
1019
1020    // Normal case for AES-192
1021    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1022    print!("K =\t");
1023    for i in 0..24
1024        { print!("{:02X}", key[i]); }
1025    println!();
1026    let mut a_aes = AES_192::new_with_key(&key);
1027
1028    let message = "In the beginning God created the heavens and the earth.".to_string();
1029    println!("M =\t{}", message);
1030    let mut cipher = [0_u8; 64];
1031    a_aes.encrypt_string_into_array(&message, &mut cipher);
1032    print!("C =\t");
1033    for c in cipher.clone()
1034        { print!("{:02X} ", c); }
1035    println!();
1036    let mut txt = String::new();
1037    for c in cipher.clone()
1038        { write!(txt, "{:02X} ", c); }
1039    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1040    println!();
1041
1042    // Normal case for AES-256
1043    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1044    print!("K =\t");
1045    for i in 0..32
1046        { print!("{:02X}", key[i]); }
1047    println!();
1048    let mut a_aes = AES_256::new_with_key(&key);
1049
1050    let message = "In the beginning God created the heavens and the earth.".to_string();
1051    println!("M =\t{}", message);
1052    let mut cipher = [0_u8; 64];
1053    a_aes.encrypt_string_into_array(&message, &mut cipher);
1054    print!("C =\t");
1055    for c in cipher.clone()
1056        { print!("{:02X} ", c); }
1057    println!();
1058    let mut txt = String::new();
1059    for c in cipher.clone()
1060        { write!(txt, "{:02X} ", c); }
1061    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1062    println!();
1063
1064    // Normal case for Rijndael-256-256
1065    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1066    print!("K =\t");
1067    for i in 0..32
1068        { print!("{:02X}", key[i]); }
1069    println!();
1070    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1071
1072    let message = "In the beginning God created the heavens and the earth.".to_string();
1073    println!("M =\t{}", message);
1074    let mut cipher = [0_u8; 64];
1075    a_rijndael.encrypt_string_into_array(&message, &mut cipher);
1076    print!("C =\t");
1077    for c in cipher.clone()
1078        { print!("{:02X} ", c); }
1079    println!();
1080    let mut txt = String::new();
1081    for c in cipher.clone()
1082        { write!(txt, "{:02X} ", c); }
1083    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1084    println!();
1085
1086    // Normal case for Rijndael-512-512 for post-quantum
1087    use cryptocol::number::SharedArrays;
1088    use cryptocol::hash::SHA3_512;
1089    let mut sha3 = SHA3_512::new();
1090    sha3.absorb_str("Post-quantum");
1091    let key: [u8; 64] = sha3.get_hash_value_in_array();
1092    print!("K =\t");
1093    for i in 0..64
1094        { print!("{:02X}", key[i]); }
1095    println!();
1096    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1097    let message = "In the beginning God created the heavens and the earth.".to_string();
1098    println!("M =\t{}", message);
1099    let mut cipher = [0_u8; 64];
1100    a_rijndael.encrypt_string_into_array(&message, &mut cipher);
1101    print!("C =\t");
1102    for c in cipher.clone()
1103        { print!("{:02X} ", c); }
1104    println!();
1105    let mut txt = String::new();
1106    for c in cipher.clone()
1107        { write!(txt, "{:02X} ", c); }
1108    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1109    println!("-------------------------------");
1110}
1111
1112fn aes_encrypt_vec_with_padding_iso_ecb()
1113{
1114    println!("aes_encrypt_vec_with_padding_iso_ecb()");
1115    use std::io::Write;
1116    use std::fmt::Write as _;
1117    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1118
1119    // Normal case for AES-128
1120    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1121    println!("K =\t{:#016X}", key);
1122    let mut a_aes = AES_128::new_with_key_u128(key);
1123
1124    let message = "In the beginning God created the heavens and the earth.";
1125    println!("M =\t{}", message);
1126    let message = unsafe { message.to_string().as_mut_vec().clone() };
1127    let mut cipher = [0_u8; 64];
1128    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1129    print!("C =\t");
1130    for c in cipher.clone()
1131        { print!("{:02X} ", c); }
1132    println!();
1133    let mut txt = String::new();
1134    for c in cipher.clone()
1135        { write!(txt, "{:02X} ", c); }
1136    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1137    println!();
1138
1139    // Normal case for AES-192
1140    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1141    print!("K =\t");
1142    for i in 0..24
1143        { print!("{:02X}", key[i]); }
1144    println!();
1145    let mut a_aes = AES_192::new_with_key(&key);
1146
1147    let message = "In the beginning God created the heavens and the earth.";
1148    println!("M =\t{}", message);
1149    let message = unsafe { message.to_string().as_mut_vec().clone() };
1150    let mut cipher = [0_u8; 64];
1151    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1152    print!("C =\t");
1153    for c in cipher.clone()
1154        { print!("{:02X} ", c); }
1155    println!();
1156    let mut txt = String::new();
1157    for c in cipher.clone()
1158        { write!(txt, "{:02X} ", c); }
1159    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1160    println!();
1161
1162    // Normal case for AES-256
1163    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1164    print!("K =\t");
1165    for i in 0..32
1166        { print!("{:02X}", key[i]); }
1167    println!();
1168    let mut a_aes = AES_256::new_with_key(&key);
1169
1170    let message = "In the beginning God created the heavens and the earth.";
1171    println!("M =\t{}", message);
1172    let message = unsafe { message.to_string().as_mut_vec().clone() };
1173    let mut cipher = [0_u8; 64];
1174    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1175    print!("C =\t");
1176    for c in cipher.clone()
1177        { print!("{:02X} ", c); }
1178    println!();
1179    let mut txt = String::new();
1180    for c in cipher.clone()
1181        { write!(txt, "{:02X} ", c); }
1182    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1183    println!();
1184
1185    // Normal case for Rijndael-256-256
1186    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1187    print!("K =\t");
1188    for i in 0..32
1189        { print!("{:02X}", key[i]); }
1190    println!();
1191    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1192
1193    let message = "In the beginning God created the heavens and the earth.";
1194    println!("M =\t{}", message);
1195    let message = unsafe { message.to_string().as_mut_vec().clone() };
1196    let mut cipher = [0_u8; 64];
1197    a_rijndael.encrypt_vec(&message, cipher.as_mut_ptr());
1198    print!("C =\t");
1199    for c in cipher.clone()
1200        { print!("{:02X} ", c); }
1201    println!();
1202    let mut txt = String::new();
1203    for c in cipher.clone()
1204        { write!(txt, "{:02X} ", c); }
1205    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1206    println!();
1207
1208    // Normal case for Rijndael-512-512 for post-quantum
1209    use cryptocol::number::SharedArrays;
1210    use cryptocol::hash::SHA3_512;
1211    let mut sha3 = SHA3_512::new();
1212    sha3.absorb_str("Post-quantum");
1213    let key: [u8; 64] = sha3.get_hash_value_in_array();
1214    print!("K =\t");
1215    for i in 0..64
1216        { print!("{:02X}", key[i]); }
1217    println!();
1218    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1219    let message = "In the beginning God created the heavens and the earth.";
1220    println!("M =\t{}", message);
1221    let message = unsafe { message.to_string().as_mut_vec().clone() };
1222    let mut cipher = [0_u8; 64];
1223    a_rijndael.encrypt_vec(&message, cipher.as_mut_ptr());
1224    print!("C =\t");
1225    for c in cipher.clone()
1226        { print!("{:02X} ", c); }
1227    println!();
1228    let mut txt = String::new();
1229    for c in cipher.clone()
1230        { write!(txt, "{:02X} ", c); }
1231    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1232    println!("-------------------------------");
1233}
1234
1235fn aes_encrypt_vec_with_padding_iso_ecb_into_vec()
1236{
1237    println!("aes_encrypt_vec_with_padding_iso_ecb_into_vec()");
1238    use std::io::Write;
1239    use std::fmt::Write as _;
1240    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1241
1242    // Normal case for AES-128
1243    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1244    println!("K =\t{:#016X}", key);
1245    let mut a_aes = AES_128::new_with_key_u128(key);
1246
1247    let message = "In the beginning God created the heavens and the earth.";
1248    println!("M =\t{}", message);
1249    let message = unsafe { message.to_string().as_mut_vec().clone() };
1250    let mut cipher = Vec::<u8>::new();
1251    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1252    print!("C =\t");
1253    for c in cipher.clone()
1254        { print!("{:02X} ", c); }
1255    println!();
1256    let mut txt = String::new();
1257    for c in cipher.clone()
1258        { write!(txt, "{:02X} ", c); }
1259    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1260    println!();
1261
1262    // Normal case for AES-192
1263    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1264    print!("K =\t");
1265    for i in 0..24
1266        { print!("{:02X}", key[i]); }
1267    println!();
1268    let mut a_aes = AES_192::new_with_key(&key);
1269
1270    let message = "In the beginning God created the heavens and the earth.";
1271    println!("M =\t{}", message);
1272    let message = unsafe { message.to_string().as_mut_vec().clone() };
1273    let mut cipher = Vec::<u8>::new();
1274    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1275    print!("C =\t");
1276    for c in cipher.clone()
1277        { print!("{:02X} ", c); }
1278    println!();
1279    let mut txt = String::new();
1280    for c in cipher.clone()
1281        { write!(txt, "{:02X} ", c); }
1282    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1283    println!();
1284
1285    // Normal case for AES-256
1286    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1287    print!("K =\t");
1288    for i in 0..32
1289        { print!("{:02X}", key[i]); }
1290    println!();
1291    let mut a_aes = AES_256::new_with_key(&key);
1292
1293    let message = "In the beginning God created the heavens and the earth.";
1294    println!("M =\t{}", message);
1295    let message = unsafe { message.to_string().as_mut_vec().clone() };
1296    let mut cipher = Vec::<u8>::new();
1297    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1298    print!("C =\t");
1299    for c in cipher.clone()
1300        { print!("{:02X} ", c); }
1301    println!();
1302    let mut txt = String::new();
1303    for c in cipher.clone()
1304        { write!(txt, "{:02X} ", c); }
1305    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1306    println!();
1307
1308    // Normal case for Rijndael-256-256
1309    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1310    print!("K =\t");
1311    for i in 0..32
1312        { print!("{:02X}", key[i]); }
1313    println!();
1314    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1315
1316    let message = "In the beginning God created the heavens and the earth.";
1317    println!("M =\t{}", message);
1318    let message = unsafe { message.to_string().as_mut_vec().clone() };
1319    let mut cipher = Vec::<u8>::new();
1320    a_rijndael.encrypt_vec_into_vec(&message, &mut cipher);
1321    print!("C =\t");
1322    for c in cipher.clone()
1323        { print!("{:02X} ", c); }
1324    println!();
1325    let mut txt = String::new();
1326    for c in cipher.clone()
1327        { write!(txt, "{:02X} ", c); }
1328    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1329    println!();
1330
1331    // Normal case for Rijndael-512-512 for post-quantum
1332    use cryptocol::number::SharedArrays;
1333    use cryptocol::hash::SHA3_512;
1334    let mut sha3 = SHA3_512::new();
1335    sha3.absorb_str("Post-quantum");
1336    let key: [u8; 64] = sha3.get_hash_value_in_array();
1337    print!("K =\t");
1338    for i in 0..64
1339        { print!("{:02X}", key[i]); }
1340    println!();
1341    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1342    let message = "In the beginning God created the heavens and the earth.";
1343    println!("M =\t{}", message);
1344    let message = unsafe { message.to_string().as_mut_vec().clone() };
1345    let mut cipher = Vec::<u8>::new();
1346    a_rijndael.encrypt_vec_into_vec(&message, &mut cipher);
1347    print!("C =\t");
1348    for c in cipher.clone()
1349        { print!("{:02X} ", c); }
1350    println!();
1351    let mut txt = String::new();
1352    for c in cipher.clone()
1353        { write!(txt, "{:02X} ", c); }
1354    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1355    println!("-------------------------------");
1356}
1357
1358fn aes_encrypt_vec_with_padding_iso_ecb_into_array()
1359{
1360    println!("aes_encrypt_vec_with_padding_iso_ecb_into_array()");
1361    use std::io::Write;
1362    use std::fmt::Write as _;
1363    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1364
1365    // Normal case for AES-128
1366    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1367    println!("K =\t{:#016X}", key);
1368    let mut a_aes = AES_128::new_with_key_u128(key);
1369
1370    let message = "In the beginning God created the heavens and the earth.";
1371    println!("M =\t{}", message);
1372    let message = unsafe { message.to_string().as_mut_vec().clone() };
1373    let mut cipher = [0_u8; 64];
1374    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1375    print!("C =\t");
1376    for c in cipher.clone()
1377        { print!("{:02X} ", c); }
1378    println!();
1379    let mut txt = String::new();
1380    for c in cipher.clone()
1381        { write!(txt, "{:02X} ", c); }
1382    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1383    println!();
1384
1385    // Normal case for AES-192
1386    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1387    print!("K =\t");
1388    for i in 0..24
1389        { print!("{:02X}", key[i]); }
1390    println!();
1391    let mut a_aes = AES_192::new_with_key(&key);
1392
1393    let message = "In the beginning God created the heavens and the earth.";
1394    println!("M =\t{}", message);
1395    let message = unsafe { message.to_string().as_mut_vec().clone() };
1396    let mut cipher = [0_u8; 64];
1397    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1398    print!("C =\t");
1399    for c in cipher.clone()
1400        { print!("{:02X} ", c); }
1401    println!();
1402    let mut txt = String::new();
1403    for c in cipher.clone()
1404        { write!(txt, "{:02X} ", c); }
1405    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1406    println!();
1407
1408    // Normal case for AES-256
1409    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1410    print!("K =\t");
1411    for i in 0..32
1412        { print!("{:02X}", key[i]); }
1413    println!();
1414    let mut a_aes = AES_256::new_with_key(&key);
1415
1416    let message = "In the beginning God created the heavens and the earth.";
1417    println!("M =\t{}", message);
1418    let message = unsafe { message.to_string().as_mut_vec().clone() };
1419    let mut cipher = [0_u8; 64];
1420    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1421    print!("C =\t");
1422    for c in cipher.clone()
1423        { print!("{:02X} ", c); }
1424    println!();
1425    let mut txt = String::new();
1426    for c in cipher.clone()
1427        { write!(txt, "{:02X} ", c); }
1428    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1429    println!();
1430
1431    // Normal case for Rijndael-256-256
1432    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1433    print!("K =\t");
1434    for i in 0..32
1435        { print!("{:02X}", key[i]); }
1436    println!();
1437    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1438
1439    let message = "In the beginning God created the heavens and the earth.";
1440    println!("M =\t{}", message);
1441    let message = unsafe { message.to_string().as_mut_vec().clone() };
1442    let mut cipher = [0_u8; 64];
1443    a_rijndael.encrypt_vec_into_array(&message, &mut cipher);
1444    print!("C =\t");
1445    for c in cipher.clone()
1446        { print!("{:02X} ", c); }
1447    println!();
1448    let mut txt = String::new();
1449    for c in cipher.clone()
1450        { write!(txt, "{:02X} ", c); }
1451    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1452    println!();
1453
1454    // Normal case for Rijndael-512-512 for post-quantum
1455    use cryptocol::number::SharedArrays;
1456    use cryptocol::hash::SHA3_512;
1457    let mut sha3 = SHA3_512::new();
1458    sha3.absorb_str("Post-quantum");
1459    let key: [u8; 64] = sha3.get_hash_value_in_array();
1460    print!("K =\t");
1461    for i in 0..64
1462        { print!("{:02X}", key[i]); }
1463    println!();
1464    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1465    let message = "In the beginning God created the heavens and the earth.";
1466    println!("M =\t{}", message);
1467    let message = unsafe { message.to_string().as_mut_vec().clone() };
1468    let mut cipher = [0_u8; 64];
1469    a_rijndael.encrypt_vec_into_array(&message, &mut cipher);
1470    print!("C =\t");
1471    for c in cipher.clone()
1472        { print!("{:02X} ", c); }
1473    println!();
1474    let mut txt = String::new();
1475    for c in cipher.clone()
1476        { write!(txt, "{:02X} ", c); }
1477    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1478    println!("-------------------------------");
1479}
1480
1481fn aes_encrypt_array_with_padding_iso_ecb()
1482{
1483    println!("aes_encrypt_array_with_padding_iso_ecb()");
1484    use std::io::Write;
1485    use std::fmt::Write as _;
1486    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1487
1488    // Normal case for AES-128
1489    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1490    println!("K =\t{:#016X}", key);
1491    let mut a_aes = AES_128::new_with_key_u128(key);
1492
1493    let mes = "In the beginning God created the heavens and the earth.";
1494    println!("M =\t{}", mes);
1495    let mut message = [0_u8; 55];
1496    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1497    let mut cipher = [0_u8; 64];
1498    a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1499    print!("C =\t");
1500    for c in cipher.clone()
1501        { print!("{:02X} ", c); }
1502    println!();
1503    let mut txt = String::new();
1504    for c in cipher.clone()
1505        { write!(txt, "{:02X} ", c); }
1506    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1507    println!();
1508
1509    // Normal case for AES-192
1510    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1511    print!("K =\t");
1512    for i in 0..24
1513        { print!("{:02X}", key[i]); }
1514    println!();
1515    let mut a_aes = AES_192::new_with_key(&key);
1516
1517    let mes = "In the beginning God created the heavens and the earth.";
1518    println!("M =\t{}", mes);
1519    let mut message = [0_u8; 55];
1520    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1521    let mut cipher = [0_u8; 64];
1522    a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1523    print!("C =\t");
1524    for c in cipher.clone()
1525        { print!("{:02X} ", c); }
1526    println!();
1527    let mut txt = String::new();
1528    for c in cipher.clone()
1529        { write!(txt, "{:02X} ", c); }
1530    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1531    println!();
1532
1533    // Normal case for AES-256
1534    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1535    print!("K =\t");
1536    for i in 0..32
1537        { print!("{:02X}", key[i]); }
1538    println!();
1539    let mut a_aes = AES_256::new_with_key(&key);
1540
1541    let mes = "In the beginning God created the heavens and the earth.";
1542    println!("M =\t{}", mes);
1543    let mut message = [0_u8; 55];
1544    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1545    let mut cipher = [0_u8; 64];
1546    a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1547    print!("C =\t");
1548    for c in cipher.clone()
1549        { print!("{:02X} ", c); }
1550    println!();
1551    let mut txt = String::new();
1552    for c in cipher.clone()
1553        { write!(txt, "{:02X} ", c); }
1554    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1555    println!();
1556
1557    // Normal case for Rijndael-256-256
1558    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1559    print!("K =\t");
1560    for i in 0..32
1561        { print!("{:02X}", key[i]); }
1562    println!();
1563    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1564
1565    let mes = "In the beginning God created the heavens and the earth.";
1566    println!("M =\t{}", mes);
1567    let mut message = [0_u8; 55];
1568    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1569    let mut cipher = [0_u8; 64];
1570    a_rijndael.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1571    print!("C =\t");
1572    for c in cipher.clone()
1573        { print!("{:02X} ", c); }
1574    println!();
1575    let mut txt = String::new();
1576    for c in cipher.clone()
1577        { write!(txt, "{:02X} ", c); }
1578    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1579    println!();
1580
1581    // Normal case for Rijndael-512-512 for post-quantum
1582    use cryptocol::number::SharedArrays;
1583    use cryptocol::hash::SHA3_512;
1584    let mut sha3 = SHA3_512::new();
1585    sha3.absorb_str("Post-quantum");
1586    let key: [u8; 64] = sha3.get_hash_value_in_array();
1587    print!("K =\t");
1588    for i in 0..64
1589        { print!("{:02X}", key[i]); }
1590    println!();
1591    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1592    let mes = "In the beginning God created the heavens and the earth.";
1593    println!("M =\t{}", mes);
1594    let mut message = [0_u8; 55];
1595    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1596    let mut cipher = [0_u8; 64];
1597    a_rijndael.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
1598    print!("C =\t");
1599    for c in cipher.clone()
1600        { print!("{:02X} ", c); }
1601    println!();
1602    let mut txt = String::new();
1603    for c in cipher.clone()
1604        { write!(txt, "{:02X} ", c); }
1605    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1606    println!("-------------------------------");
1607}
1608
1609fn aes_encrypt_array_with_padding_iso_ecb_into_vec()
1610{
1611    println!("aes_encrypt_array_with_padding_iso_ecb_into_vec()");
1612    use std::io::Write;
1613    use std::fmt::Write as _;
1614    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1615
1616    // Normal case for AES-128
1617    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1618    println!("K =\t{:#016X}", key);
1619    let mut a_aes = AES_128::new_with_key_u128(key);
1620
1621    let mes = "In the beginning God created the heavens and the earth.";
1622    println!("M =\t{}", mes);
1623    let mut message = [0_u8; 55];
1624    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1625    let mut cipher = Vec::<u8>::new();
1626    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1627    print!("C =\t");
1628    for c in cipher.clone()
1629        { print!("{:02X} ", c); }
1630    println!();
1631    let mut txt = String::new();
1632    for c in cipher.clone()
1633        { write!(txt, "{:02X} ", c); }
1634    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1635    println!();
1636
1637    // Normal case for AES-192
1638    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1639    print!("K =\t");
1640    for i in 0..24
1641        { print!("{:02X}", key[i]); }
1642    println!();
1643    let mut a_aes = AES_192::new_with_key(&key);
1644
1645    let mes = "In the beginning God created the heavens and the earth.";
1646    println!("M =\t{}", mes);
1647    let mut message = [0_u8; 55];
1648    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1649    let mut cipher = Vec::<u8>::new();
1650    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1651    print!("C =\t");
1652    for c in cipher.clone()
1653        { print!("{:02X} ", c); }
1654    println!();
1655    let mut txt = String::new();
1656    for c in cipher.clone()
1657        { write!(txt, "{:02X} ", c); }
1658    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1659    println!();
1660
1661    // Normal case for AES-256
1662    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1663    print!("K =\t");
1664    for i in 0..32
1665        { print!("{:02X}", key[i]); }
1666    println!();
1667    let mut a_aes = AES_256::new_with_key(&key);
1668
1669    let mes = "In the beginning God created the heavens and the earth.";
1670    println!("M =\t{}", mes);
1671    let mut message = [0_u8; 55];
1672    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1673    let mut cipher = Vec::<u8>::new();
1674    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1675    print!("C =\t");
1676    for c in cipher.clone()
1677        { print!("{:02X} ", c); }
1678    println!();
1679    let mut txt = String::new();
1680    for c in cipher.clone()
1681        { write!(txt, "{:02X} ", c); }
1682    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1683    println!();
1684
1685    // Normal case for Rijndael-256-256
1686    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1687    print!("K =\t");
1688    for i in 0..32
1689        { print!("{:02X}", key[i]); }
1690    println!();
1691    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1692
1693    let mes = "In the beginning God created the heavens and the earth.";
1694    println!("M =\t{}", mes);
1695    let mut message = [0_u8; 55];
1696    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1697    let mut cipher = Vec::<u8>::new();
1698    a_rijndael.encrypt_array_into_vec(&message, &mut cipher);
1699    print!("C =\t");
1700    for c in cipher.clone()
1701        { print!("{:02X} ", c); }
1702    println!();
1703    let mut txt = String::new();
1704    for c in cipher.clone()
1705        { write!(txt, "{:02X} ", c); }
1706    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1707    println!();
1708
1709    // Normal case for Rijndael-512-512 for post-quantum
1710    use cryptocol::number::SharedArrays;
1711    use cryptocol::hash::SHA3_512;
1712    let mut sha3 = SHA3_512::new();
1713    sha3.absorb_str("Post-quantum");
1714    let key: [u8; 64] = sha3.get_hash_value_in_array();
1715    print!("K =\t");
1716    for i in 0..64
1717        { print!("{:02X}", key[i]); }
1718    println!();
1719    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1720    let mes = "In the beginning God created the heavens and the earth.";
1721    println!("M =\t{}", mes);
1722    let mut message = [0_u8; 55];
1723    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1724    let mut cipher = Vec::<u8>::new();
1725    a_rijndael.encrypt_array_into_vec(&message, &mut cipher);
1726    print!("C =\t");
1727    for c in cipher.clone()
1728        { print!("{:02X} ", c); }
1729    println!();
1730    let mut txt = String::new();
1731    for c in cipher.clone()
1732        { write!(txt, "{:02X} ", c); }
1733    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1734    println!("-------------------------------");
1735}
1736
1737fn aes_encrypt_array_with_padding_iso_ecb_into_array()
1738{
1739    println!("aes_encrypt_array_with_padding_iso_ecb_into_array()");
1740    use std::io::Write;
1741    use std::fmt::Write as _;
1742    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1743
1744    // Normal case for AES-128
1745    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1746    println!("K =\t{:#016X}", key);
1747    let mut a_aes = AES_128::new_with_key_u128(key);
1748
1749    let mes = "In the beginning God created the heavens and the earth.";
1750    println!("M =\t{}", mes);
1751    let mut message = [0_u8; 55];
1752    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1753    let mut cipher = [0_u8; 64];
1754    a_aes.encrypt_array_into_array(&message, &mut cipher);
1755    print!("C =\t");
1756    for c in cipher.clone()
1757        { print!("{:02X} ", c); }
1758    println!();
1759    let mut txt = String::new();
1760    for c in cipher.clone()
1761        { write!(txt, "{:02X} ", c); }
1762    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1763    println!();
1764
1765    // Normal case for AES-192
1766    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1767    print!("K =\t");
1768    for i in 0..24
1769        { print!("{:02X}", key[i]); }
1770    println!();
1771    let mut a_aes = AES_192::new_with_key(&key);
1772
1773    let mes = "In the beginning God created the heavens and the earth.";
1774    println!("M =\t{}", mes);
1775    let mut message = [0_u8; 55];
1776    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1777    let mut cipher = [0_u8; 64];
1778    a_aes.encrypt_array_into_array(&message, &mut cipher);
1779    print!("C =\t");
1780    for c in cipher.clone()
1781        { print!("{:02X} ", c); }
1782    println!();
1783    let mut txt = String::new();
1784    for c in cipher.clone()
1785        { write!(txt, "{:02X} ", c); }
1786    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1787    println!();
1788
1789    // Normal case for AES-256
1790    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1791    print!("K =\t");
1792    for i in 0..32
1793        { print!("{:02X}", key[i]); }
1794    println!();
1795    let mut a_aes = AES_256::new_with_key(&key);
1796
1797    let mes = "In the beginning God created the heavens and the earth.";
1798    println!("M =\t{}", mes);
1799    let mut message = [0_u8; 55];
1800    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1801    let mut cipher = [0_u8; 64];
1802    a_aes.encrypt_array_into_array(&message, &mut cipher);
1803    print!("C =\t");
1804    for c in cipher.clone()
1805        { print!("{:02X} ", c); }
1806    println!();
1807    let mut txt = String::new();
1808    for c in cipher.clone()
1809        { write!(txt, "{:02X} ", c); }
1810    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1811    println!();
1812
1813    // Normal case for Rijndael-256-256
1814    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1815    print!("K =\t");
1816    for i in 0..32
1817        { print!("{:02X}", key[i]); }
1818    println!();
1819    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1820
1821    let mes = "In the beginning God created the heavens and the earth.";
1822    println!("M =\t{}", mes);
1823    let mut message = [0_u8; 55];
1824    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1825    let mut cipher = [0_u8; 64];
1826    a_rijndael.encrypt_array_into_array(&message, &mut cipher);
1827    print!("C =\t");
1828    for c in cipher.clone()
1829        { print!("{:02X} ", c); }
1830    println!();
1831    let mut txt = String::new();
1832    for c in cipher.clone()
1833        { write!(txt, "{:02X} ", c); }
1834    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1835    println!();
1836
1837    // Normal case for Rijndael-512-512 for post-quantum
1838    use cryptocol::number::SharedArrays;
1839    use cryptocol::hash::SHA3_512;
1840    let mut sha3 = SHA3_512::new();
1841    sha3.absorb_str("Post-quantum");
1842    let key: [u8; 64] = sha3.get_hash_value_in_array();
1843    print!("K =\t");
1844    for i in 0..64
1845        { print!("{:02X}", key[i]); }
1846    println!();
1847    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1848    let mes = "In the beginning God created the heavens and the earth.";
1849    println!("M =\t{}", mes);
1850    let mut message = [0_u8; 55];
1851    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1852    let mut cipher = [0_u8; 64];
1853    a_rijndael.encrypt_array_into_array(&message, &mut cipher);
1854    print!("C =\t");
1855    for c in cipher.clone()
1856        { print!("{:02X} ", c); }
1857    println!();
1858    let mut txt = String::new();
1859    for c in cipher.clone()
1860        { write!(txt, "{:02X} ", c); }
1861    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1862    println!("-------------------------------");
1863}
1864
1865fn aes_decrypt_with_padding_iso_ecb()
1866{
1867    println!("aes_decrypt_with_padding_iso_ecb");
1868    use std::io::Write;
1869    use std::fmt::Write as _;
1870    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1871
1872    // Normal case for AES-128
1873    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1874    println!("K =\t{:#016X}", key);
1875    let mut a_aes = AES_128::new_with_key_u128(key);
1876
1877    let message = "In the beginning God created the heavens and the earth.";
1878    println!("M =\t{}", message);
1879    let mut cipher = [0_u8; 64];
1880    a_aes.encrypt_str_into_array(&message, &mut cipher);
1881    print!("C =\t");
1882    for c in cipher.clone()
1883        { print!("{:02X} ", c); }
1884    println!();
1885    let mut txt = String::new();
1886    for c in cipher.clone()
1887        { write!(txt, "{:02X} ", c); }
1888    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1889
1890    let mut recovered = vec![0; 55];
1891    a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
1892    print!("Ba =\t");
1893    for b in recovered.clone()
1894        { print!("{:02X} ", b); }
1895    println!();
1896    let mut txt = String::new();
1897    for c in recovered.clone()
1898        { write!(txt, "{:02X} ", c); }
1899    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
1900
1901    let mut converted = String::new();
1902    unsafe { converted.as_mut_vec() }.append(&mut recovered);
1903    
1904    println!("Bb =\t{}", converted);
1905    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
1906    assert_eq!(converted, message);
1907    println!();
1908
1909    // Normal case for AES-192
1910    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1911    print!("K =\t");
1912    for i in 0..24
1913        { print!("{:02X}", key[i]); }
1914    println!();
1915    let mut a_aes = AES_192::new_with_key(&key);
1916
1917    let message = "In the beginning God created the heavens and the earth.";
1918    println!("M =\t{}", message);
1919    let mut cipher = [0_u8; 64];
1920    a_aes.encrypt_str_into_array(&message, &mut cipher);
1921    print!("C =\t");
1922    for c in cipher.clone()
1923        { print!("{:02X} ", c); }
1924    println!();
1925    let mut txt = String::new();
1926    for c in cipher.clone()
1927        { write!(txt, "{:02X} ", c); }
1928    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1929
1930    let mut recovered = vec![0; 55];
1931    a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
1932    print!("Ba =\t");
1933    for b in recovered.clone()
1934        { print!("{:02X} ", b); }
1935    println!();
1936    let mut txt = String::new();
1937    for c in recovered.clone()
1938        { write!(txt, "{:02X} ", c); }
1939    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
1940
1941    let mut converted = String::new();
1942    unsafe { converted.as_mut_vec() }.append(&mut recovered);
1943    
1944    println!("Bb =\t{}", converted);
1945    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
1946    assert_eq!(converted, message);
1947    println!();
1948
1949    // Normal case for AES-256
1950    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1951    print!("K =\t");
1952    for i in 0..32
1953        { print!("{:02X}", key[i]); }
1954    println!();
1955    let mut a_aes = AES_256::new_with_key(&key);
1956
1957    let message = "In the beginning God created the heavens and the earth.";
1958    println!("M =\t{}", message);
1959    let mut cipher = [0_u8; 64];
1960    a_aes.encrypt_str_into_array(&message, &mut cipher);
1961    print!("C =\t");
1962    for c in cipher.clone()
1963        { print!("{:02X} ", c); }
1964    println!();
1965    let mut txt = String::new();
1966    for c in cipher.clone()
1967        { write!(txt, "{:02X} ", c); }
1968    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1969
1970    let mut recovered = vec![0; 55];
1971    a_aes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
1972    print!("Ba =\t");
1973    for b in recovered.clone()
1974        { print!("{:02X} ", b); }
1975    println!();
1976    let mut txt = String::new();
1977    for c in recovered.clone()
1978        { write!(txt, "{:02X} ", c); }
1979    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
1980
1981    let mut converted = String::new();
1982    unsafe { converted.as_mut_vec() }.append(&mut recovered);
1983    
1984    println!("Bb =\t{}", converted);
1985    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
1986    assert_eq!(converted, message);
1987    println!();
1988
1989    // Normal case for Rijndael-256-256
1990    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1991    print!("K =\t");
1992    for i in 0..32
1993        { print!("{:02X}", key[i]); }
1994    println!();
1995    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1996
1997    let message = "In the beginning God created the heavens and the earth.";
1998    println!("M =\t{}", message);
1999    let mut cipher = [0_u8; 64];
2000    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2001    print!("C =\t");
2002    for c in cipher.clone()
2003        { print!("{:02X} ", c); }
2004    println!();
2005    let mut txt = String::new();
2006    for c in cipher.clone()
2007        { write!(txt, "{:02X} ", c); }
2008    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2009
2010    let mut recovered = vec![0; 55];
2011    a_rijndael.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2012    print!("Ba =\t");
2013    for b in recovered.clone()
2014        { print!("{:02X} ", b); }
2015    println!();
2016    let mut txt = String::new();
2017    for c in recovered.clone()
2018        { write!(txt, "{:02X} ", c); }
2019    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2020
2021    let mut converted = String::new();
2022    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2023    
2024    println!("Bb =\t{}", converted);
2025    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2026    assert_eq!(converted, message);
2027    println!();
2028
2029    // Normal case for Rijndael-512-512 for post-quantum
2030    use cryptocol::number::SharedArrays;
2031    use cryptocol::hash::SHA3_512;
2032    let mut sha3 = SHA3_512::new();
2033    sha3.absorb_str("Post-quantum");
2034    let key: [u8; 64] = sha3.get_hash_value_in_array();
2035    print!("K =\t");
2036    for i in 0..64
2037        { print!("{:02X}", key[i]); }
2038    println!();
2039    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2040    let message = "In the beginning God created the heavens and the earth.";
2041    println!("M =\t{}", message);
2042    let mut cipher = [0_u8; 64];
2043    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2044    print!("C =\t");
2045    for c in cipher.clone()
2046        { print!("{:02X} ", c); }
2047    println!();
2048    let mut txt = String::new();
2049    for c in cipher.clone()
2050        { write!(txt, "{:02X} ", c); }
2051    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2052    
2053    let mut recovered = vec![0; 55];
2054    a_rijndael.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2055    print!("Ba =\t");
2056    for b in recovered.clone()
2057        { print!("{:02X} ", b); }
2058    println!();
2059    let mut txt = String::new();
2060    for c in recovered.clone()
2061        { write!(txt, "{:02X} ", c); }
2062    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2063
2064    let mut converted = String::new();
2065    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2066    
2067    println!("Bb =\t{}", converted);
2068    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2069    assert_eq!(converted, message);
2070    println!("-------------------------------");
2071}
2072
2073
2074fn aes_decrypt_with_padding_iso_ecb_into_vec()
2075{
2076    println!("aes_decrypt_with_padding_iso_ecb_into_vec()");
2077    use std::io::Write;
2078    use std::fmt::Write as _;
2079    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2080
2081    // Normal case for AES-128
2082    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2083    println!("K =\t{:#016X}", key);
2084    let mut a_aes = AES_128::new_with_key_u128(key);
2085
2086    let message = "In the beginning God created the heavens and the earth.";
2087    println!("M =\t{}", message);
2088    let mut cipher = [0_u8; 64];
2089    a_aes.encrypt_str_into_array(&message, &mut cipher);
2090    print!("C =\t");
2091    for c in cipher.clone()
2092        { print!("{:02X} ", c); }
2093    println!();
2094    let mut txt = String::new();
2095    for c in cipher.clone()
2096        { write!(txt, "{:02X} ", c); }
2097    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2098    println!();
2099
2100    let mut recovered = Vec::<u8>::new();
2101    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2102    print!("Ba =\t");
2103    for b in recovered.clone()
2104        { print!("{:02X} ", b); }
2105    println!();
2106    let mut txt = String::new();
2107    for c in recovered.clone()
2108        { write!(txt, "{:02X} ", c); }
2109    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2110
2111    let mut converted = String::new();
2112    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2113    
2114    println!("Bb =\t{}", converted);
2115    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2116    assert_eq!(converted, message);
2117    println!();
2118
2119    // Normal case for AES-192
2120    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2121    print!("K =\t");
2122    for i in 0..24
2123        { print!("{:02X}", key[i]); }
2124    println!();
2125    let mut a_aes = AES_192::new_with_key(&key);
2126
2127    let message = "In the beginning God created the heavens and the earth.";
2128    println!("M =\t{}", message);
2129    let mut cipher = [0_u8; 64];
2130    a_aes.encrypt_str_into_array(&message, &mut cipher);
2131    print!("C =\t");
2132    for c in cipher.clone()
2133        { print!("{:02X} ", c); }
2134    println!();
2135    let mut txt = String::new();
2136    for c in cipher.clone()
2137        { write!(txt, "{:02X} ", c); }
2138    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2139    println!();
2140
2141    let mut recovered = Vec::<u8>::new();
2142    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2143    print!("Ba =\t");
2144    for b in recovered.clone()
2145        { print!("{:02X} ", b); }
2146    println!();
2147    let mut txt = String::new();
2148    for c in recovered.clone()
2149        { write!(txt, "{:02X} ", c); }
2150    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2151
2152    let mut converted = String::new();
2153    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2154    
2155    println!("Bb =\t{}", converted);
2156    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2157    assert_eq!(converted, message);
2158    println!();
2159
2160    // Normal case for AES-256
2161    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2162    print!("K =\t");
2163    for i in 0..32
2164        { print!("{:02X}", key[i]); }
2165    println!();
2166    let mut a_aes = AES_256::new_with_key(&key);
2167
2168    let message = "In the beginning God created the heavens and the earth.";
2169    println!("M =\t{}", message);
2170    let mut cipher = [0_u8; 64];
2171    a_aes.encrypt_str_into_array(&message, &mut cipher);
2172    print!("C =\t");
2173    for c in cipher.clone()
2174        { print!("{:02X} ", c); }
2175    println!();
2176    let mut txt = String::new();
2177    for c in cipher.clone()
2178        { write!(txt, "{:02X} ", c); }
2179    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2180    println!();
2181
2182    let mut recovered = Vec::<u8>::new();
2183    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2184    print!("Ba =\t");
2185    for b in recovered.clone()
2186        { print!("{:02X} ", b); }
2187    println!();
2188    let mut txt = String::new();
2189    for c in recovered.clone()
2190        { write!(txt, "{:02X} ", c); }
2191    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2192
2193    let mut converted = String::new();
2194    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2195    
2196    println!("Bb =\t{}", converted);
2197    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2198    assert_eq!(converted, message);
2199    println!();
2200
2201    // Normal case for Rijndael-256-256
2202    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2203    print!("K =\t");
2204    for i in 0..32
2205        { print!("{:02X}", key[i]); }
2206    println!();
2207    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2208
2209    let message = "In the beginning God created the heavens and the earth.";
2210    println!("M =\t{}", message);
2211    let mut cipher = [0_u8; 64];
2212    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2213    print!("C =\t");
2214    for c in cipher.clone()
2215        { print!("{:02X} ", c); }
2216    println!();
2217    let mut txt = String::new();
2218    for c in cipher.clone()
2219        { write!(txt, "{:02X} ", c); }
2220    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2221    println!();
2222
2223    let mut recovered = Vec::<u8>::new();
2224    a_rijndael.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2225    print!("Ba =\t");
2226    for b in recovered.clone()
2227        { print!("{:02X} ", b); }
2228    println!();
2229    let mut txt = String::new();
2230    for c in recovered.clone()
2231        { write!(txt, "{:02X} ", c); }
2232    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2233
2234    let mut converted = String::new();
2235    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2236    
2237    println!("Bb =\t{}", converted);
2238    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2239    assert_eq!(converted, message);
2240    println!();
2241
2242    // Normal case for Rijndael-512-512 for post-quantum
2243    use cryptocol::number::SharedArrays;
2244    use cryptocol::hash::SHA3_512;
2245    let mut sha3 = SHA3_512::new();
2246    sha3.absorb_str("Post-quantum");
2247    let key: [u8; 64] = sha3.get_hash_value_in_array();
2248    print!("K =\t");
2249    for i in 0..64
2250        { print!("{:02X}", key[i]); }
2251    println!();
2252    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2253    let message = "In the beginning God created the heavens and the earth.";
2254    println!("M =\t{}", message);
2255    let mut cipher = [0_u8; 64];
2256    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2257    print!("C =\t");
2258    for c in cipher.clone()
2259        { print!("{:02X} ", c); }
2260    println!();
2261    let mut txt = String::new();
2262    for c in cipher.clone()
2263        { write!(txt, "{:02X} ", c); }
2264    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2265    
2266    let mut recovered = Vec::<u8>::new();
2267    a_rijndael.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2268    print!("Ba =\t");
2269    for b in recovered.clone()
2270        { print!("{:02X} ", b); }
2271    println!();
2272    let mut txt = String::new();
2273    for c in recovered.clone()
2274        { write!(txt, "{:02X} ", c); }
2275    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2276
2277    let mut converted = String::new();
2278    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2279    
2280    println!("Bb =\t{}", converted);
2281    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2282    assert_eq!(converted, message);
2283    println!("-------------------------------");
2284}
2285
2286fn aes_decrypt_with_padding_iso_ecb_into_array()
2287{
2288    println!("aes_decrypt_with_padding_iso_ecb_into_array()");
2289    use std::io::Write;
2290    use std::fmt::Write as _;
2291    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2292
2293    // Normal case for AES-128
2294    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2295    println!("K =\t{:#016X}", key);
2296    let mut a_aes = AES_128::new_with_key_u128(key);
2297
2298    let message = "In the beginning God created the heavens and the earth.";
2299    println!("M =\t{}", message);
2300    let mut cipher = [0_u8; 64];
2301    a_aes.encrypt_str_into_array(&message, &mut cipher);
2302    print!("C =\t");
2303    for c in cipher.clone()
2304        { print!("{:02X} ", c); }
2305    println!();
2306    let mut txt = String::new();
2307    for c in cipher.clone()
2308        { write!(txt, "{:02X} ", c); }
2309    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2310
2311    let mut recovered = [0; 64];
2312    let len = a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2313    print!("Ba =\t");
2314    for b in recovered.clone()
2315        { print!("{:02X} ", b); }
2316    println!();
2317    let mut txt = String::new();
2318    for c in recovered.clone()
2319        { write!(txt, "{:02X} ", c); }
2320    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2321
2322    let mut converted = String::new();
2323    unsafe { converted.as_mut_vec() }.write(&recovered);
2324    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2325
2326    println!("Bb =\t{}", converted);
2327    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2328    assert_eq!(converted, message);
2329    println!();
2330
2331    // Normal case for AES-192
2332    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2333    print!("K =\t");
2334    for i in 0..24
2335        { print!("{:02X}", key[i]); }
2336    println!();
2337    let mut a_aes = AES_192::new_with_key(&key);
2338
2339    let message = "In the beginning God created the heavens and the earth.";
2340    println!("M =\t{}", message);
2341    let mut cipher = [0_u8; 64];
2342    a_aes.encrypt_str_into_array(&message, &mut cipher);
2343    print!("C =\t");
2344    for c in cipher.clone()
2345        { print!("{:02X} ", c); }
2346    println!();
2347    let mut txt = String::new();
2348    for c in cipher.clone()
2349        { write!(txt, "{:02X} ", c); }
2350    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2351
2352    let mut recovered = [0; 64];
2353    a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2354    print!("Ba =\t");
2355    for b in recovered.clone()
2356        { print!("{:02X} ", b); }
2357    println!();
2358    let mut txt = String::new();
2359
2360    for c in recovered.clone()
2361        { write!(txt, "{:02X} ", c); }
2362    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2363
2364    let mut converted = String::new();
2365    unsafe { converted.as_mut_vec() }.write(&recovered);
2366    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2367
2368    println!("Bb =\t{}", converted);
2369    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2370    assert_eq!(converted, message);
2371    println!();
2372
2373    // Normal case for AES-256
2374    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2375    print!("K =\t");
2376    for i in 0..32
2377        { print!("{:02X}", key[i]); }
2378    println!();
2379    let mut a_aes = AES_256::new_with_key(&key);
2380
2381    let message = "In the beginning God created the heavens and the earth.";
2382    println!("M =\t{}", message);
2383    let mut cipher = [0_u8; 64];
2384    a_aes.encrypt_str_into_array(&message, &mut cipher);
2385    print!("C =\t");
2386    for c in cipher.clone()
2387        { print!("{:02X} ", c); }
2388    println!();
2389    let mut txt = String::new();
2390    for c in cipher.clone()
2391        { write!(txt, "{:02X} ", c); }
2392    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2393
2394    let mut recovered = [0; 64];
2395    a_aes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2396    print!("Ba =\t");
2397    for b in recovered.clone()
2398        { print!("{:02X} ", b); }
2399    println!();
2400    let mut txt = String::new();
2401    for c in recovered.clone()
2402        { write!(txt, "{:02X} ", c); }
2403    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2404
2405    let mut converted = String::new();
2406    unsafe { converted.as_mut_vec() }.write(&recovered);
2407    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2408     
2409    println!("Bb =\t{}", converted);
2410    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2411    assert_eq!(converted, message);
2412    println!();
2413
2414    // Normal case for Rijndael-256-256
2415    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2416    print!("K =\t");
2417    for i in 0..32
2418        { print!("{:02X}", key[i]); }
2419    println!();
2420    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2421
2422    let message = "In the beginning God created the heavens and the earth.";
2423    println!("M =\t{}", message);
2424    let mut cipher = [0_u8; 64];
2425    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2426    print!("C =\t");
2427    for c in cipher.clone()
2428        { print!("{:02X} ", c); }
2429    println!();
2430    let mut txt = String::new();
2431    for c in cipher.clone()
2432        { write!(txt, "{:02X} ", c); }
2433    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2434
2435    let mut recovered = [0; 64];
2436    a_rijndael.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2437    for b in recovered.clone()
2438        { print!("{:02X} ", b); }
2439    println!();
2440    let mut txt = String::new();
2441    for c in recovered.clone()
2442        { write!(txt, "{:02X} ", c); }
2443    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2444
2445    let mut converted = String::new();
2446    unsafe { converted.as_mut_vec() }.write(&recovered);
2447    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2448
2449    println!("Bb =\t{}", converted);
2450    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2451    assert_eq!(converted, message);
2452    println!();
2453
2454    // Normal case for Rijndael-512-512 for post-quantum
2455    use cryptocol::number::SharedArrays;
2456    use cryptocol::hash::SHA3_512;
2457    let mut sha3 = SHA3_512::new();
2458    sha3.absorb_str("Post-quantum");
2459    let key: [u8; 64] = sha3.get_hash_value_in_array();
2460    print!("K =\t");
2461    for i in 0..64
2462        { print!("{:02X}", key[i]); }
2463    println!();
2464    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2465
2466    let message = "In the beginning God created the heavens and the earth.";
2467    println!("M =\t{}", message);
2468    let mut cipher = [0_u8; 64];
2469    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2470    print!("C =\t");
2471    for c in cipher.clone()
2472        { print!("{:02X} ", c); }
2473    println!();
2474    let mut txt = String::new();
2475    for c in cipher.clone()
2476        { write!(txt, "{:02X} ", c); }
2477    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2478    
2479    let mut recovered = [0; 64];
2480    a_rijndael.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2481    print!("Ba =\t");
2482    for b in recovered.clone()
2483        { print!("{:02X} ", b); }
2484    println!();
2485    let mut txt = String::new();
2486    for c in recovered.clone()
2487        { write!(txt, "{:02X} ", c); }
2488    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
2489
2490    let mut converted = String::new();
2491    unsafe { converted.as_mut_vec() }.write(&recovered);
2492    unsafe { converted.as_mut_vec() }.truncate(len as usize);
2493
2494    println!("Bb =\t{}", converted);
2495    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2496    assert_eq!(converted, message);
2497    println!("-------------------------------");
2498}
2499
2500fn aes_decrypt_with_padding_iso_ecb_into_string()
2501{
2502    println!("aes_decrypt_with_padding_iso_ecb_into_string()");
2503    use std::io::Write;
2504    use std::fmt::Write as _;
2505    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2506
2507    // Normal case for AES-128
2508    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2509    println!("K =\t{:#016X}", key);
2510    let mut a_aes = AES_128::new_with_key_u128(key);
2511
2512    let message = "In the beginning God created the heavens and the earth.";
2513    println!("M =\t{}", message);
2514    let mut cipher = [0_u8; 64];
2515    a_aes.encrypt_str_into_array(&message, &mut cipher);
2516    print!("C =\t");
2517    for c in cipher.clone()
2518        { print!("{:02X} ", c); }
2519    println!();
2520    let mut txt = String::new();
2521    for c in cipher.clone()
2522        { write!(txt, "{:02X} ", c); }
2523    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2524
2525    let mut converted= String::new();
2526    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2527    println!("B =\t{}", converted);
2528    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2529    assert_eq!(converted, message);
2530    println!();
2531
2532    // Normal case for AES-192
2533    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2534    print!("K =\t");
2535    for i in 0..24
2536        { print!("{:02X}", key[i]); }
2537    println!();
2538    let mut a_aes = AES_192::new_with_key(&key);
2539
2540    let message = "In the beginning God created the heavens and the earth.";
2541    println!("M =\t{}", message);
2542    let mut cipher = [0_u8; 64];
2543    a_aes.encrypt_str_into_array(&message, &mut cipher);
2544    print!("C =\t");
2545    for c in cipher.clone()
2546        { print!("{:02X} ", c); }
2547    println!();
2548    let mut txt = String::new();
2549    for c in cipher.clone()
2550        { write!(txt, "{:02X} ", c); }
2551    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2552
2553    let mut converted= String::new();
2554    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2555    println!("B =\t{}", converted);
2556    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2557    assert_eq!(converted, message);
2558    println!();
2559
2560    // Normal case for AES-256
2561    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2562    print!("K =\t");
2563    for i in 0..32
2564        { print!("{:02X}", key[i]); }
2565    println!();
2566    let mut a_aes = AES_256::new_with_key(&key);
2567
2568    let message = "In the beginning God created the heavens and the earth.";
2569    println!("M =\t{}", message);
2570    let mut cipher = [0_u8; 64];
2571    a_aes.encrypt_str_into_array(&message, &mut cipher);
2572    print!("C =\t");
2573    for c in cipher.clone()
2574        { print!("{:02X} ", c); }
2575    println!();
2576    let mut txt = String::new();
2577    for c in cipher.clone()
2578        { write!(txt, "{:02X} ", c); }
2579    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2580
2581    let mut converted= String::new();
2582    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2583    println!("B =\t{}", converted);
2584    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2585    assert_eq!(converted, message);
2586    println!();
2587
2588    // Normal case for Rijndael-256-256
2589    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2590    print!("K =\t");
2591    for i in 0..32
2592        { print!("{:02X}", key[i]); }
2593    println!();
2594    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2595
2596    let message = "In the beginning God created the heavens and the earth.";
2597    println!("M =\t{}", message);
2598    let mut cipher = [0_u8; 64];
2599    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2600    print!("C =\t");
2601    for c in cipher.clone()
2602        { print!("{:02X} ", c); }
2603    println!();
2604    let mut txt = String::new();
2605    for c in cipher.clone()
2606        { write!(txt, "{:02X} ", c); }
2607    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2608
2609    let mut converted= String::new();
2610    a_rijndael.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2611    println!("B =\t{}", converted);
2612    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2613    assert_eq!(converted, message);
2614    println!();
2615
2616    // Normal case for Rijndael-512-512 for post-quantum
2617    use cryptocol::number::SharedArrays;
2618    use cryptocol::hash::SHA3_512;
2619    let mut sha3 = SHA3_512::new();
2620    sha3.absorb_str("Post-quantum");
2621    let key: [u8; 64] = sha3.get_hash_value_in_array();
2622    print!("K =\t");
2623    for i in 0..64
2624        { print!("{:02X}", key[i]); }
2625    println!();
2626    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2627    let message = "In the beginning God created the heavens and the earth.";
2628    println!("M =\t{}", message);
2629    let mut cipher = [0_u8; 64];
2630    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2631    print!("C =\t");
2632    for c in cipher.clone()
2633        { print!("{:02X} ", c); }
2634    println!();
2635    let mut txt = String::new();
2636    for c in cipher.clone()
2637        { write!(txt, "{:02X} ", c); }
2638    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2639    
2640    let mut converted= String::new();
2641    a_rijndael.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2642    println!("B =\t{}", converted);
2643    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2644    assert_eq!(converted, message);
2645    println!("-------------------------------");
2646}
2647
2648fn aes_decrypt_vec_with_padding_iso_ecb()
2649{
2650    println!("aes_decrypt_vec_with_padding_iso_ecb()");
2651    use std::io::Write;
2652    use std::fmt::Write as _;
2653    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2654
2655    // Normal case for AES-128
2656    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2657    println!("K =\t{:#016X}", key);
2658    let mut a_aes = AES_128::new_with_key_u128(key);
2659
2660    let message = "In the beginning God created the heavens and the earth.";
2661    println!("M =\t{}", message);
2662    let mut cipher = Vec::<u8>::new();
2663    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2664    print!("C =\t");
2665    for c in cipher.clone()
2666        { print!("{:02X} ", c); }
2667    println!();
2668    let mut txt = String::new();
2669    for c in cipher.clone()
2670        { write!(txt, "{:02X} ", c); }
2671    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2672
2673    let mut recovered = vec![0; 55];
2674    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2675    print!("Ba =\t");
2676    for b in recovered.clone()
2677        { print!("{:02X} ", b); }
2678    println!();
2679    let mut txt = String::new();
2680    for c in recovered.clone()
2681        { write!(txt, "{:02X} ", c); }
2682    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2683
2684    let mut converted = String::new();
2685    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2686    
2687    println!("Bb =\t{}", converted);
2688    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2689    assert_eq!(converted, message);
2690    println!();
2691
2692    // Normal case for AES-192
2693    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2694    print!("K =\t");
2695    for i in 0..24
2696        { print!("{:02X}", key[i]); }
2697    println!();
2698    let mut a_aes = AES_192::new_with_key(&key);
2699
2700    let message = "In the beginning God created the heavens and the earth.";
2701    println!("M =\t{}", message);
2702    let mut cipher = Vec::<u8>::new();
2703    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2704    print!("C =\t");
2705    for c in cipher.clone()
2706        { print!("{:02X} ", c); }
2707    println!();
2708    let mut txt = String::new();
2709    for c in cipher.clone()
2710        { write!(txt, "{:02X} ", c); }
2711    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2712
2713    let mut recovered = vec![0; 55];
2714    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2715    print!("Ba =\t");
2716    for b in recovered.clone()
2717        { print!("{:02X} ", b); }
2718    println!();
2719    let mut txt = String::new();
2720    for c in recovered.clone()
2721        { write!(txt, "{:02X} ", c); }
2722    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2723
2724    let mut converted = String::new();
2725    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2726    
2727    println!("Bb =\t{}", converted);
2728    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2729    assert_eq!(converted, message);
2730    println!();
2731
2732    // Normal case for AES-256
2733    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2734    print!("K =\t");
2735    for i in 0..32
2736        { print!("{:02X}", key[i]); }
2737    println!();
2738    let mut a_aes = AES_256::new_with_key(&key);
2739
2740    let message = "In the beginning God created the heavens and the earth.";
2741    println!("M =\t{}", message);
2742    let mut cipher = Vec::<u8>::new();
2743    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2744    print!("C =\t");
2745    for c in cipher.clone()
2746        { print!("{:02X} ", c); }
2747    println!();
2748    let mut txt = String::new();
2749    for c in cipher.clone()
2750        { write!(txt, "{:02X} ", c); }
2751    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2752
2753    let mut recovered = vec![0; 55];
2754    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2755    print!("Ba =\t");
2756    for b in recovered.clone()
2757        { print!("{:02X} ", b); }
2758    println!();
2759    let mut txt = String::new();
2760    for c in recovered.clone()
2761        { write!(txt, "{:02X} ", c); }
2762    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2763
2764    let mut converted = String::new();
2765    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2766    
2767    println!("Bb =\t{}", converted);
2768    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2769    assert_eq!(converted, message);
2770    println!();
2771
2772    // Normal case for Rijndael-256-256
2773    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2774    print!("K =\t");
2775    for i in 0..32
2776        { print!("{:02X}", key[i]); }
2777    println!();
2778    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2779
2780    let message = "In the beginning God created the heavens and the earth.";
2781    println!("M =\t{}", message);
2782    let mut cipher = Vec::<u8>::new();
2783    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2784    print!("C =\t");
2785    for c in cipher.clone()
2786        { print!("{:02X} ", c); }
2787    println!();
2788    let mut txt = String::new();
2789    for c in cipher.clone()
2790        { write!(txt, "{:02X} ", c); }
2791    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2792
2793    let mut recovered = vec![0; 55];
2794    a_rijndael.decrypt_vec(&cipher, recovered.as_mut_ptr());
2795    print!("Ba =\t");
2796    for b in recovered.clone()
2797        { print!("{:02X} ", b); }
2798    println!();
2799    let mut txt = String::new();
2800    for c in recovered.clone()
2801        { write!(txt, "{:02X} ", c); }
2802    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2803
2804    let mut converted = String::new();
2805    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2806    
2807    println!("Bb =\t{}", converted);
2808    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2809    assert_eq!(converted, message);
2810    println!();
2811
2812    // Normal case for Rijndael-512-512 for post-quantum
2813    use cryptocol::number::SharedArrays;
2814    use cryptocol::hash::SHA3_512;
2815    let mut sha3 = SHA3_512::new();
2816    sha3.absorb_str("Post-quantum");
2817    let key: [u8; 64] = sha3.get_hash_value_in_array();
2818    print!("K =\t");
2819    for i in 0..64
2820        { print!("{:02X}", key[i]); }
2821    println!();
2822    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2823    let message = "In the beginning God created the heavens and the earth.";
2824    println!("M =\t{}", message);
2825    let mut cipher = Vec::<u8>::new();
2826    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2827    print!("C =\t");
2828    for c in cipher.clone()
2829        { print!("{:02X} ", c); }
2830    println!();
2831    let mut txt = String::new();
2832    for c in cipher.clone()
2833        { write!(txt, "{:02X} ", c); }
2834    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2835
2836    let mut recovered = vec![0; 55];
2837    a_rijndael.decrypt_vec(&cipher, recovered.as_mut_ptr());
2838    print!("Ba =\t");
2839    for b in recovered.clone()
2840        { print!("{:02X} ", b); }
2841    println!();
2842    let mut txt = String::new();
2843    for c in recovered.clone()
2844        { write!(txt, "{:02X} ", c); }
2845    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2846
2847    let mut converted = String::new();
2848    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2849    
2850    println!("Bb =\t{}", converted);
2851    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2852    assert_eq!(converted, message);
2853    println!("-------------------------------");
2854}
2855
2856fn aes_decrypt_vec_with_padding_iso_ecb_into_vec()
2857{
2858    println!("aes_decrypt_vec_with_padding_iso_ecb_into_vec()");
2859    use std::io::Write;
2860    use std::fmt::Write as _;
2861    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2862
2863    // Normal case for AES-128
2864    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2865    println!("K =\t{:#016X}", key);
2866    let mut a_aes = AES_128::new_with_key_u128(key);
2867
2868    let message = "In the beginning God created the heavens and the earth.";
2869    println!("M =\t{}", message);
2870    let mut cipher = Vec::<u8>::new();
2871    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2872    print!("C =\t");
2873    for c in cipher.clone()
2874        { print!("{:02X} ", c); }
2875    println!();
2876    let mut txt = String::new();
2877    for c in cipher.clone()
2878        { write!(txt, "{:02X} ", c); }
2879    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2880
2881    let mut recovered = Vec::<u8>::new();
2882    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2883    print!("Ba =\t");
2884    for b in recovered.clone()
2885        { print!("{:02X} ", b); }
2886    println!();
2887    let mut txt = String::new();
2888    for c in recovered.clone()
2889        { write!(txt, "{:02X} ", c); }
2890    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2891
2892    let mut converted = String::new();
2893    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2894    
2895    println!("Bb =\t{}", converted);
2896    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2897    assert_eq!(converted, message);
2898    println!();
2899
2900    // Normal case for AES-192
2901    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2902    print!("K =\t");
2903    for i in 0..24
2904        { print!("{:02X}", key[i]); }
2905    println!();
2906    let mut a_aes = AES_192::new_with_key(&key);
2907
2908    let message = "In the beginning God created the heavens and the earth.";
2909    println!("M =\t{}", message);
2910    let mut cipher = Vec::<u8>::new();
2911    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2912    print!("C =\t");
2913    for c in cipher.clone()
2914        { print!("{:02X} ", c); }
2915    println!();
2916    let mut txt = String::new();
2917    for c in cipher.clone()
2918        { write!(txt, "{:02X} ", c); }
2919    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2920
2921    let mut recovered = Vec::<u8>::new();
2922    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2923    print!("Ba =\t");
2924    for b in recovered.clone()
2925        { print!("{:02X} ", b); }
2926    println!();
2927    let mut txt = String::new();
2928    for c in recovered.clone()
2929        { write!(txt, "{:02X} ", c); }
2930    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2931
2932    let mut converted = String::new();
2933    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2934    
2935    println!("Bb =\t{}", converted);
2936    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2937    assert_eq!(converted, message);
2938    println!();
2939
2940    // Normal case for AES-256
2941    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2942    print!("K =\t");
2943    for i in 0..32
2944        { print!("{:02X}", key[i]); }
2945    println!();
2946    let mut a_aes = AES_256::new_with_key(&key);
2947
2948    let message = "In the beginning God created the heavens and the earth.";
2949    println!("M =\t{}", message);
2950    let mut cipher = Vec::<u8>::new();
2951    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2952    print!("C =\t");
2953    for c in cipher.clone()
2954        { print!("{:02X} ", c); }
2955    println!();
2956    let mut txt = String::new();
2957    for c in cipher.clone()
2958        { write!(txt, "{:02X} ", c); }
2959    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2960
2961    let mut recovered = Vec::<u8>::new();
2962    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2963    print!("Ba =\t");
2964    for b in recovered.clone()
2965        { print!("{:02X} ", b); }
2966    println!();
2967    let mut txt = String::new();
2968    for c in recovered.clone()
2969        { write!(txt, "{:02X} ", c); }
2970    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2971
2972    let mut converted = String::new();
2973    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2974    
2975    println!("Bb =\t{}", converted);
2976    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2977    assert_eq!(converted, message);
2978    println!();
2979
2980    // Normal case for Rijndael-256-256
2981    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2982    print!("K =\t");
2983    for i in 0..32
2984        { print!("{:02X}", key[i]); }
2985    println!();
2986    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2987
2988    let message = "In the beginning God created the heavens and the earth.";
2989    println!("M =\t{}", message);
2990    let mut cipher = Vec::<u8>::new();
2991    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2992    print!("C =\t");
2993    for c in cipher.clone()
2994        { print!("{:02X} ", c); }
2995    println!();
2996    let mut txt = String::new();
2997    for c in cipher.clone()
2998        { write!(txt, "{:02X} ", c); }
2999    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3000
3001    let mut recovered = Vec::<u8>::new();
3002    a_rijndael.decrypt_vec_into_vec(&cipher, &mut recovered);
3003    print!("Ba =\t");
3004    for b in recovered.clone()
3005        { print!("{:02X} ", b); }
3006    println!();
3007    let mut txt = String::new();
3008    for c in recovered.clone()
3009        { write!(txt, "{:02X} ", c); }
3010    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3011
3012    let mut converted = String::new();
3013    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3014    
3015    println!("Bb =\t{}", converted);
3016    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3017    assert_eq!(converted, message);
3018    println!();
3019
3020    // Normal case for Rijndael-512-512 for post-quantum
3021    use cryptocol::number::SharedArrays;
3022    use cryptocol::hash::SHA3_512;
3023    let mut sha3 = SHA3_512::new();
3024    sha3.absorb_str("Post-quantum");
3025    let key: [u8; 64] = sha3.get_hash_value_in_array();
3026    print!("K =\t");
3027    for i in 0..64
3028        { print!("{:02X}", key[i]); }
3029    println!();
3030    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3031
3032    let message = "In the beginning God created the heavens and the earth.";
3033    println!("M =\t{}", message);
3034    let mut cipher = Vec::<u8>::new();
3035    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3036    print!("C =\t");
3037    for c in cipher.clone()
3038        { print!("{:02X} ", c); }
3039    println!();
3040    let mut txt = String::new();
3041    for c in cipher.clone()
3042        { write!(txt, "{:02X} ", c); }
3043    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3044    
3045    let mut recovered = Vec::<u8>::new();
3046    a_rijndael.decrypt_vec_into_vec(&cipher, &mut recovered);
3047    print!("Ba =\t");
3048    for b in recovered.clone()
3049        { print!("{:02X} ", b); }
3050    println!();
3051    let mut txt = String::new();
3052    for c in recovered.clone()
3053        { write!(txt, "{:02X} ", c); }
3054    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3055
3056    let mut converted = String::new();
3057    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3058    
3059    println!("Bb =\t{}", converted);
3060    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3061    assert_eq!(converted, message);
3062    println!("-------------------------------");
3063}
3064
3065fn aes_decrypt_vec_with_padding_iso_ecb_into_array()
3066{
3067    println!("aes_decrypt_vec_with_padding_iso_ecb_into_array()");
3068    use std::io::Write;
3069    use std::fmt::Write as _;
3070    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3071
3072    // Normal case for AES-128
3073    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3074    println!("K =\t{:#016X}", key);
3075    let mut a_aes = AES_128::new_with_key_u128(key);
3076
3077    let message = "In the beginning God created the heavens and the earth.";
3078    println!("M =\t{}", message);
3079    let mut cipher = Vec::<u8>::new();
3080    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3081    print!("C =\t");
3082    for c in cipher.clone()
3083        { print!("{:02X} ", c); }
3084    println!();
3085    let mut txt = String::new();
3086    for c in cipher.clone()
3087        { write!(txt, "{:02X} ", c); }
3088    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3089
3090    let mut recovered = [0; 64];
3091    let len = a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3092    print!("Ba =\t");
3093    for b in recovered.clone()
3094        { print!("{:02X} ", b); }
3095    println!();
3096    let mut txt = String::new();
3097    for c in recovered.clone()
3098        { write!(txt, "{:02X} ", c); }
3099    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3100
3101    let mut converted = String::new();
3102    unsafe { converted.as_mut_vec() }.write(&recovered);
3103    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3104    println!("Bb =\t{}", converted);
3105    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3106    assert_eq!(converted, message);
3107    println!();
3108
3109    // Normal case for AES-192
3110    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3111    print!("K =\t");
3112    for i in 0..24
3113        { print!("{:02X}", key[i]); }
3114    println!();
3115    let mut a_aes = AES_192::new_with_key(&key);
3116
3117    let message = "In the beginning God created the heavens and the earth.";
3118    println!("M =\t{}", message);
3119    let mut cipher = Vec::<u8>::new();
3120    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3121    print!("C =\t");
3122    for c in cipher.clone()
3123        { print!("{:02X} ", c); }
3124    println!();
3125    let mut txt = String::new();
3126    for c in cipher.clone()
3127        { write!(txt, "{:02X} ", c); }
3128    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3129
3130    let mut recovered = [0; 64];
3131    a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3132    print!("Ba =\t");
3133    for b in recovered.clone()
3134        { print!("{:02X} ", b); }
3135    println!();
3136    let mut txt = String::new();
3137    for c in recovered.clone()
3138        { write!(txt, "{:02X} ", c); }
3139    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3140
3141    let mut converted = String::new();
3142    unsafe { converted.as_mut_vec() }.write(&recovered);
3143    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3144    println!("Bb =\t{}", converted);
3145    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3146    assert_eq!(converted, message);
3147    println!();
3148
3149    // Normal case for AES-256
3150    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3151    print!("K =\t");
3152    for i in 0..32
3153        { print!("{:02X}", key[i]); }
3154    println!();
3155    let mut a_aes = AES_256::new_with_key(&key);
3156
3157    let message = "In the beginning God created the heavens and the earth.";
3158    println!("M =\t{}", message);
3159    let mut cipher = Vec::<u8>::new();
3160    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3161    print!("C =\t");
3162    for c in cipher.clone()
3163        { print!("{:02X} ", c); }
3164    println!();
3165    let mut txt = String::new();
3166    for c in cipher.clone()
3167        { write!(txt, "{:02X} ", c); }
3168    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3169
3170    let mut recovered = [0; 64];
3171    a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3172    print!("Ba =\t");
3173    for b in recovered.clone()
3174        { print!("{:02X} ", b); }
3175    println!();
3176    let mut txt = String::new();
3177    for c in recovered.clone()
3178        { write!(txt, "{:02X} ", c); }
3179    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3180
3181    let mut converted = String::new();
3182    unsafe { converted.as_mut_vec() }.write(&recovered);
3183    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3184    println!("Bb =\t{}", converted);
3185    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3186    assert_eq!(converted, message);
3187    println!();
3188
3189    // Normal case for Rijndael-256-256
3190    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3191    print!("K =\t");
3192    for i in 0..32
3193        { print!("{:02X}", key[i]); }
3194    println!();
3195    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3196
3197    let message = "In the beginning God created the heavens and the earth.";
3198    println!("M =\t{}", message);
3199    let mut cipher = Vec::<u8>::new();
3200    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3201    print!("C =\t");
3202    for c in cipher.clone()
3203        { print!("{:02X} ", c); }
3204    println!();
3205    let mut txt = String::new();
3206    for c in cipher.clone()
3207        { write!(txt, "{:02X} ", c); }
3208    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3209
3210    let mut recovered = [0; 64];
3211    a_rijndael.decrypt_vec_into_array(&cipher, &mut recovered);
3212    print!("Ba =\t");
3213    for b in recovered.clone()
3214        { print!("{:02X} ", b); }
3215    println!();
3216    let mut txt = String::new();
3217    for c in recovered.clone()
3218        { write!(txt, "{:02X} ", c); }
3219    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3220
3221    let mut converted = String::new();
3222    unsafe { converted.as_mut_vec() }.write(&recovered);
3223    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3224    println!("Bb =\t{}", converted);
3225    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3226    assert_eq!(converted, message);
3227    println!();
3228
3229    // Normal case for Rijndael-512-512 for post-quantum
3230    use cryptocol::number::SharedArrays;
3231    use cryptocol::hash::SHA3_512;
3232    let mut sha3 = SHA3_512::new();
3233    sha3.absorb_str("Post-quantum");
3234    let key: [u8; 64] = sha3.get_hash_value_in_array();
3235    print!("K =\t");
3236    for i in 0..64
3237        { print!("{:02X}", key[i]); }
3238    println!();
3239    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3240
3241    let message = "In the beginning God created the heavens and the earth.";
3242    println!("M =\t{}", message);
3243    let mut cipher = Vec::<u8>::new();
3244    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3245    print!("C =\t");
3246    for c in cipher.clone()
3247        { print!("{:02X} ", c); }
3248    println!();
3249    let mut txt = String::new();
3250    for c in cipher.clone()
3251        { write!(txt, "{:02X} ", c); }
3252    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3253    
3254    let mut recovered = [0; 64];
3255    a_rijndael.decrypt_vec_into_array(&cipher, &mut recovered);
3256    print!("Ba =\t");
3257    for b in recovered.clone()
3258        { print!("{:02X} ", b); }
3259    println!();
3260    let mut txt = String::new();
3261    for c in recovered.clone()
3262        { write!(txt, "{:02X} ", c); }
3263    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3264
3265    let mut converted = String::new();
3266    unsafe { converted.as_mut_vec() }.write(&recovered);
3267    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3268    println!("Bb =\t{}", converted);
3269    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3270    assert_eq!(converted, message);
3271    println!("-------------------------------");
3272}
3273
3274fn aes_decrypt_vec_with_padding_iso_ecb_into_string()
3275{
3276    println!("aes_decrypt_vec_with_padding_iso_ecb_into_string()");
3277    use std::io::Write;
3278    use std::fmt::Write as _;
3279    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3280
3281    // Normal case for AES-128
3282    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3283    println!("K =\t{:#016X}", key);
3284    let mut a_aes = AES_128::new_with_key_u128(key);
3285
3286    let message = "In the beginning God created the heavens and the earth.";
3287    println!("M =\t{}", message);
3288    let mut cipher = Vec::<u8>::new();
3289    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3290    print!("C =\t");
3291    for c in cipher.clone()
3292        { print!("{:02X} ", c); }
3293    println!();
3294    let mut txt = String::new();
3295    for c in cipher.clone()
3296        { write!(txt, "{:02X} ", c); }
3297    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3298
3299    let mut converted= String::new();
3300    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3301    println!("B =\t{}", converted);
3302    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3303    assert_eq!(converted, message);
3304    println!();
3305
3306    // Normal case for AES-192
3307    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3308    print!("K =\t");
3309    for i in 0..24
3310        { print!("{:02X}", key[i]); }
3311    println!();
3312    let mut a_aes = AES_192::new_with_key(&key);
3313
3314    let message = "In the beginning God created the heavens and the earth.";
3315    println!("M =\t{}", message);
3316    let mut cipher = Vec::<u8>::new();
3317    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3318    print!("C =\t");
3319    for c in cipher.clone()
3320        { print!("{:02X} ", c); }
3321    println!();
3322    let mut txt = String::new();
3323    for c in cipher.clone()
3324        { write!(txt, "{:02X} ", c); }
3325    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3326
3327    let mut converted= String::new();
3328    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3329    println!("B =\t{}", converted);
3330    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3331    assert_eq!(converted, message);
3332    println!();
3333
3334    // Normal case for AES-256
3335    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3336    print!("K =\t");
3337    for i in 0..32
3338        { print!("{:02X}", key[i]); }
3339    println!();
3340    let mut a_aes = AES_256::new_with_key(&key);
3341
3342    let message = "In the beginning God created the heavens and the earth.";
3343    println!("M =\t{}", message);
3344    let mut cipher = Vec::<u8>::new();
3345    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3346    print!("C =\t");
3347    for c in cipher.clone()
3348        { print!("{:02X} ", c); }
3349    println!();
3350    let mut txt = String::new();
3351    for c in cipher.clone()
3352        { write!(txt, "{:02X} ", c); }
3353    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3354
3355    let mut converted= String::new();
3356    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3357    println!("B =\t{}", converted);
3358    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3359    assert_eq!(converted, message);
3360    println!();
3361
3362    // Normal case for Rijndael-256-256
3363    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3364    print!("K =\t");
3365    for i in 0..32
3366        { print!("{:02X}", key[i]); }
3367    println!();
3368    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3369
3370    let message = "In the beginning God created the heavens and the earth.";
3371    println!("M =\t{}", message);
3372    let mut cipher = Vec::<u8>::new();
3373    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3374    print!("C =\t");
3375    for c in cipher.clone()
3376        { print!("{:02X} ", c); }
3377    println!();
3378    let mut txt = String::new();
3379    for c in cipher.clone()
3380        { write!(txt, "{:02X} ", c); }
3381    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3382
3383    let mut converted= String::new();
3384    a_rijndael.decrypt_vec_into_string(&cipher, &mut converted);
3385    println!("B =\t{}", converted);
3386    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3387    assert_eq!(converted, message);
3388    println!();
3389
3390    // Normal case for Rijndael-512-512 for post-quantum
3391    use cryptocol::number::SharedArrays;
3392    use cryptocol::hash::SHA3_512;
3393    let mut sha3 = SHA3_512::new();
3394    sha3.absorb_str("Post-quantum");
3395    let key: [u8; 64] = sha3.get_hash_value_in_array();
3396    print!("K =\t");
3397    for i in 0..64
3398        { print!("{:02X}", key[i]); }
3399    println!();
3400    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3401
3402    let message = "In the beginning God created the heavens and the earth.";
3403    println!("M =\t{}", message);
3404    let mut cipher = Vec::<u8>::new();
3405    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3406    print!("C =\t");
3407    for c in cipher.clone()
3408        { print!("{:02X} ", c); }
3409    println!();
3410    let mut txt = String::new();
3411    for c in cipher.clone()
3412        { write!(txt, "{:02X} ", c); }
3413    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3414    
3415    let mut converted= String::new();
3416    a_rijndael.decrypt_vec_into_string(&cipher, &mut converted);
3417    println!("B =\t{}", converted);
3418    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3419    assert_eq!(converted, message);
3420    println!("-------------------------------");
3421}
3422
3423fn aes_decrypt_array_with_padding_iso_ecb()
3424{
3425    println!("aes_decrypt_array_with_padding_iso_ecb()");
3426    use std::io::Write;
3427    use std::fmt::Write as _;
3428    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3429
3430    // Normal case for AES-128
3431    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3432    println!("K =\t{:#016X}", key);
3433    let mut a_aes = AES_128::new_with_key_u128(key);
3434
3435    let message = "In the beginning God created the heavens and the earth.";
3436    println!("M =\t{}", message);
3437    let mut cipher = [0_u8; 64];
3438    a_aes.encrypt_str_into_array(&message, &mut cipher);
3439    print!("C =\t");
3440    for c in cipher.clone()
3441        { print!("{:02X} ", c); }
3442    println!();
3443    let mut txt = String::new();
3444    for c in cipher.clone()
3445        { write!(txt, "{:02X} ", c); }
3446    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3447
3448    let mut recovered = vec![0; 55];
3449    a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
3450    print!("Ba =\t");
3451    for b in recovered.clone()
3452        { print!("{:02X} ", b); }
3453    println!();
3454    let mut txt = String::new();
3455    for c in recovered.clone()
3456        { write!(txt, "{:02X} ", c); }
3457    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3458
3459    let mut converted = String::new();
3460    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3461    
3462    println!("Bb =\t{}", converted);
3463    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3464    assert_eq!(converted, message);
3465    println!();
3466
3467    // Normal case for AES-192
3468    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3469    print!("K =\t");
3470    for i in 0..24
3471        { print!("{:02X}", key[i]); }
3472    println!();
3473    let mut a_aes = AES_192::new_with_key(&key);
3474
3475    let message = "In the beginning God created the heavens and the earth.";
3476    println!("M =\t{}", message);
3477    let mut cipher = [0_u8; 64];
3478    a_aes.encrypt_str_into_array(&message, &mut cipher);
3479    print!("C =\t");
3480    for c in cipher.clone()
3481        { print!("{:02X} ", c); }
3482    println!();
3483    let mut txt = String::new();
3484    for c in cipher.clone()
3485        { write!(txt, "{:02X} ", c); }
3486    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3487
3488    let mut recovered = vec![0; 55];
3489    a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
3490    print!("Ba =\t");
3491    for b in recovered.clone()
3492        { print!("{:02X} ", b); }
3493    println!();
3494    let mut txt = String::new();
3495    for c in recovered.clone()
3496        { write!(txt, "{:02X} ", c); }
3497    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3498
3499    let mut converted = String::new();
3500    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3501    
3502    println!("Bb =\t{}", converted);
3503    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3504    assert_eq!(converted, message);
3505    println!();
3506
3507    // Normal case for AES-256
3508    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3509    print!("K =\t");
3510    for i in 0..32
3511        { print!("{:02X}", key[i]); }
3512    println!();
3513    let mut a_aes = AES_256::new_with_key(&key);
3514
3515    let message = "In the beginning God created the heavens and the earth.";
3516    println!("M =\t{}", message);
3517    let mut cipher = [0_u8; 64];
3518    a_aes.encrypt_str_into_array(&message, &mut cipher);
3519    print!("C =\t");
3520    for c in cipher.clone()
3521        { print!("{:02X} ", c); }
3522    println!();
3523    let mut txt = String::new();
3524    for c in cipher.clone()
3525        { write!(txt, "{:02X} ", c); }
3526    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3527
3528    let mut recovered = vec![0; 55];
3529    a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
3530    print!("Ba =\t");
3531    for b in recovered.clone()
3532        { print!("{:02X} ", b); }
3533    println!();
3534    let mut txt = String::new();
3535    for c in recovered.clone()
3536        { write!(txt, "{:02X} ", c); }
3537    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3538
3539    let mut converted = String::new();
3540    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3541    
3542    println!("Bb =\t{}", converted);
3543    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3544    assert_eq!(converted, message);
3545    println!();
3546
3547    // Normal case for Rijndael-256-256
3548    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3549    print!("K =\t");
3550    for i in 0..32
3551        { print!("{:02X}", key[i]); }
3552    println!();
3553    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3554
3555    let message = "In the beginning God created the heavens and the earth.";
3556    println!("M =\t{}", message);
3557    let mut cipher = [0_u8; 64];
3558    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3559    print!("C =\t");
3560    for c in cipher.clone()
3561        { print!("{:02X} ", c); }
3562    println!();
3563    let mut txt = String::new();
3564    for c in cipher.clone()
3565        { write!(txt, "{:02X} ", c); }
3566    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3567
3568    let mut recovered = vec![0; 55];
3569    a_rijndael.decrypt_array(&cipher, recovered.as_mut_ptr());
3570    print!("Ba =\t");
3571    for b in recovered.clone()
3572        { print!("{:02X} ", b); }
3573    println!();
3574    let mut txt = String::new();
3575    for c in recovered.clone()
3576        { write!(txt, "{:02X} ", c); }
3577    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3578
3579    let mut converted = String::new();
3580    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3581    
3582    println!("Bb =\t{}", converted);
3583    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3584    assert_eq!(converted, message);
3585    println!();
3586
3587    // Normal case for Rijndael-512-512 for post-quantum
3588    use cryptocol::number::SharedArrays;
3589    use cryptocol::hash::SHA3_512;
3590    let mut sha3 = SHA3_512::new();
3591    sha3.absorb_str("Post-quantum");
3592    let key: [u8; 64] = sha3.get_hash_value_in_array();
3593    print!("K =\t");
3594    for i in 0..64
3595        { print!("{:02X}", key[i]); }
3596    println!();
3597    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3598    let message = "In the beginning God created the heavens and the earth.";
3599    println!("M =\t{}", message);
3600    let mut cipher = [0_u8; 64];
3601    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3602    print!("C =\t");
3603    for c in cipher.clone()
3604        { print!("{:02X} ", c); }
3605    println!();
3606    let mut txt = String::new();
3607    for c in cipher.clone()
3608        { write!(txt, "{:02X} ", c); }
3609    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3610    
3611    let mut recovered = vec![0; 55];
3612    a_rijndael.decrypt_array(&cipher, recovered.as_mut_ptr());
3613    print!("Ba =\t");
3614    for b in recovered.clone()
3615        { print!("{:02X} ", b); }
3616    println!();
3617    let mut txt = String::new();
3618    for c in recovered.clone()
3619        { write!(txt, "{:02X} ", c); }
3620    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3621
3622    let mut converted = String::new();
3623    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3624    
3625    println!("Bb =\t{}", converted);
3626    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3627    assert_eq!(converted, message);
3628    println!("-------------------------------");
3629}
3630
3631fn aes_decrypt_array_with_padding_iso_ecb_into_vec()
3632{
3633    println!("aes_decrypt_array_with_padding_iso_ecb_into_vec()");
3634    use std::io::Write;
3635    use std::fmt::Write as _;
3636    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3637
3638    // Normal case for AES-128
3639    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3640    println!("K =\t{:#016X}", key);
3641    let mut a_aes = AES_128::new_with_key_u128(key);
3642
3643    let message = "In the beginning God created the heavens and the earth.";
3644    println!("M =\t{}", message);
3645    let mut cipher = [0_u8; 64];
3646    a_aes.encrypt_str_into_array(&message, &mut cipher);
3647    print!("C =\t");
3648    for c in cipher.clone()
3649        { print!("{:02X} ", c); }
3650    println!();
3651    let mut txt = String::new();
3652    for c in cipher.clone()
3653        { write!(txt, "{:02X} ", c); }
3654    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3655
3656    let mut recovered = vec![0; 55];
3657    a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
3658    print!("Ba =\t");
3659    for b in recovered.clone()
3660        { print!("{:02X} ", b); }
3661    println!();
3662    let mut txt = String::new();
3663    for c in recovered.clone()
3664        { write!(txt, "{:02X} ", c); }
3665    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3666
3667    let mut converted = String::new();
3668    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3669    
3670    println!("Bb =\t{}", converted);
3671    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3672    assert_eq!(converted, message);
3673    println!();
3674
3675    // Normal case for AES-192
3676    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3677    print!("K =\t");
3678    for i in 0..24
3679        { print!("{:02X}", key[i]); }
3680    println!();
3681    let mut a_aes = AES_192::new_with_key(&key);
3682
3683    let message = "In the beginning God created the heavens and the earth.";
3684    println!("M =\t{}", message);
3685    let mut cipher = [0_u8; 64];
3686    a_aes.encrypt_str_into_array(&message, &mut cipher);
3687    print!("C =\t");
3688    for c in cipher.clone()
3689        { print!("{:02X} ", c); }
3690    println!();
3691    let mut txt = String::new();
3692    for c in cipher.clone()
3693        { write!(txt, "{:02X} ", c); }
3694    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3695
3696    let mut recovered = vec![0; 55];
3697    a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
3698    print!("Ba =\t");
3699    for b in recovered.clone()
3700        { print!("{:02X} ", b); }
3701    println!();
3702    let mut txt = String::new();
3703    for c in recovered.clone()
3704        { write!(txt, "{:02X} ", c); }
3705    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3706
3707    let mut converted = String::new();
3708    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3709    
3710    println!("Bb =\t{}", converted);
3711    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3712    assert_eq!(converted, message);
3713    println!();
3714
3715    // Normal case for AES-256
3716    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3717    print!("K =\t");
3718    for i in 0..32
3719        { print!("{:02X}", key[i]); }
3720    println!();
3721    let mut a_aes = AES_256::new_with_key(&key);
3722
3723    let message = "In the beginning God created the heavens and the earth.";
3724    println!("M =\t{}", message);
3725    let mut cipher = [0_u8; 64];
3726    a_aes.encrypt_str_into_array(&message, &mut cipher);
3727    print!("C =\t");
3728    for c in cipher.clone()
3729        { print!("{:02X} ", c); }
3730    println!();
3731    let mut txt = String::new();
3732    for c in cipher.clone()
3733        { write!(txt, "{:02X} ", c); }
3734    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3735
3736    let mut recovered = vec![0; 55];
3737    a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
3738    print!("Ba =\t");
3739    for b in recovered.clone()
3740        { print!("{:02X} ", b); }
3741    println!();
3742    let mut txt = String::new();
3743    for c in recovered.clone()
3744        { write!(txt, "{:02X} ", c); }
3745    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3746
3747    let mut converted = String::new();
3748    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3749    
3750    println!("Bb =\t{}", converted);
3751    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3752    assert_eq!(converted, message);
3753    println!();
3754
3755    // Normal case for Rijndael-256-256
3756    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3757    print!("K =\t");
3758    for i in 0..32
3759        { print!("{:02X}", key[i]); }
3760    println!();
3761    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3762
3763    let message = "In the beginning God created the heavens and the earth.";
3764    println!("M =\t{}", message);
3765    let mut cipher = [0_u8; 64];
3766    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3767    print!("C =\t");
3768    for c in cipher.clone()
3769        { print!("{:02X} ", c); }
3770    println!();
3771    let mut txt = String::new();
3772    for c in cipher.clone()
3773        { write!(txt, "{:02X} ", c); }
3774    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3775
3776    let mut recovered = vec![0; 55];
3777    a_rijndael.decrypt_array_into_vec(&cipher, &mut recovered);
3778    print!("Ba =\t");
3779    for b in recovered.clone()
3780        { print!("{:02X} ", b); }
3781    println!();
3782    let mut txt = String::new();
3783    for c in recovered.clone()
3784        { write!(txt, "{:02X} ", c); }
3785    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3786
3787    let mut converted = String::new();
3788    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3789    
3790    println!("Bb =\t{}", converted);
3791    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3792    assert_eq!(converted, message);
3793    println!();
3794
3795    // Normal case for Rijndael-512-512 for post-quantum
3796    use cryptocol::number::SharedArrays;
3797    use cryptocol::hash::SHA3_512;
3798    let mut sha3 = SHA3_512::new();
3799    sha3.absorb_str("Post-quantum");
3800    let key: [u8; 64] = sha3.get_hash_value_in_array();
3801    print!("K =\t");
3802    for i in 0..64
3803        { print!("{:02X}", key[i]); }
3804    println!();
3805    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3806    let message = "In the beginning God created the heavens and the earth.";
3807    println!("M =\t{}", message);
3808    let mut cipher = [0_u8; 64];
3809    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3810    print!("C =\t");
3811    for c in cipher.clone()
3812        { print!("{:02X} ", c); }
3813    println!();
3814    let mut txt = String::new();
3815    for c in cipher.clone()
3816        { write!(txt, "{:02X} ", c); }
3817    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3818
3819    let mut recovered = vec![0; 55];
3820    a_rijndael.decrypt_array_into_vec(&cipher, &mut recovered);
3821    print!("Ba =\t");
3822    for b in recovered.clone()
3823        { print!("{:02X} ", b); }
3824    println!();
3825    let mut txt = String::new();
3826    for c in recovered.clone()
3827        { write!(txt, "{:02X} ", c); }
3828    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3829
3830    let mut converted = String::new();
3831    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3832    
3833    println!("Bb =\t{}", converted);
3834    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3835    assert_eq!(converted, message);
3836    println!("-------------------------------");
3837}
3838
3839fn aes_decrypt_array_with_padding_iso_ecb_into_array()
3840{
3841    println!("aes_decrypt_array_with_padding_iso_ecb_into_array()");
3842    use std::io::Write;
3843    use std::fmt::Write as _;
3844    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3845
3846    // Normal case for AES-128
3847    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3848    println!("K =\t{:#016X}", key);
3849    let mut a_aes = AES_128::new_with_key_u128(key);
3850
3851    let message = "In the beginning God created the heavens and the earth.";
3852    println!("M =\t{}", message);
3853    let mut cipher = [0_u8; 64];
3854    a_aes.encrypt_str_into_array(&message, &mut cipher);
3855    print!("C =\t");
3856    for c in cipher.clone()
3857        { print!("{:02X} ", c); }
3858    println!();
3859    let mut txt = String::new();
3860    for c in cipher.clone()
3861        { write!(txt, "{:02X} ", c); }
3862    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3863
3864    let mut recovered = [0; 64];
3865    let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
3866    print!("Ba =\t");
3867    for b in recovered.clone()
3868        { print!("{:02X} ", b); }
3869    println!();
3870    let mut txt = String::new();
3871    for c in recovered.clone()
3872        { write!(txt, "{:02X} ", c); }
3873    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3874
3875    let mut converted = String::new();
3876    unsafe { converted.as_mut_vec() }.write(&recovered);
3877    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3878    println!("Bb =\t{}", converted);
3879    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3880    assert_eq!(converted, message);
3881    println!();
3882
3883    // Normal case for AES-192
3884    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3885    print!("K =\t");
3886    for i in 0..24
3887        { print!("{:02X}", key[i]); }
3888    println!();
3889    let mut a_aes = AES_192::new_with_key(&key);
3890
3891    let message = "In the beginning God created the heavens and the earth.";
3892    println!("M =\t{}", message);
3893    let mut cipher = [0_u8; 64];
3894    a_aes.encrypt_str_into_array(&message, &mut cipher);
3895    print!("C =\t");
3896    for c in cipher.clone()
3897        { print!("{:02X} ", c); }
3898    println!();
3899    let mut txt = String::new();
3900    for c in cipher.clone()
3901        { write!(txt, "{:02X} ", c); }
3902    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3903
3904    let mut recovered = [0; 64];
3905    let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
3906    print!("Ba =\t");
3907    for b in recovered.clone()
3908        { print!("{:02X} ", b); }
3909    println!();
3910    let mut txt = String::new();
3911    for c in recovered.clone()
3912        { write!(txt, "{:02X} ", c); }
3913    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3914
3915    let mut converted = String::new();
3916    unsafe { converted.as_mut_vec() }.write(&recovered);
3917    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3918    println!("Bb =\t{}", converted);
3919    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3920    assert_eq!(converted, message);
3921    println!();
3922
3923    // Normal case for AES-256
3924    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3925    print!("K =\t");
3926    for i in 0..32
3927        { print!("{:02X}", key[i]); }
3928    println!();
3929    let mut a_aes = AES_256::new_with_key(&key);
3930
3931    let message = "In the beginning God created the heavens and the earth.";
3932    println!("M =\t{}", message);
3933    let mut cipher = [0_u8; 64];
3934    a_aes.encrypt_str_into_array(&message, &mut cipher);
3935    print!("C =\t");
3936    for c in cipher.clone()
3937        { print!("{:02X} ", c); }
3938    println!();
3939    let mut txt = String::new();
3940    for c in cipher.clone()
3941        { write!(txt, "{:02X} ", c); }
3942    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3943
3944    let mut recovered = [0; 64];
3945    let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
3946    print!("Ba =\t");
3947    for b in recovered.clone()
3948        { print!("{:02X} ", b); }
3949    println!();
3950    let mut txt = String::new();
3951    for c in recovered.clone()
3952        { write!(txt, "{:02X} ", c); }
3953    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3954
3955    let mut converted = String::new();
3956    unsafe { converted.as_mut_vec() }.write(&recovered);
3957    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3958    println!("Bb =\t{}", converted);
3959    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3960    assert_eq!(converted, message);
3961    println!();
3962
3963    // Normal case for Rijndael-256-256
3964    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3965    print!("K =\t");
3966    for i in 0..32
3967        { print!("{:02X}", key[i]); }
3968    println!();
3969    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3970
3971    let message = "In the beginning God created the heavens and the earth.";
3972    println!("M =\t{}", message);
3973    let mut cipher = [0_u8; 64];
3974    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3975    print!("C =\t");
3976    for c in cipher.clone()
3977        { print!("{:02X} ", c); }
3978    println!();
3979    let mut txt = String::new();
3980    for c in cipher.clone()
3981        { write!(txt, "{:02X} ", c); }
3982    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3983
3984    let mut recovered = [0; 64];
3985    let len = a_rijndael.decrypt_array_into_array(&cipher, &mut recovered);
3986    print!("Ba =\t");
3987    for b in recovered.clone()
3988        { print!("{:02X} ", b); }
3989    println!();
3990    let mut txt = String::new();
3991    for c in recovered.clone()
3992        { write!(txt, "{:02X} ", c); }
3993    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3994
3995    let mut converted = String::new();
3996    unsafe { converted.as_mut_vec() }.write(&recovered);
3997    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3998    println!("Bb =\t{}", converted);
3999    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4000    assert_eq!(converted, message);
4001    println!();
4002
4003    // Normal case for Rijndael-512-512 for post-quantum
4004    use cryptocol::number::SharedArrays;
4005    use cryptocol::hash::SHA3_512;
4006    let mut sha3 = SHA3_512::new();
4007    sha3.absorb_str("Post-quantum");
4008    let key: [u8; 64] = sha3.get_hash_value_in_array();
4009    print!("K =\t");
4010    for i in 0..64
4011        { print!("{:02X}", key[i]); }
4012    println!();
4013    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
4014    let message = "In the beginning God created the heavens and the earth.";
4015    println!("M =\t{}", message);
4016    let mut cipher = [0_u8; 64];
4017    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
4018    print!("C =\t");
4019    for c in cipher.clone()
4020        { print!("{:02X} ", c); }
4021    println!();
4022    let mut txt = String::new();
4023    for c in cipher.clone()
4024        { write!(txt, "{:02X} ", c); }
4025    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
4026
4027    let mut recovered = [0; 64];
4028    let len = a_rijndael.decrypt_array_into_array(&cipher, &mut recovered);
4029    print!("Ba =\t");
4030    for b in recovered.clone()
4031        { print!("{:02X} ", b); }
4032    println!();
4033    let mut txt = String::new();
4034    for c in recovered.clone()
4035        { write!(txt, "{:02X} ", c); }
4036    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
4037
4038    let mut converted = String::new();
4039    unsafe { converted.as_mut_vec() }.write(&recovered);
4040    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4041    println!("Bb =\t{}", converted);
4042    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4043    assert_eq!(converted, message);
4044    println!("-------------------------------");
4045}
4046
4047fn aes_decrypt_array_with_padding_iso_ecb_into_string()
4048{
4049    println!("aes_decrypt_array_with_padding_iso_ecb_into_string()");
4050    use std::io::Write;
4051    use std::fmt::Write as _;
4052    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
4053
4054    // Normal case for AES-128
4055    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
4056    println!("K =\t{:#016X}", key);
4057    let mut a_aes = AES_128::new_with_key_u128(key);
4058
4059    let message = "In the beginning God created the heavens and the earth.";
4060    println!("M =\t{}", message);
4061    let mut cipher = [0_u8; 64];
4062    a_aes.encrypt_str_into_array(&message, &mut cipher);
4063    print!("C =\t");
4064    for c in cipher.clone()
4065        { print!("{:02X} ", c); }
4066    println!();
4067    let mut txt = String::new();
4068    for c in cipher.clone()
4069        { write!(txt, "{:02X} ", c); }
4070    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
4071
4072    let mut converted= String::new();
4073    a_aes.decrypt_array_into_string(&cipher, &mut converted);
4074    println!("B =\t{}", converted);
4075    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4076    assert_eq!(converted, message);
4077    println!();
4078
4079    // Normal case for AES-192
4080    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
4081    print!("K =\t");
4082    for i in 0..24
4083        { print!("{:02X}", key[i]); }
4084    println!();
4085    let mut a_aes = AES_192::new_with_key(&key);
4086
4087    let message = "In the beginning God created the heavens and the earth.";
4088    println!("M =\t{}", message);
4089    let mut cipher = [0_u8; 64];
4090    a_aes.encrypt_str_into_array(&message, &mut cipher);
4091    print!("C =\t");
4092    for c in cipher.clone()
4093        { print!("{:02X} ", c); }
4094    println!();
4095    let mut txt = String::new();
4096    for c in cipher.clone()
4097        { write!(txt, "{:02X} ", c); }
4098    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
4099
4100    let mut converted= String::new();
4101    a_aes.decrypt_array_into_string(&cipher, &mut converted);
4102    println!("B =\t{}", converted);
4103    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4104    assert_eq!(converted, message);
4105    println!();
4106
4107    // Normal case for AES-256
4108    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
4109    print!("K =\t");
4110    for i in 0..32
4111        { print!("{:02X}", key[i]); }
4112    println!();
4113    let mut a_aes = AES_256::new_with_key(&key);
4114
4115    let message = "In the beginning God created the heavens and the earth.";
4116    println!("M =\t{}", message);
4117    let mut cipher = [0_u8; 64];
4118    a_aes.encrypt_str_into_array(&message, &mut cipher);
4119    print!("C =\t");
4120    for c in cipher.clone()
4121        { print!("{:02X} ", c); }
4122    println!();
4123    let mut txt = String::new();
4124    for c in cipher.clone()
4125        { write!(txt, "{:02X} ", c); }
4126    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
4127
4128    let mut converted= String::new();
4129    a_aes.decrypt_array_into_string(&cipher, &mut converted);
4130    println!("B =\t{}", converted);
4131    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4132    assert_eq!(converted, message);
4133    println!();
4134
4135    // Normal case for Rijndael-256-256
4136    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
4137    print!("K =\t");
4138    for i in 0..32
4139        { print!("{:02X}", key[i]); }
4140    println!();
4141    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
4142
4143    let message = "In the beginning God created the heavens and the earth.";
4144    println!("M =\t{}", message);
4145    let mut cipher = [0_u8; 64];
4146    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
4147    print!("C =\t");
4148    for c in cipher.clone()
4149        { print!("{:02X} ", c); }
4150    println!();
4151    let mut txt = String::new();
4152    for c in cipher.clone()
4153        { write!(txt, "{:02X} ", c); }
4154    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
4155
4156    let mut converted= String::new();
4157    a_rijndael.decrypt_array_into_string(&cipher, &mut converted);
4158    println!("B =\t{}", converted);
4159    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4160    assert_eq!(converted, message);
4161    println!();
4162
4163    // Normal case for Rijndael-512-512 for post-quantum
4164    use cryptocol::number::SharedArrays;
4165    use cryptocol::hash::SHA3_512;
4166    let mut sha3 = SHA3_512::new();
4167    sha3.absorb_str("Post-quantum");
4168    let key: [u8; 64] = sha3.get_hash_value_in_array();
4169    print!("K =\t");
4170    for i in 0..64
4171        { print!("{:02X}", key[i]); }
4172    println!();
4173    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
4174    let message = "In the beginning God created the heavens and the earth.";
4175    println!("M =\t{}", message);
4176    let mut cipher = [0_u8; 64];
4177    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
4178    print!("C =\t");
4179    for c in cipher.clone()
4180        { print!("{:02X} ", c); }
4181    println!();
4182    let mut txt = String::new();
4183    for c in cipher.clone()
4184        { write!(txt, "{:02X} ", c); }
4185    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
4186
4187    let mut converted= String::new();
4188    a_rijndael.decrypt_array_into_string(&cipher, &mut converted);
4189    println!("B =\t{}", converted);
4190    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4191    assert_eq!(converted, message);
4192    println!("-------------------------------");
4193}
examples/des_ecb_iso_examples.rs (line 933)
918fn des_encrypt_str_with_padding_iso_ecb_into_array()
919{
920    println!("des_encrypt_str_with_padding_iso_ecb_into_array()");
921    use std::io::Write;
922    use std::fmt::Write as _;
923    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
924
925    // Normal case
926    let key = 0x_1234567890ABCDEF_u64;
927    println!("K =\t{:#016X}", key);
928    let mut a_des = DES::new_with_key_u64(key);
929
930    let message = "In the beginning God created the heavens and the earth.";
931    println!("M =\t{}", message);
932    let mut cipher = [0_u8; 56];
933    a_des.encrypt_str_into_array(&message, &mut cipher);
934    print!("C (16 rounds) =\t");
935    for c in cipher.clone()
936        { print!("{:02X} ", c); }
937    println!();
938    let mut txt = String::new();
939    for c in cipher.clone()
940        { write!(txt, "{:02X} ", c); }
941    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
942    println!();
943
944    // Expanded case for 128 rounds
945    let key = 0x_1234567890ABCDEF_u64;
946    println!("K =\t{:#016X}", key);
947    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
948
949    let message = "In the beginning God created the heavens and the earth.";
950    println!("M =\t{}", message);
951    let mut cipher = [0_u8; 56];
952    a_des.encrypt_str_into_array(&message, &mut cipher);
953    print!("C (128 rounds) =\t");
954    for c in cipher.clone()
955        { print!("{:02X} ", c); }
956    println!();
957    let mut txt = String::new();
958    for c in cipher.clone()
959        { write!(txt, "{:02X} ", c); }
960    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
961    println!();
962
963    // Expanded case for 0 rounds which means that key is meaningless
964    let key1 = 0x_1234567890ABCDEF_u64;
965    let key2 = 0_u64;
966    println!("K =\t{:#016X}", key);
967    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
968    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
969
970    let message = "In the beginning God created the heavens and the earth.";
971    println!("M =\t{}", message);
972    let mut cipher1 = [0_u8; 56];
973    let mut cipher2 = [0_u8; 56];
974    c_des.encrypt_str_into_array(&message, &mut cipher1);
975    d_des.encrypt_str_into_array(&message, &mut cipher2);
976    print!("C (0 rounds) =\t");
977    for c in cipher1.clone()
978        { print!("{:02X} ", c); }
979    println!();
980    let mut txt = String::new();
981    for c in cipher1.clone()
982        { write!(txt, "{:02X} ", c); }
983    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
984    print!("D (0 rounds) =\t");
985    for c in cipher2.clone()
986        { print!("{:02X} ", c); }
987    println!();
988    let mut txt = String::new();
989    for c in cipher2.clone()
990        { write!(txt, "{:02X} ", c); }
991    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
992    println!();
993
994    // Normal case for the message of 0 bytes
995    let key = 0x_1234567890ABCDEF_u64;
996    println!("K =\t{:#016X}", key);
997    let mut a_des = DES::new_with_key_u64(key);
998
999    let message = "";
1000    println!("M =\t{}", message);
1001    let mut cipher = [0_u8; 8];
1002    a_des.encrypt_str_into_array(&message, &mut cipher);
1003    print!("C =\t");
1004    for c in cipher.clone()
1005        { print!("{:02X} ", c); }
1006    println!();
1007    let mut txt = String::new();
1008    for c in cipher.clone()
1009        { write!(txt, "{:02X} ", c); }
1010    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1011    println!();
1012
1013    // Normal case for the message shorter than 8 bytes
1014    let key = 0x_1234567890ABCDEF_u64;
1015    println!("K =\t{:#016X}", key);
1016    let mut a_des = DES::new_with_key_u64(key);
1017
1018    let message = "7 bytes";
1019    println!("M =\t{}", message);
1020    let mut cipher = [0_u8; 8];
1021    a_des.encrypt_str_into_array(&message, &mut cipher);
1022    print!("C =\t");
1023    for c in cipher.clone()
1024        { print!("{:02X} ", c); }
1025    println!();
1026    let mut txt = String::new();
1027    for c in cipher.clone()
1028        { write!(txt, "{:02X} ", c); }
1029    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1030    println!();
1031
1032    // Normal case for the message of 8 bytes
1033    let key = 0x_1234567890ABCDEF_u64;
1034    println!("K =\t{:#016X}", key);
1035    let mut a_des = DES::new_with_key_u64(key);
1036
1037    let message = "I am OK.";
1038    println!("M =\t{}", message);
1039    let mut cipher = [0_u8; 16];
1040    a_des.encrypt_str_into_array(&message, &mut cipher);
1041    print!("C =\t");
1042    for c in cipher.clone()
1043        { print!("{:02X} ", c); }
1044    println!();
1045    let mut txt = String::new();
1046    for c in cipher.clone()
1047        { write!(txt, "{:02X} ", c); }
1048    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1049    println!();
1050
1051    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1052    let key = 0x_1234567890ABCDEF_u64;
1053    println!("K =\t{:#016X}", key);
1054    let mut a_des = DES::new_with_key_u64(key);
1055
1056    let message = "PARK Youngho";
1057    println!("M =\t{}", message);
1058    let mut cipher = [0_u8; 16];
1059    a_des.encrypt_str_into_array(&message, &mut cipher);
1060    print!("C =\t");
1061    for c in cipher.clone()
1062        { print!("{:02X} ", c); }
1063    println!();
1064    let mut txt = String::new();
1065    for c in cipher.clone()
1066        { write!(txt, "{:02X} ", c); }
1067    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1068    println!();
1069
1070
1071    // Normal case for the message of 16 bytes
1072    let key = 0x_1234567890ABCDEF_u64;
1073    println!("K =\t{:#016X}", key);
1074    let mut a_des = DES::new_with_key_u64(key);
1075
1076    let message = "고맙습니다.";
1077    println!("M =\t{}", message);
1078    let mut cipher = [0_u8; 24];
1079    a_des.encrypt_str_into_array(&message, &mut cipher);
1080    print!("C =\t");
1081    for c in cipher.clone()
1082        { print!("{:02X} ", c); }
1083    println!();
1084    let mut txt = String::new();
1085    for c in cipher.clone()
1086        { write!(txt, "{:02X} ", c); }
1087    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1088    println!("-------------------------------");
1089}
1090
1091fn des_encrypt_string_with_padding_iso_ecb()
1092{
1093    println!("des_encrypt_string_with_padding_iso_ecb()");
1094    use std::io::Write;
1095    use std::fmt::Write as _;
1096    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1097
1098    // Normal case
1099    let key = 0x_1234567890ABCDEF_u64;
1100    println!("K =\t{:#016X}", key);
1101    let mut a_des = DES::new_with_key_u64(key);
1102
1103    let message = "In the beginning God created the heavens and the earth.".to_string();
1104    println!("M =\t{}", message);
1105    let mut cipher = [0_u8; 56];
1106    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1107    print!("C (16 rounds) =\t");
1108    for c in cipher.clone()
1109        { print!("{:02X} ", c); }
1110    println!();
1111    let mut txt = String::new();
1112    for c in cipher.clone()
1113        { write!(txt, "{:02X} ", c); }
1114    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1115    println!();
1116
1117    // Expanded case for 128 rounds
1118    let key = 0x_1234567890ABCDEF_u64;
1119    println!("K =\t{:#016X}", key);
1120    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1121
1122    let message = "In the beginning God created the heavens and the earth.".to_string();
1123    println!("M =\t{}", message);
1124    let mut cipher = [0_u8; 56];
1125    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1126    print!("C (128 rounds) =\t");
1127    for c in cipher.clone()
1128        { print!("{:02X} ", c); }
1129    println!();
1130    let mut txt = String::new();
1131    for c in cipher.clone()
1132        { write!(txt, "{:02X} ", c); }
1133    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1134    println!();
1135
1136    // Expanded case for 0 rounds which means that key is meaningless
1137    let key1 = 0x_1234567890ABCDEF_u64;
1138    let key2 = 0_u64;
1139    println!("K =\t{:#016X}", key);
1140    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1141    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1142
1143    let message = "In the beginning God created the heavens and the earth.".to_string();
1144    println!("M =\t{}", message);
1145    let mut cipher1 = [0_u8; 56];
1146    let mut cipher2 = [0_u8; 56];
1147    c_des.encrypt_string(&message, cipher1.as_mut_ptr());
1148    d_des.encrypt_string(&message, cipher2.as_mut_ptr());
1149    print!("C (0 rounds) =\t");
1150    for c in cipher1.clone()
1151        { print!("{:02X} ", c); }
1152    println!();
1153    let mut txt = String::new();
1154    for c in cipher1.clone()
1155        { write!(txt, "{:02X} ", c); }
1156    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1157    print!("D (0 rounds) =\t");
1158    for c in cipher2.clone()
1159        { print!("{:02X} ", c); }
1160    println!();
1161    let mut txt = String::new();
1162    for c in cipher2.clone()
1163        { write!(txt, "{:02X} ", c); }
1164    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1165    println!();
1166
1167    // Normal case for the message of 0 bytes
1168    let key = 0x_1234567890ABCDEF_u64;
1169    println!("K =\t{:#016X}", key);
1170    let mut a_des = DES::new_with_key_u64(key);
1171
1172    let message = "".to_string();
1173    println!("M =\t{}", message);
1174    let mut cipher = [0_u8; 8];
1175    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1176    print!("C =\t");
1177    for c in cipher.clone()
1178        { print!("{:02X} ", c); }
1179    println!();
1180    let mut txt = String::new();
1181    for c in cipher.clone()
1182        { write!(txt, "{:02X} ", c); }
1183    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1184    println!();
1185
1186    // Normal case for the message shorter than 8 bytes
1187    let key = 0x_1234567890ABCDEF_u64;
1188    println!("K =\t{:#016X}", key);
1189    let mut a_des = DES::new_with_key_u64(key);
1190
1191    let message = "7 bytes".to_string();
1192    println!("M =\t{}", message);
1193    let mut cipher = [0_u8; 8];
1194    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1195    print!("C =\t");
1196    for c in cipher.clone()
1197        { print!("{:02X} ", c); }
1198    println!();
1199    let mut txt = String::new();
1200    for c in cipher.clone()
1201        { write!(txt, "{:02X} ", c); }
1202    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1203    println!();
1204
1205    // Normal case for the message of 8 bytes
1206    let key = 0x_1234567890ABCDEF_u64;
1207    println!("K =\t{:#016X}", key);
1208    let mut a_des = DES::new_with_key_u64(key);
1209
1210    let message = "I am OK.".to_string();
1211    println!("M =\t{}", message);
1212    let mut cipher = [0_u8; 16];
1213    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1214    print!("C =\t");
1215    for c in cipher.clone()
1216        { print!("{:02X} ", c); }
1217    println!();
1218    let mut txt = String::new();
1219    for c in cipher.clone()
1220        { write!(txt, "{:02X} ", c); }
1221    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1222    println!();
1223
1224    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1225    let key = 0x_1234567890ABCDEF_u64;
1226    println!("K =\t{:#016X}", key);
1227    let mut a_des = DES::new_with_key_u64(key);
1228
1229    let message = "PARK Youngho".to_string();
1230    println!("M =\t{}", message);
1231    let mut cipher = [0_u8; 16];
1232    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1233    print!("C =\t");
1234    for c in cipher.clone()
1235        { print!("{:02X} ", c); }
1236    println!();
1237    let mut txt = String::new();
1238    for c in cipher.clone()
1239        { write!(txt, "{:02X} ", c); }
1240    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1241    println!();
1242
1243
1244    // Normal case for the message of 16 bytes
1245    let key = 0x_1234567890ABCDEF_u64;
1246    println!("K =\t{:#016X}", key);
1247    let mut a_des = DES::new_with_key_u64(key);
1248
1249    let message = "고맙습니다.".to_string();
1250    println!("M =\t{}", message);
1251    let mut cipher = [0_u8; 24];
1252    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1253    print!("C =\t");
1254    for c in cipher.clone()
1255        { print!("{:02X} ", c); }
1256    println!();
1257    let mut txt = String::new();
1258    for c in cipher.clone()
1259        { write!(txt, "{:02X} ", c); }
1260    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1261    println!("-------------------------------");
1262}
1263
1264fn des_encrypt_string_with_padding_iso_ecb_into_vec()
1265{
1266    println!("des_encrypt_string_with_padding_iso_ecb_into_vec()");
1267    use std::io::Write;
1268    use std::fmt::Write as _;
1269    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1270
1271    // Normal case
1272    let key = 0x_1234567890ABCDEF_u64;
1273    println!("K =\t{:#016X}", key);
1274    let mut a_des = DES::new_with_key_u64(key);
1275
1276    let message = "In the beginning God created the heavens and the earth.".to_string();
1277    println!("M =\t{}", message);
1278    let mut cipher = Vec::<u8>::new();
1279    a_des.encrypt_string_into_vec(&message, &mut cipher);
1280    print!("C (16 rounds) =\t");
1281    for c in cipher.clone()
1282        { print!("{:02X} ", c); }
1283    println!();
1284    let mut txt = String::new();
1285    for c in cipher.clone()
1286        { write!(txt, "{:02X} ", c); }
1287    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1288    println!();
1289
1290    // Expanded case for 128 rounds
1291    let key = 0x_1234567890ABCDEF_u64;
1292    println!("K =\t{:#016X}", key);
1293    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1294
1295    let message = "In the beginning God created the heavens and the earth.".to_string();
1296    println!("M =\t{}", message);
1297    let mut cipher = Vec::<u8>::new();
1298    a_des.encrypt_string_into_vec(&message, &mut cipher);
1299    print!("C (128 rounds) =\t");
1300    for c in cipher.clone()
1301        { print!("{:02X} ", c); }
1302    println!();
1303    let mut txt = String::new();
1304    for c in cipher.clone()
1305        { write!(txt, "{:02X} ", c); }
1306    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1307    println!();
1308
1309    // Expanded case for 0 rounds which means that key is meaningless
1310    let key1 = 0x_1234567890ABCDEF_u64;
1311    let key2 = 0_u64;
1312    println!("K =\t{:#016X}", key);
1313    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1314    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1315
1316    let message = "In the beginning God created the heavens and the earth.".to_string();
1317    println!("M =\t{}", message);
1318    let mut cipher1 = Vec::<u8>::new();
1319    let mut cipher2 = Vec::<u8>::new();
1320    c_des.encrypt_string_into_vec(&message, &mut cipher1);
1321    d_des.encrypt_string_into_vec(&message, &mut cipher2);
1322    print!("C (0 rounds) =\t");
1323    for c in cipher1.clone()
1324        { print!("{:02X} ", c); }
1325    println!();
1326    let mut txt = String::new();
1327    for c in cipher1.clone()
1328        { write!(txt, "{:02X} ", c); }
1329    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1330    print!("D (0 rounds) =\t");
1331    for c in cipher2.clone()
1332        { print!("{:02X} ", c); }
1333    println!();
1334    let mut txt = String::new();
1335    for c in cipher2.clone()
1336        { write!(txt, "{:02X} ", c); }
1337    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1338    println!();
1339
1340    // Normal case for the message of 0 bytes
1341    let key = 0x_1234567890ABCDEF_u64;
1342    println!("K =\t{:#016X}", key);
1343    let mut a_des = DES::new_with_key_u64(key);
1344
1345    let message = "".to_string();
1346    println!("M =\t{}", message);
1347    let mut cipher = Vec::<u8>::new();
1348    a_des.encrypt_string_into_vec(&message, &mut cipher);
1349    print!("C =\t");
1350    for c in cipher.clone()
1351        { print!("{:02X} ", c); }
1352    println!();
1353    let mut txt = String::new();
1354    for c in cipher.clone()
1355        { write!(txt, "{:02X} ", c); }
1356    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1357    println!();
1358
1359    // Normal case for the message shorter than 8 bytes
1360    let key = 0x_1234567890ABCDEF_u64;
1361    println!("K =\t{:#016X}", key);
1362    let mut a_des = DES::new_with_key_u64(key);
1363
1364    let message = "7 bytes".to_string();
1365    println!("M =\t{}", message);
1366    let mut cipher = Vec::<u8>::new();
1367    a_des.encrypt_string_into_vec(&message, &mut cipher);
1368    print!("C =\t");
1369    for c in cipher.clone()
1370        { print!("{:02X} ", c); }
1371    println!();
1372    let mut txt = String::new();
1373    for c in cipher.clone()
1374        { write!(txt, "{:02X} ", c); }
1375    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1376    println!();
1377
1378    // Normal case for the message of 8 bytes
1379    let key = 0x_1234567890ABCDEF_u64;
1380    println!("K =\t{:#016X}", key);
1381    let mut a_des = DES::new_with_key_u64(key);
1382
1383    let message = "I am OK.".to_string();
1384    println!("M =\t{}", message);
1385    let mut cipher = Vec::<u8>::new();
1386    a_des.encrypt_string_into_vec(&message, &mut cipher);
1387    print!("C =\t");
1388    for c in cipher.clone()
1389        { print!("{:02X} ", c); }
1390    println!();
1391    let mut txt = String::new();
1392    for c in cipher.clone()
1393        { write!(txt, "{:02X} ", c); }
1394    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1395    println!();
1396
1397    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1398    let key = 0x_1234567890ABCDEF_u64;
1399    println!("K =\t{:#016X}", key);
1400    let mut a_des = DES::new_with_key_u64(key);
1401
1402    let message = "PARK Youngho".to_string();
1403    println!("M =\t{}", message);
1404    let mut cipher = Vec::<u8>::new();
1405    a_des.encrypt_string_into_vec(&message, &mut cipher);
1406    print!("C =\t");
1407    for c in cipher.clone()
1408        { print!("{:02X} ", c); }
1409    println!();
1410    let mut txt = String::new();
1411    for c in cipher.clone()
1412        { write!(txt, "{:02X} ", c); }
1413    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1414    println!();
1415
1416
1417    // Normal case for the message of 16 bytes
1418    let key = 0x_1234567890ABCDEF_u64;
1419    println!("K =\t{:#016X}", key);
1420    let mut a_des = DES::new_with_key_u64(key);
1421
1422    let message = "고맙습니다.".to_string();
1423    println!("M =\t{}", message);
1424    let mut cipher = Vec::<u8>::new();
1425    a_des.encrypt_string_into_vec(&message, &mut cipher);
1426    print!("C =\t");
1427    for c in cipher.clone()
1428        { print!("{:02X} ", c); }
1429    println!();
1430    let mut txt = String::new();
1431    for c in cipher.clone()
1432        { write!(txt, "{:02X} ", c); }
1433    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1434    println!("-------------------------------");
1435}
1436
1437fn des_encrypt_string_with_padding_iso_ecb_into_array()
1438{
1439    println!("des_encrypt_string_with_padding_iso_ecb_into_array()");
1440    use std::io::Write;
1441    use std::fmt::Write as _;
1442    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1443
1444    // Normal case
1445    let key = 0x_1234567890ABCDEF_u64;
1446    println!("K =\t{:#016X}", key);
1447    let mut a_des = DES::new_with_key_u64(key);
1448
1449    let message = "In the beginning God created the heavens and the earth.".to_string();
1450    println!("M =\t{}", message);
1451    let mut cipher = [0_u8; 56];
1452    a_des.encrypt_string_into_array(&message, &mut cipher);
1453    print!("C (16 rounds) =\t");
1454    for c in cipher.clone()
1455        { print!("{:02X} ", c); }
1456    println!();
1457    let mut txt = String::new();
1458    for c in cipher.clone()
1459        { write!(txt, "{:02X} ", c); }
1460    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1461    println!();
1462
1463    // Expanded case for 128 rounds
1464    let key = 0x_1234567890ABCDEF_u64;
1465    println!("K =\t{:#016X}", key);
1466    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1467
1468    let message = "In the beginning God created the heavens and the earth.".to_string();
1469    println!("M =\t{}", message);
1470    let mut cipher = [0_u8; 56];
1471    a_des.encrypt_string_into_array(&message, &mut cipher);
1472    print!("C (128 rounds) =\t");
1473    for c in cipher.clone()
1474        { print!("{:02X} ", c); }
1475    println!();
1476    let mut txt = String::new();
1477    for c in cipher.clone()
1478        { write!(txt, "{:02X} ", c); }
1479    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1480    println!();
1481
1482    // Expanded case for 0 rounds which means that key is meaningless
1483    let key1 = 0x_1234567890ABCDEF_u64;
1484    let key2 = 0_u64;
1485    println!("K =\t{:#016X}", key);
1486    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1487    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1488
1489    let message = "In the beginning God created the heavens and the earth.".to_string();
1490    println!("M =\t{}", message);
1491    let mut cipher1 = [0_u8; 56];
1492    let mut cipher2 = [0_u8; 56];
1493    c_des.encrypt_string_into_array(&message, &mut cipher1);
1494    d_des.encrypt_string_into_array(&message, &mut cipher2);
1495    print!("C (0 rounds) =\t");
1496    for c in cipher1.clone()
1497        { print!("{:02X} ", c); }
1498    println!();
1499    let mut txt = String::new();
1500    for c in cipher1.clone()
1501        { write!(txt, "{:02X} ", c); }
1502    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1503    print!("D (0 rounds) =\t");
1504    for c in cipher2.clone()
1505        { print!("{:02X} ", c); }
1506    println!();
1507    let mut txt = String::new();
1508    for c in cipher2.clone()
1509        { write!(txt, "{:02X} ", c); }
1510    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1511    println!();
1512
1513    // Normal case for the message of 0 bytes
1514    let key = 0x_1234567890ABCDEF_u64;
1515    println!("K =\t{:#016X}", key);
1516    let mut a_des = DES::new_with_key_u64(key);
1517
1518    let message = "".to_string();
1519    println!("M =\t{}", message);
1520    let mut cipher = [0_u8; 8];
1521    a_des.encrypt_string_into_array(&message, &mut cipher);
1522    print!("C =\t");
1523    for c in cipher.clone()
1524        { print!("{:02X} ", c); }
1525    println!();
1526    let mut txt = String::new();
1527    for c in cipher.clone()
1528        { write!(txt, "{:02X} ", c); }
1529    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1530    println!();
1531
1532    // Normal case for the message shorter than 8 bytes
1533    let key = 0x_1234567890ABCDEF_u64;
1534    println!("K =\t{:#016X}", key);
1535    let mut a_des = DES::new_with_key_u64(key);
1536
1537    let message = "7 bytes".to_string();
1538    println!("M =\t{}", message);
1539    let mut cipher = [0_u8; 8];
1540    a_des.encrypt_string_into_array(&message, &mut cipher);
1541    print!("C =\t");
1542    for c in cipher.clone()
1543        { print!("{:02X} ", c); }
1544    println!();
1545    let mut txt = String::new();
1546    for c in cipher.clone()
1547        { write!(txt, "{:02X} ", c); }
1548    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1549    println!();
1550
1551    // Normal case for the message of 8 bytes
1552    let key = 0x_1234567890ABCDEF_u64;
1553    println!("K =\t{:#016X}", key);
1554    let mut a_des = DES::new_with_key_u64(key);
1555
1556    let message = "I am OK.".to_string();
1557    println!("M =\t{}", message);
1558    let mut cipher = [0_u8; 16];
1559    a_des.encrypt_string_into_array(&message, &mut cipher);
1560    print!("C =\t");
1561    for c in cipher.clone()
1562        { print!("{:02X} ", c); }
1563    println!();
1564    let mut txt = String::new();
1565    for c in cipher.clone()
1566        { write!(txt, "{:02X} ", c); }
1567    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1568    println!();
1569
1570    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1571    let key = 0x_1234567890ABCDEF_u64;
1572    println!("K =\t{:#016X}", key);
1573    let mut a_des = DES::new_with_key_u64(key);
1574
1575    let message = "PARK Youngho".to_string();
1576    println!("M =\t{}", message);
1577    let mut cipher = [0_u8; 16];
1578    a_des.encrypt_string_into_array(&message, &mut cipher);
1579    print!("C =\t");
1580    for c in cipher.clone()
1581        { print!("{:02X} ", c); }
1582    println!();
1583    let mut txt = String::new();
1584    for c in cipher.clone()
1585        { write!(txt, "{:02X} ", c); }
1586    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1587    println!();
1588
1589    // Normal case for the message of 16 bytes
1590    let key = 0x_1234567890ABCDEF_u64;
1591    println!("K =\t{:#016X}", key);
1592    let mut a_des = DES::new_with_key_u64(key);
1593
1594    let message = "고맙습니다.".to_string();
1595    println!("M =\t{}", message);
1596    let mut cipher = [0_u8; 24];
1597    a_des.encrypt_string_into_array(&message, &mut cipher);
1598    print!("C =\t");
1599    for c in cipher.clone()
1600        { print!("{:02X} ", c); }
1601    println!();
1602    let mut txt = String::new();
1603    for c in cipher.clone()
1604        { write!(txt, "{:02X} ", c); }
1605    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1606    println!("-------------------------------");
1607}
1608
1609fn des_encrypt_vec_with_padding_iso_ecb()
1610{
1611    println!("des_encrypt_vec_with_padding_iso_ecb()");
1612    use std::io::Write;
1613    use std::fmt::Write as _;
1614    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1615
1616    // Normal case
1617    let key = 0x_1234567890ABCDEF_u64;
1618    println!("K =\t{:#016X}", key);
1619    let mut a_des = DES::new_with_key_u64(key);
1620
1621    let message = "In the beginning God created the heavens and the earth.";
1622    println!("M =\t{}", message);
1623    let message = unsafe { message.to_string().as_mut_vec().clone() };
1624    let mut cipher = [0_u8; 56];
1625    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1626    print!("C (16 rounds) =\t");
1627    for c in cipher.clone()
1628        { print!("{:02X} ", c); }
1629    println!();
1630    let mut txt = String::new();
1631    for c in cipher.clone()
1632        { write!(txt, "{:02X} ", c); }
1633    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1634    println!();
1635
1636    // Expanded case for 128 rounds
1637    let key = 0x_1234567890ABCDEF_u64;
1638    println!("K =\t{:#016X}", key);
1639    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1640
1641    let message = "In the beginning God created the heavens and the earth.";
1642    println!("M =\t{}", message);
1643    let message = unsafe { message.to_string().as_mut_vec().clone() };
1644    let mut cipher = [0_u8; 56];
1645    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1646    print!("C (128 rounds) =\t");
1647    for c in cipher.clone()
1648        { print!("{:02X} ", c); }
1649    println!();
1650    let mut txt = String::new();
1651    for c in cipher.clone()
1652        { write!(txt, "{:02X} ", c); }
1653    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1654    println!();
1655
1656    // Expanded case for 0 rounds which means that key is meaningless
1657    let key1 = 0x_1234567890ABCDEF_u64;
1658    let key2 = 0_u64;
1659    println!("K1 =\t{:#016X}", key1);
1660    println!("K2 =\t{:#016X}", key2);
1661    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1662    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1663
1664    let message = "In the beginning God created the heavens and the earth.";
1665    println!("M =\t{}", message);
1666    let message = unsafe { message.to_string().as_mut_vec().clone() };
1667    let mut cipher1 = [0_u8; 56];
1668    let mut cipher2 = [0_u8; 56];
1669    c_des.encrypt_vec(&message, cipher1.as_mut_ptr());
1670    d_des.encrypt_vec(&message, cipher2.as_mut_ptr());
1671    print!("C (0 rounds) =\t");
1672    for c in cipher1.clone()
1673        { print!("{:02X} ", c); }
1674    println!();
1675    let mut txt = String::new();
1676    for c in cipher1.clone()
1677        { write!(txt, "{:02X} ", c); }
1678    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1679    print!("D (0 rounds) =\t");
1680    for c in cipher2.clone()
1681        { print!("{:02X} ", c); }
1682    println!();
1683    let mut txt = String::new();
1684    for c in cipher2.clone()
1685        { write!(txt, "{:02X} ", c); }
1686    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1687    println!();
1688
1689    // Normal case for the message of 0 bytes
1690    let key = 0x_1234567890ABCDEF_u64;
1691    println!("K =\t{:#016X}", key);
1692    let mut a_des = DES::new_with_key_u64(key);
1693
1694    let message = "";
1695    println!("M =\t{}", message);
1696    let message = unsafe { message.to_string().as_mut_vec().clone() };
1697    let mut cipher = [0_u8; 8];
1698    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1699    print!("C =\t");
1700    for c in cipher.clone()
1701        { print!("{:02X} ", c); }
1702    println!();
1703    let mut txt = String::new();
1704    for c in cipher.clone()
1705        { write!(txt, "{:02X} ", c); }
1706    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1707    println!();
1708
1709    // Normal case for the message shorter than 8 bytes
1710    let key = 0x_1234567890ABCDEF_u64;
1711    println!("K =\t{:#016X}", key);
1712    let mut a_des = DES::new_with_key_u64(key);
1713
1714    let message = "7 bytes";
1715    println!("M =\t{}", message);
1716    let message = unsafe { message.to_string().as_mut_vec().clone() };
1717    let mut cipher = [0_u8; 8];
1718    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1719    print!("C =\t");
1720    for c in cipher.clone()
1721        { print!("{:02X} ", c); }
1722    println!();
1723    let mut txt = String::new();
1724    for c in cipher.clone()
1725        { write!(txt, "{:02X} ", c); }
1726    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1727    println!();
1728
1729    // Normal case for the message of 8 bytes
1730    let key = 0x_1234567890ABCDEF_u64;
1731    println!("K =\t{:#016X}", key);
1732    let mut a_des = DES::new_with_key_u64(key);
1733
1734    let message = "I am OK.";
1735    println!("M =\t{}", message);
1736    let message = unsafe { message.to_string().as_mut_vec().clone() };
1737    let mut cipher = [0_u8; 16];
1738    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1739    print!("C =\t");
1740    for c in cipher.clone()
1741        { print!("{:02X} ", c); }
1742    println!();
1743    let mut txt = String::new();
1744    for c in cipher.clone()
1745        { write!(txt, "{:02X} ", c); }
1746    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1747    println!();
1748
1749    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1750    let key = 0x_1234567890ABCDEF_u64;
1751    println!("K =\t{:#016X}", key);
1752    let mut a_des = DES::new_with_key_u64(key);
1753
1754    let message = "PARK Youngho";
1755    println!("M =\t{}", message);
1756    let message = unsafe { message.to_string().as_mut_vec().clone() };
1757    let mut cipher = [0_u8; 16];
1758    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1759    print!("C =\t");
1760    for c in cipher.clone()
1761        { print!("{:02X} ", c); }
1762    println!();
1763    let mut txt = String::new();
1764    for c in cipher.clone()
1765        { write!(txt, "{:02X} ", c); }
1766    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1767    println!();
1768
1769
1770    // Normal case for the message of 16 bytes
1771    let key = 0x_1234567890ABCDEF_u64;
1772    println!("K =\t{:#016X}", key);
1773    let mut a_des = DES::new_with_key_u64(key);
1774
1775    let message = "고맙습니다.";
1776    println!("M =\t{}", message);
1777    let message = unsafe { message.to_string().as_mut_vec().clone() };
1778    let mut cipher = [0_u8; 24];
1779    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1780    print!("C =\t");
1781    for c in cipher.clone()
1782        { print!("{:02X} ", c); }
1783    println!();
1784    let mut txt = String::new();
1785    for c in cipher.clone()
1786        { write!(txt, "{:02X} ", c); }
1787    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1788    println!("-------------------------------");
1789}
1790
1791fn des_encrypt_vec_with_padding_iso_ecb_into_vec()
1792{
1793    println!("des_encrypt_vec_with_padding_iso_ecb_into_vec()");
1794    use std::io::Write;
1795    use std::fmt::Write as _;
1796    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1797
1798    // Normal case
1799    let key = 0x_1234567890ABCDEF_u64;
1800    println!("K =\t{:#016X}", key);
1801    let mut a_des = DES::new_with_key_u64(key);
1802
1803    let message = "In the beginning God created the heavens and the earth.";
1804    println!("M =\t{}", message);
1805    let message = unsafe { message.to_string().as_mut_vec().clone() };
1806    let mut cipher = Vec::<u8>::new();
1807    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1808    print!("C (16 rounds) =\t");
1809    for c in cipher.clone()
1810        { print!("{:02X} ", c); }
1811    println!();
1812    let mut txt = String::new();
1813    for c in cipher.clone()
1814        { write!(txt, "{:02X} ", c); }
1815    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1816    println!();
1817
1818    // Expanded case for 128 rounds
1819    let key = 0x_1234567890ABCDEF_u64;
1820    println!("K =\t{:#016X}", key);
1821    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1822
1823    let message = "In the beginning God created the heavens and the earth.";
1824    println!("M =\t{}", message);
1825    let message = unsafe { message.to_string().as_mut_vec().clone() };
1826    let mut cipher = Vec::<u8>::new();
1827    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1828    print!("C (128 rounds) =\t");
1829    for c in cipher.clone()
1830        { print!("{:02X} ", c); }
1831    println!();
1832    let mut txt = String::new();
1833    for c in cipher.clone()
1834        { write!(txt, "{:02X} ", c); }
1835    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1836    println!();
1837
1838    // Expanded case for 0 rounds which means that key is meaningless
1839    let key1 = 0x_1234567890ABCDEF_u64;
1840    let key2 = 0_u64;
1841    println!("K1 =\t{:#016X}", key1);
1842    println!("K2 =\t{:#016X}", key2);
1843    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1844    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1845
1846    let message = "In the beginning God created the heavens and the earth.";
1847    println!("M =\t{}", message);
1848    let message = unsafe { message.to_string().as_mut_vec().clone() };
1849
1850    let mut cipher1 = Vec::<u8>::new();
1851    let mut cipher2 = Vec::<u8>::new();
1852    c_des.encrypt_vec_into_vec(&message, &mut cipher1);
1853    d_des.encrypt_vec_into_vec(&message, &mut cipher2);
1854    print!("C (0 rounds) =\t");
1855    for c in cipher1.clone()
1856        { print!("{:02X} ", c); }
1857    println!();
1858    let mut txt = String::new();
1859    for c in cipher1.clone()
1860        { write!(txt, "{:02X} ", c); }
1861    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1862    print!("D (0 rounds) =\t");
1863    for c in cipher2.clone()
1864        { print!("{:02X} ", c); }
1865    println!();
1866    let mut txt = String::new();
1867    for c in cipher2.clone()
1868        { write!(txt, "{:02X} ", c); }
1869    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1870    println!();
1871
1872    // Normal case for the message of 0 bytes
1873    let key = 0x_1234567890ABCDEF_u64;
1874    println!("K =\t{:#016X}", key);
1875    let mut a_des = DES::new_with_key_u64(key);
1876
1877    let message = "";
1878    println!("M =\t{}", message);
1879    let message = unsafe { message.to_string().as_mut_vec().clone() };
1880    let mut cipher = Vec::<u8>::new();
1881    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1882    print!("C =\t");
1883    for c in cipher.clone()
1884        { print!("{:02X} ", c); }
1885    println!();
1886    let mut txt = String::new();
1887    for c in cipher.clone()
1888        { write!(txt, "{:02X} ", c); }
1889    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1890    println!();
1891
1892    // Normal case for the message shorter than 8 bytes
1893    let key = 0x_1234567890ABCDEF_u64;
1894    println!("K =\t{:#016X}", key);
1895    let mut a_des = DES::new_with_key_u64(key);
1896
1897    let message = "7 bytes";
1898    println!("M =\t{}", message);
1899    let message = unsafe { message.to_string().as_mut_vec().clone() };
1900    let mut cipher = Vec::<u8>::new();
1901    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1902    print!("C =\t");
1903    for c in cipher.clone()
1904        { print!("{:02X} ", c); }
1905    println!();
1906    let mut txt = String::new();
1907    for c in cipher.clone()
1908        { write!(txt, "{:02X} ", c); }
1909    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1910    println!();
1911
1912    // Normal case for the message of 8 bytes
1913    let key = 0x_1234567890ABCDEF_u64;
1914    println!("K =\t{:#016X}", key);
1915    let mut a_des = DES::new_with_key_u64(key);
1916
1917    let message = "I am OK.";
1918    println!("M =\t{}", message);
1919    let message = unsafe { message.to_string().as_mut_vec().clone() };
1920    let mut cipher = Vec::<u8>::new();
1921    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1922    print!("C =\t");
1923    for c in cipher.clone()
1924        { print!("{:02X} ", c); }
1925    println!();
1926    let mut txt = String::new();
1927    for c in cipher.clone()
1928        { write!(txt, "{:02X} ", c); }
1929    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1930    println!();
1931
1932    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1933    let key = 0x_1234567890ABCDEF_u64;
1934    println!("K =\t{:#016X}", key);
1935    let mut a_des = DES::new_with_key_u64(key);
1936
1937    let message = "PARK Youngho";
1938    println!("M =\t{}", message);
1939    let message = unsafe { message.to_string().as_mut_vec().clone() };
1940    let mut cipher = Vec::<u8>::new();
1941    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1942    print!("C =\t");
1943    for c in cipher.clone()
1944        { print!("{:02X} ", c); }
1945    println!();
1946    let mut txt = String::new();
1947    for c in cipher.clone()
1948        { write!(txt, "{:02X} ", c); }
1949    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1950    println!();
1951
1952
1953    // Normal case for the message of 16 bytes
1954    let key = 0x_1234567890ABCDEF_u64;
1955    println!("K =\t{:#016X}", key);
1956    let mut a_des = DES::new_with_key_u64(key);
1957
1958    let message = "고맙습니다.";
1959    println!("M =\t{}", message);
1960    let message = unsafe { message.to_string().as_mut_vec().clone() };
1961    let mut cipher = Vec::<u8>::new();
1962    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1963    print!("C =\t");
1964    for c in cipher.clone()
1965        { print!("{:02X} ", c); }
1966    println!();
1967    let mut txt = String::new();
1968    for c in cipher.clone()
1969        { write!(txt, "{:02X} ", c); }
1970    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1971    println!("-------------------------------");
1972}
1973
1974fn des_encrypt_vec_with_padding_iso_ecb_into_array()
1975{
1976    println!("des_encrypt_vec_with_padding_iso_ecb_into_array()");
1977    use std::io::Write;
1978    use std::fmt::Write as _;
1979    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1980
1981    // Normal case
1982    let key = 0x_1234567890ABCDEF_u64;
1983    println!("K =\t{:#016X}", key);
1984    let mut a_des = DES::new_with_key_u64(key);
1985
1986    let message = "In the beginning God created the heavens and the earth.";
1987    println!("M =\t{}", message);
1988    let message = unsafe { message.to_string().as_mut_vec().clone() };
1989    let mut cipher = [0_u8; 56];
1990    a_des.encrypt_vec_into_array(&message, &mut cipher);
1991    print!("C (16 rounds) =\t");
1992    for c in cipher.clone()
1993        { print!("{:02X} ", c); }
1994    println!();
1995    let mut txt = String::new();
1996    for c in cipher.clone()
1997        { write!(txt, "{:02X} ", c); }
1998    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1999    println!();
2000
2001    // Expanded case for 128 rounds
2002    let key = 0x_1234567890ABCDEF_u64;
2003    println!("K =\t{:#016X}", key);
2004    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2005
2006    let message = "In the beginning God created the heavens and the earth.";
2007    println!("M =\t{}", message);
2008    let message = unsafe { message.to_string().as_mut_vec().clone() };
2009    let mut cipher = [0_u8; 56];
2010    a_des.encrypt_vec_into_array(&message, &mut cipher);
2011    print!("C (128 rounds) =\t");
2012    for c in cipher.clone()
2013        { print!("{:02X} ", c); }
2014    println!();
2015    let mut txt = String::new();
2016    for c in cipher.clone()
2017        { write!(txt, "{:02X} ", c); }
2018    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2019    println!();
2020
2021    // Expanded case for 0 rounds which means that key is meaningless
2022    let key1 = 0x_1234567890ABCDEF_u64;
2023    let key2 = 0_u64;
2024    println!("K1 =\t{:#016X}", key1);
2025    println!("K2 =\t{:#016X}", key2);
2026    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2027    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2028
2029    let message = "In the beginning God created the heavens and the earth.";
2030    println!("M =\t{}", message);
2031    let message = unsafe { message.to_string().as_mut_vec().clone() };
2032    let mut cipher1 = [0_u8; 56];
2033    let mut cipher2 = [0_u8; 56];
2034    c_des.encrypt_vec_into_array(&message, &mut cipher1);
2035    d_des.encrypt_vec_into_array(&message, &mut cipher2);
2036    print!("C (0 rounds) =\t");
2037    for c in cipher1.clone()
2038        { print!("{:02X} ", c); }
2039    println!();
2040    let mut txt = String::new();
2041    for c in cipher1.clone()
2042        { write!(txt, "{:02X} ", c); }
2043    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2044    print!("D (0 rounds) =\t");
2045    for c in cipher2.clone()
2046        { print!("{:02X} ", c); }
2047    println!();
2048    let mut txt = String::new();
2049    for c in cipher2.clone()
2050        { write!(txt, "{:02X} ", c); }
2051    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2052    println!();
2053
2054    // Normal case for the message of 0 bytes
2055    let key = 0x_1234567890ABCDEF_u64;
2056    println!("K =\t{:#016X}", key);
2057    let mut a_des = DES::new_with_key_u64(key);
2058
2059    let message = "";
2060    println!("M =\t{}", message);
2061    let message = unsafe { message.to_string().as_mut_vec().clone() };
2062    let mut cipher = [0_u8; 8];
2063    a_des.encrypt_vec_into_array(&message, &mut cipher);
2064    print!("C =\t");
2065    for c in cipher.clone()
2066        { print!("{:02X} ", c); }
2067    println!();
2068    let mut txt = String::new();
2069    for c in cipher.clone()
2070        { write!(txt, "{:02X} ", c); }
2071    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2072    println!();
2073
2074    // Normal case for the message shorter than 8 bytes
2075    let key = 0x_1234567890ABCDEF_u64;
2076    println!("K =\t{:#016X}", key);
2077    let mut a_des = DES::new_with_key_u64(key);
2078
2079    let message = "7 bytes";
2080    println!("M =\t{}", message);
2081    let message = unsafe { message.to_string().as_mut_vec().clone() };
2082    let mut cipher = [0_u8; 8];
2083    a_des.encrypt_vec_into_array(&message, &mut cipher);
2084    print!("C =\t");
2085    for c in cipher.clone()
2086        { print!("{:02X} ", c); }
2087    println!();
2088    let mut txt = String::new();
2089    for c in cipher.clone()
2090        { write!(txt, "{:02X} ", c); }
2091    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2092    println!();
2093
2094    // Normal case for the message of 8 bytes
2095    let key = 0x_1234567890ABCDEF_u64;
2096    println!("K =\t{:#016X}", key);
2097    let mut a_des = DES::new_with_key_u64(key);
2098
2099    let message = "I am OK.";
2100    println!("M =\t{}", message);
2101    let message = unsafe { message.to_string().as_mut_vec().clone() };
2102    let mut cipher = [0_u8; 16];
2103    a_des.encrypt_vec_into_array(&message, &mut cipher);
2104    print!("C =\t");
2105    for c in cipher.clone()
2106        { print!("{:02X} ", c); }
2107    println!();
2108    let mut txt = String::new();
2109    for c in cipher.clone()
2110        { write!(txt, "{:02X} ", c); }
2111    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2112    println!();
2113
2114    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2115    let key = 0x_1234567890ABCDEF_u64;
2116    println!("K =\t{:#016X}", key);
2117    let mut a_des = DES::new_with_key_u64(key);
2118
2119    let message = "PARK Youngho";
2120    println!("M =\t{}", message);
2121    let message = unsafe { message.to_string().as_mut_vec().clone() };
2122    let mut cipher = [0_u8; 16];
2123    a_des.encrypt_vec_into_array(&message, &mut cipher);
2124    print!("C =\t");
2125    for c in cipher.clone()
2126        { print!("{:02X} ", c); }
2127    println!();
2128    let mut txt = String::new();
2129    for c in cipher.clone()
2130        { write!(txt, "{:02X} ", c); }
2131    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2132    println!();
2133
2134
2135    // Normal case for the message of 16 bytes
2136    let key = 0x_1234567890ABCDEF_u64;
2137    println!("K =\t{:#016X}", key);
2138    let mut a_des = DES::new_with_key_u64(key);
2139 
2140    let message = "고맙습니다.";
2141    println!("M =\t{}", message);
2142    let message = unsafe { message.to_string().as_mut_vec().clone() };
2143    let mut cipher = [0_u8; 24];
2144    a_des.encrypt_vec_into_array(&message, &mut cipher);
2145    print!("C =\t");
2146    for c in cipher.clone()
2147        { print!("{:02X} ", c); }
2148    println!();
2149    let mut txt = String::new();
2150    for c in cipher.clone()
2151        { write!(txt, "{:02X} ", c); }
2152    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2153    println!("-------------------------------");
2154}
2155
2156fn des_encrypt_array_with_padding_iso_ecb()
2157{
2158    println!("des_encrypt_array_with_padding_iso_ecb()");
2159    use std::io::Write;
2160    use std::fmt::Write as _;
2161    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2162
2163    // Normal case
2164    let key = 0x_1234567890ABCDEF_u64;
2165    println!("K =\t{:#016X}", key);
2166    let mut a_des = DES::new_with_key_u64(key);
2167
2168    let mes = "In the beginning God created the heavens and the earth.";
2169    println!("M =\t{}", mes);
2170    let mut message = [0_u8; 55];
2171    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2172    let mut cipher = [0_u8; 56];
2173    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2174    print!("C (16 rounds) =\t");
2175    for c in cipher.clone()
2176        { print!("{:02X} ", c); }
2177    println!();
2178    let mut txt = String::new();
2179    for c in cipher.clone()
2180        { write!(txt, "{:02X} ", c); }
2181    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2182    println!();
2183
2184    // Expanded case for 128 rounds
2185    let key = 0x_1234567890ABCDEF_u64;
2186    println!("K =\t{:#016X}", key);
2187    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2188
2189    let mes = "In the beginning God created the heavens and the earth.";
2190    println!("M =\t{}", mes);
2191    let mut message = [0_u8; 55];
2192    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2193    let mut cipher = [0_u8; 56];
2194    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2195    print!("C (128 rounds) =\t");
2196    for c in cipher.clone()
2197        { print!("{:02X} ", c); }
2198    println!();
2199    let mut txt = String::new();
2200    for c in cipher.clone()
2201        { write!(txt, "{:02X} ", c); }
2202    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2203    println!();
2204
2205    // Expanded case for 0 rounds which means that key is meaningless
2206    let key1 = 0x_1234567890ABCDEF_u64;
2207    let key2 = 0_u64;
2208    println!("K1 =\t{:#016X}", key1);
2209    println!("K2 =\t{:#016X}", key2);
2210    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2211    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2212
2213    let mes = "In the beginning God created the heavens and the earth.";
2214    println!("M =\t{}", mes);
2215    let mut message = [0_u8; 55];
2216    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2217    let mut cipher1 = [0_u8; 56];
2218    let mut cipher2 = [0_u8; 56];
2219    c_des.encrypt_array(&message, cipher1.as_mut_ptr());
2220    d_des.encrypt_array(&message, cipher2.as_mut_ptr());
2221    print!("C (0 rounds) =\t");
2222    for c in cipher1.clone()
2223        { print!("{:02X} ", c); }
2224    println!();
2225    let mut txt = String::new();
2226    for c in cipher1.clone()
2227        { write!(txt, "{:02X} ", c); }
2228    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2229    print!("D (0 rounds) =\t");
2230    for c in cipher2.clone()
2231        { print!("{:02X} ", c); }
2232    println!();
2233    let mut txt = String::new();
2234    for c in cipher2.clone()
2235        { write!(txt, "{:02X} ", c); }
2236    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2237    println!();
2238
2239    // Normal case for the message of 0 bytes
2240    let key = 0x_1234567890ABCDEF_u64;
2241    println!("K =\t{:#016X}", key);
2242    let mut a_des = DES::new_with_key_u64(key);
2243
2244    let mes = "";
2245    println!("M =\t{}", mes);
2246    let mut message = [0_u8; 0];
2247    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2248    let mut cipher = [0_u8; 8];
2249    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2250    print!("C =\t");
2251    for c in cipher.clone()
2252        { print!("{:02X} ", c); }
2253    println!();
2254    let mut txt = String::new();
2255    for c in cipher.clone()
2256        { write!(txt, "{:02X} ", c); }
2257    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2258    println!();
2259
2260    // Normal case for the message shorter than 8 bytes
2261    let key = 0x_1234567890ABCDEF_u64;
2262    println!("K =\t{:#016X}", key);
2263    let mut a_des = DES::new_with_key_u64(key);
2264
2265    let mes = "7 bytes";
2266    println!("M =\t{}", mes);
2267    let mut message = [0_u8; 7];
2268    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2269    let mut cipher = [0_u8; 8];
2270    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2271    print!("C =\t");
2272    for c in cipher.clone()
2273        { print!("{:02X} ", c); }
2274    println!();
2275    let mut txt = String::new();
2276    for c in cipher.clone()
2277        { write!(txt, "{:02X} ", c); }
2278    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2279    println!();
2280
2281    // Normal case for the message of 8 bytes
2282    let key = 0x_1234567890ABCDEF_u64;
2283    println!("K =\t{:#016X}", key);
2284    let mut a_des = DES::new_with_key_u64(key);
2285
2286    let mes = "I am OK.";
2287    println!("M =\t{}", mes);
2288    let mut message = [0_u8; 8];
2289    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2290    let mut cipher = [0_u8; 16];
2291    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2292    print!("C =\t");
2293    for c in cipher.clone()
2294        { print!("{:02X} ", c); }
2295    println!();
2296    let mut txt = String::new();
2297    for c in cipher.clone()
2298        { write!(txt, "{:02X} ", c); }
2299    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2300    println!();
2301
2302    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2303    let key = 0x_1234567890ABCDEF_u64;
2304    println!("K =\t{:#016X}", key);
2305    let mut a_des = DES::new_with_key_u64(key);
2306
2307    let mes = "PARK Youngho";
2308    println!("M =\t{}", mes);
2309    let mut message = [0_u8; 12];
2310    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2311    let mut cipher = [0_u8; 16];
2312    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2313    print!("C =\t");
2314    for c in cipher.clone()
2315        { print!("{:02X} ", c); }
2316    println!();
2317    let mut txt = String::new();
2318    for c in cipher.clone()
2319        { write!(txt, "{:02X} ", c); }
2320    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2321    println!();
2322
2323
2324    // Normal case for the message of 16 bytes
2325    let key = 0x_1234567890ABCDEF_u64;
2326    println!("K =\t{:#016X}", key);
2327    let mut a_des = DES::new_with_key_u64(key);
2328
2329    let mes = "고맙습니다.";
2330    println!("M =\t{}", mes);
2331    let mut message = [0_u8; 16];
2332    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2333    let mut cipher = [0_u8; 24];
2334    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2335    print!("C =\t");
2336    for c in cipher.clone()
2337        { print!("{:02X} ", c); }
2338    println!();
2339    let mut txt = String::new();
2340    for c in cipher.clone()
2341        { write!(txt, "{:02X} ", c); }
2342    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2343    println!("-------------------------------");
2344}
2345
2346fn des_encrypt_array_with_padding_iso_ecb_into_vec()
2347{
2348    println!("des_encrypt_array_with_padding_iso_ecb_into_vec()");
2349    use std::io::Write;
2350    use std::fmt::Write as _;
2351    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2352
2353    // Normal case
2354    let key = 0x_1234567890ABCDEF_u64;
2355    println!("K =\t{:#016X}", key);
2356    let mut a_des = DES::new_with_key_u64(key);
2357
2358    let mes = "In the beginning God created the heavens and the earth.";
2359    println!("M =\t{}", mes);
2360    let mut message = [0_u8; 55];
2361    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2362    let mut cipher = Vec::<u8>::new();
2363    a_des.encrypt_array_into_vec(&message, &mut cipher);
2364    print!("C (16 rounds) =\t");
2365    for c in cipher.clone()
2366        { print!("{:02X} ", c); }
2367    println!();
2368    let mut txt = String::new();
2369    for c in cipher.clone()
2370        { write!(txt, "{:02X} ", c); }
2371    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2372    println!();
2373
2374    // Expanded case for 128 rounds
2375    let key = 0x_1234567890ABCDEF_u64;
2376    println!("K =\t{:#016X}", key);
2377    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2378
2379    let mes = "In the beginning God created the heavens and the earth.";
2380    println!("M =\t{}", mes);
2381    let mut message = [0_u8; 55];
2382    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2383    let mut cipher = Vec::<u8>::new();
2384    a_des.encrypt_array_into_vec(&message, &mut cipher);
2385    print!("C (128 rounds) =\t");
2386    for c in cipher.clone()
2387        { print!("{:02X} ", c); }
2388    println!();
2389    let mut txt = String::new();
2390    for c in cipher.clone()
2391        { write!(txt, "{:02X} ", c); }
2392    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2393    println!();
2394
2395    // Expanded case for 0 rounds which means that key is meaningless
2396    let key1 = 0x_1234567890ABCDEF_u64;
2397    let key2 = 0_u64;
2398    println!("K1 =\t{:#016X}", key1);
2399    println!("K2 =\t{:#016X}", key2);
2400    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2401    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2402
2403    let mes = "In the beginning God created the heavens and the earth.";
2404    println!("M =\t{}", mes);
2405    let mut message = [0_u8; 55];
2406    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2407
2408    let mut cipher1 = Vec::<u8>::new();
2409    let mut cipher2 = Vec::<u8>::new();
2410    c_des.encrypt_array_into_vec(&message, &mut cipher1);
2411    d_des.encrypt_array_into_vec(&message, &mut cipher2);
2412    print!("C (0 rounds) =\t");
2413    for c in cipher1.clone()
2414        { print!("{:02X} ", c); }
2415    println!();
2416    let mut txt = String::new();
2417    for c in cipher1.clone()
2418        { write!(txt, "{:02X} ", c); }
2419    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2420    print!("D (0 rounds) =\t");
2421    for c in cipher2.clone()
2422        { print!("{:02X} ", c); }
2423    println!();
2424    let mut txt = String::new();
2425    for c in cipher2.clone()
2426        { write!(txt, "{:02X} ", c); }
2427    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2428    println!();
2429
2430    // Normal case for the message of 0 bytes
2431    let key = 0x_1234567890ABCDEF_u64;
2432    println!("K =\t{:#016X}", key);
2433    let mut a_des = DES::new_with_key_u64(key);
2434
2435    let mes = "";
2436    println!("M =\t{}", mes);
2437    let mut message = [0_u8; 0];
2438    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2439    let mut cipher = Vec::<u8>::new();
2440    a_des.encrypt_array_into_vec(&message, &mut cipher);
2441    print!("C =\t");
2442    for c in cipher.clone()
2443        { print!("{:02X} ", c); }
2444    println!();
2445    let mut txt = String::new();
2446    for c in cipher.clone()
2447        { write!(txt, "{:02X} ", c); }
2448    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2449    println!();
2450
2451    // Normal case for the message shorter than 8 bytes
2452    let key = 0x_1234567890ABCDEF_u64;
2453    println!("K =\t{:#016X}", key);
2454    let mut a_des = DES::new_with_key_u64(key);
2455
2456    let mes = "7 bytes";
2457    println!("M =\t{}", mes);
2458    let mut message = [0_u8; 7];
2459    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460    let mut cipher = Vec::<u8>::new();
2461    a_des.encrypt_array_into_vec(&message, &mut cipher);
2462    print!("C =\t");
2463    for c in cipher.clone()
2464        { print!("{:02X} ", c); }
2465    println!();
2466    let mut txt = String::new();
2467    for c in cipher.clone()
2468        { write!(txt, "{:02X} ", c); }
2469    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2470    println!();
2471
2472    // Normal case for the message of 8 bytes
2473    let key = 0x_1234567890ABCDEF_u64;
2474    println!("K =\t{:#016X}", key);
2475    let mut a_des = DES::new_with_key_u64(key);
2476
2477    let mes = "I am OK.";
2478    println!("M =\t{}", mes);
2479    let mut message = [0_u8; 8];
2480    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2481    let mut cipher = Vec::<u8>::new();
2482    a_des.encrypt_array_into_vec(&message, &mut cipher);
2483    print!("C =\t");
2484    for c in cipher.clone()
2485        { print!("{:02X} ", c); }
2486    println!();
2487    let mut txt = String::new();
2488    for c in cipher.clone()
2489        { write!(txt, "{:02X} ", c); }
2490    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2491    println!();
2492
2493    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2494    let key = 0x_1234567890ABCDEF_u64;
2495    println!("K =\t{:#016X}", key);
2496    let mut a_des = DES::new_with_key_u64(key);
2497
2498    let mes = "PARK Youngho";
2499    println!("M =\t{}", mes);
2500    let mut message = [0_u8; 12];
2501    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2502    let mut cipher = Vec::<u8>::new();
2503    a_des.encrypt_array_into_vec(&message, &mut cipher);
2504    print!("C =\t");
2505    for c in cipher.clone()
2506        { print!("{:02X} ", c); }
2507    println!();
2508    let mut txt = String::new();
2509    for c in cipher.clone()
2510        { write!(txt, "{:02X} ", c); }
2511    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2512    println!();
2513
2514
2515    // Normal case for the message of 16 bytes
2516    let key = 0x_1234567890ABCDEF_u64;
2517    println!("K =\t{:#016X}", key);
2518    let mut a_des = DES::new_with_key_u64(key);
2519
2520    let mes = "고맙습니다.";
2521    println!("M =\t{}", mes);
2522    let mut message = [0_u8; 16];
2523    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2524    let mut cipher = Vec::<u8>::new();
2525    a_des.encrypt_array_into_vec(&message, &mut cipher);
2526    print!("C =\t");
2527    for c in cipher.clone()
2528        { print!("{:02X} ", c); }
2529    println!();
2530    let mut txt = String::new();
2531    for c in cipher.clone()
2532        { write!(txt, "{:02X} ", c); }
2533    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2534    println!("-------------------------------");
2535}
2536
2537fn des_encrypt_array_with_padding_iso_ecb_into_array()
2538{
2539    println!("des_encrypt_array_with_padding_iso_ecb_into_array()");
2540    use std::io::Write;
2541    use std::fmt::Write as _;
2542    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2543
2544    // Normal case
2545    let key = 0x_1234567890ABCDEF_u64;
2546    println!("K =\t{:#016X}", key);
2547    let mut a_des = DES::new_with_key_u64(key);
2548
2549    let mes = "In the beginning God created the heavens and the earth.";
2550    println!("M =\t{}", mes);
2551    let mut message = [0_u8; 55];
2552    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2553    let mut cipher = [0_u8; 56];
2554    a_des.encrypt_array_into_array(&message, &mut cipher);
2555    for c in cipher.clone()
2556        { print!("{:02X} ", c); }
2557    println!();
2558    let mut txt = String::new();
2559    for c in cipher.clone()
2560        { write!(txt, "{:02X} ", c); }
2561    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2562    println!();
2563
2564    // Expanded case for 128 rounds
2565    let key = 0x_1234567890ABCDEF_u64;
2566    println!("K =\t{:#016X}", key);
2567    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2568
2569    let mes = "In the beginning God created the heavens and the earth.";
2570    println!("M =\t{}", mes);
2571    let mut message = [0_u8; 55];
2572    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2573    let mut cipher = [0_u8; 56];
2574    a_des.encrypt_array_into_array(&message, &mut cipher);
2575    print!("C (128 rounds) =\t");
2576    for c in cipher.clone()
2577        { print!("{:02X} ", c); }
2578    println!();
2579    let mut txt = String::new();
2580    for c in cipher.clone()
2581        { write!(txt, "{:02X} ", c); }
2582    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2583    println!();
2584
2585    // Expanded case for 0 rounds which means that key is meaningless
2586    let key1 = 0x_1234567890ABCDEF_u64;
2587    let key2 = 0_u64;
2588    println!("K1 =\t{:#016X}", key1);
2589    println!("K2 =\t{:#016X}", key2);
2590    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2591    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2592
2593    let mes = "In the beginning God created the heavens and the earth.";
2594    println!("M =\t{}", mes);
2595    let mut message = [0_u8; 55];
2596    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2597    let mut cipher1 = [0_u8; 56];
2598    let mut cipher2 = [0_u8; 56];
2599    c_des.encrypt_array_into_array(&message, &mut cipher1);
2600    d_des.encrypt_array_into_array(&message, &mut cipher2);
2601    print!("C (0 rounds) =\t");
2602    for c in cipher1.clone()
2603        { print!("{:02X} ", c); }
2604    println!();
2605    let mut txt = String::new();
2606    for c in cipher1.clone()
2607        { write!(txt, "{:02X} ", c); }
2608    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2609    print!("D (0 rounds) =\t");
2610    for c in cipher2.clone()
2611        { print!("{:02X} ", c); }
2612    println!();
2613    let mut txt = String::new();
2614    for c in cipher2.clone()
2615        { write!(txt, "{:02X} ", c); }
2616    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2617    println!();
2618
2619    // Normal case for the message of 0 bytes
2620    let key = 0x_1234567890ABCDEF_u64;
2621    println!("K =\t{:#016X}", key);
2622    let mut a_des = DES::new_with_key_u64(key);
2623
2624    let mes = "";
2625    println!("M =\t{}", mes);
2626    let mut message = [0_u8; 0];
2627    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2628    let mut cipher = [0_u8; 8];
2629    a_des.encrypt_array_into_array(&message, &mut cipher);
2630    print!("C =\t");
2631    for c in cipher.clone()
2632        { print!("{:02X} ", c); }
2633    println!();
2634    let mut txt = String::new();
2635    for c in cipher.clone()
2636        { write!(txt, "{:02X} ", c); }
2637    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2638    println!();
2639
2640    // Normal case for the message shorter than 8 bytes
2641    let key = 0x_1234567890ABCDEF_u64;
2642    println!("K =\t{:#016X}", key);
2643    let mut a_des = DES::new_with_key_u64(key);
2644
2645    let mes = "7 bytes";
2646    println!("M =\t{}", mes);
2647    let mut message = [0_u8; 7];
2648    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2649    let mut cipher = [0_u8; 8];
2650    a_des.encrypt_array_into_array(&message, &mut cipher);
2651    print!("C =\t");
2652    for c in cipher.clone()
2653        { print!("{:02X} ", c); }
2654    println!();
2655    let mut txt = String::new();
2656    for c in cipher.clone()
2657        { write!(txt, "{:02X} ", c); }
2658    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2659    println!();
2660
2661    // Normal case for the message of 8 bytes
2662    let key = 0x_1234567890ABCDEF_u64;
2663    println!("K =\t{:#016X}", key);
2664    let mut a_des = DES::new_with_key_u64(key);
2665
2666    let mes = "I am OK.";
2667    println!("M =\t{}", mes);
2668    let mut message = [0_u8; 8];
2669    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2670    let mut cipher = [0_u8; 16];
2671    a_des.encrypt_array_into_array(&message, &mut cipher);
2672    print!("C =\t");
2673    for c in cipher.clone()
2674        { print!("{:02X} ", c); }
2675    println!();
2676    let mut txt = String::new();
2677    for c in cipher.clone()
2678        { write!(txt, "{:02X} ", c); }
2679    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2680    println!();
2681
2682    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2683    let key = 0x_1234567890ABCDEF_u64;
2684    println!("K =\t{:#016X}", key);
2685    let mut a_des = DES::new_with_key_u64(key);
2686
2687    let mes = "PARK Youngho";
2688    println!("M =\t{}", mes);
2689    let mut message = [0_u8; 12];
2690    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2691    let mut cipher = [0_u8; 16];
2692    a_des.encrypt_array_into_array(&message, &mut cipher);
2693    print!("C =\t");
2694    for c in cipher.clone()
2695        { print!("{:02X} ", c); }
2696    println!();
2697    let mut txt = String::new();
2698    for c in cipher.clone()
2699        { write!(txt, "{:02X} ", c); }
2700    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2701    println!();
2702
2703
2704    // Normal case for the message of 16 bytes
2705    let key = 0x_1234567890ABCDEF_u64;
2706    println!("K =\t{:#016X}", key);
2707    let mut a_des = DES::new_with_key_u64(key);
2708 
2709    let mes = "고맙습니다.";
2710    println!("M =\t{}", mes);
2711    let mut message = [0_u8; 16];
2712    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2713    let mut cipher = [0_u8; 24];
2714    a_des.encrypt_array_into_array(&message, &mut cipher);
2715    print!("C =\t");
2716    for c in cipher.clone()
2717        { print!("{:02X} ", c); }
2718    println!();
2719    let mut txt = String::new();
2720    for c in cipher.clone()
2721        { write!(txt, "{:02X} ", c); }
2722    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2723    println!("-------------------------------");
2724}
2725
2726fn des_decrypt_with_padding_iso_ecb()
2727{
2728    println!("des_decrypt_with_padding_iso_ecb()");
2729    use std::io::Write;
2730    use std::fmt::Write as _;
2731    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2732
2733    // Normal case
2734    let key = 0x_1234567890ABCDEF_u64;
2735    println!("K =\t{:#016X}", key);
2736    let mut a_des = DES::new_with_key_u64(key);
2737
2738    let message = "In the beginning God created the heavens and the earth.";
2739    println!("M =\t{}", message);
2740    let mut cipher = Vec::<u8>::new();
2741    a_des.encrypt_str_into_vec(&message, &mut cipher);
2742    print!("C (16 rounds) =\t");
2743    for c in cipher.clone()
2744        { print!("{:02X} ", c); }
2745    println!();
2746    let mut txt = String::new();
2747    for c in cipher.clone()
2748        { write!(txt, "{:02X} ", c); }
2749    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2750
2751    let mut recovered = vec![0; 55];
2752    a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2753    print!("Ba (16 rounds) =\t");
2754    for b in recovered.clone()
2755        { print!("{:02X} ", b); }
2756    println!();
2757    let mut txt = String::new();
2758    for c in recovered.clone()
2759        { write!(txt, "{:02X} ", c); }
2760    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2761
2762    let mut converted = String::new();
2763    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2764    
2765    println!("Bb (16 rounds) =\t{}", converted);
2766    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2767    assert_eq!(converted, message);
2768    println!();
2769
2770    // Expanded case for 128 rounds
2771    let key = 0x_1234567890ABCDEF_u64;
2772    println!("K =\t{:#016X}", key);
2773    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2774
2775    let message = "In the beginning God created the heavens and the earth.";
2776    println!("M =\t{}", message);
2777    let mut cipher = Vec::<u8>::new();
2778    a_des.encrypt_str_into_vec(&message, &mut cipher);
2779    print!("C (128 rounds) =\t");
2780    for c in cipher.clone()
2781        { print!("{:02X} ", c); }
2782    println!();
2783    let mut txt = String::new();
2784    for c in cipher.clone()
2785        { write!(txt, "{:02X} ", c); }
2786    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2787
2788    let mut recovered = vec![0; 55];
2789    a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2790    print!("Ba (128 rounds) =\t");
2791    for b in recovered.clone()
2792        { print!("{:02X} ", b); }
2793    println!();
2794    let mut txt = String::new();
2795    for c in recovered.clone()
2796        { write!(txt, "{:02X} ", c); }
2797    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2798
2799    let mut converted = String::new();
2800    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2801    
2802    println!("Bb (128 rounds) =\t{}", converted);
2803    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2804    assert_eq!(converted, message);
2805    println!();
2806
2807    // Expanded case for 0 rounds which means that key is meaningless
2808    let key1 = 0x_1234567890ABCDEF_u64;
2809    let key2 = 0_u64;
2810    println!("K =\t{:#016X}", key);
2811    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2812    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2813
2814    let message = "In the beginning God created the heavens and the earth.";
2815    println!("M =\t{}", message);
2816    let mut cipher1 = Vec::<u8>::new();
2817    let mut cipher2 = Vec::<u8>::new();
2818    c_des.encrypt_str_into_vec(&message, &mut cipher1);
2819    d_des.encrypt_str_into_vec(&message, &mut cipher2);
2820    print!("C (0 rounds) =\t");
2821    for c in cipher1.clone()
2822        { print!("{:02X} ", c); }
2823    println!();
2824    let mut txt = String::new();
2825    for c in cipher1.clone()
2826        { write!(txt, "{:02X} ", c); }
2827    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2828    print!("D (0 rounds) =\t");
2829    for c in cipher2.clone()
2830        { print!("{:02X} ", c); }
2831    println!();
2832    let mut txt = String::new();
2833    for c in cipher2.clone()
2834        { write!(txt, "{:02X} ", c); }
2835    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2836
2837    let mut recovered1 = vec![0; 55];
2838    let mut recovered2 = vec![0; 55];
2839    c_des.decrypt(cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
2840    d_des.decrypt(cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
2841    print!("B1a (0 rounds) =\t");
2842    for b in recovered1.clone()
2843        { print!("{:02X} ", b); }
2844    println!();
2845    let mut txt = String::new();
2846    for c in recovered1.clone()
2847        { write!(txt, "{:02X} ", c); }
2848    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2849    print!("B2a (0 rounds) =\t");
2850    for b in recovered2.clone()
2851        { print!("{:02X} ", b); }
2852    println!();
2853    let mut txt = String::new();
2854    for c in recovered2.clone()
2855        { write!(txt, "{:02X} ", c); }
2856    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2857
2858    let mut converted1 = String::new();
2859    let mut converted2 = String::new();
2860    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
2861    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
2862    
2863    println!("B1b (0 rounds) =\t{}", converted1);
2864    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
2865    assert_eq!(converted1, message);
2866    println!("B2b (0 rounds) =\t{}", converted2);
2867    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
2868    assert_eq!(converted2, message);
2869    assert_eq!(converted1, converted1);
2870    println!();
2871
2872    // Normal case for the message of 0 bytes
2873    let key = 0x_1234567890ABCDEF_u64;
2874    println!("K =\t{:#016X}", key);
2875    let mut a_des = DES::new_with_key_u64(key);
2876
2877    let message = "";
2878    println!("M =\t{}", message);
2879    let mut cipher = Vec::<u8>::new();
2880    a_des.encrypt_str_into_vec(&message, &mut cipher);
2881    print!("C =\t");
2882    for c in cipher.clone()
2883        { print!("{:02X} ", c); }
2884    println!();
2885    let mut txt = String::new();
2886    for c in cipher.clone()
2887        { write!(txt, "{:02X} ", c); }
2888    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2889
2890    let mut recovered = vec![0; 8];
2891    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2892    print!("Ba =\t");
2893    for b in recovered.clone()
2894        { print!("{:02X} ", b); }
2895    println!();
2896    let mut txt = String::new();
2897    for c in recovered.clone()
2898        { write!(txt, "{:02X} ", c); }
2899    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2900
2901    let mut converted = String::new();
2902    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2903    converted.truncate(len as usize);
2904    
2905    println!("Bb =\t{}", converted);
2906    assert_eq!(converted, "");
2907    assert_eq!(converted, message);
2908    println!();
2909
2910    // Normal case for the message shorter than 8 bytes
2911    let key = 0x_1234567890ABCDEF_u64;
2912    println!("K =\t{:#016X}", key);
2913    let mut a_des = DES::new_with_key_u64(key);
2914
2915    let message = "7 bytes";
2916    println!("M =\t{}", message);
2917    let mut cipher = Vec::<u8>::new();
2918    a_des.encrypt_str_into_vec(&message, &mut cipher);
2919    print!("C =\t");
2920    for c in cipher.clone()
2921        { print!("{:02X} ", c); }
2922    println!();
2923    let mut txt = String::new();
2924    for c in cipher.clone()
2925        { write!(txt, "{:02X} ", c); }
2926    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2927    
2928    let mut recovered = vec![0; 8];
2929    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2930    print!("Ba =\t");
2931    for b in recovered.clone()
2932        { print!("{:02X} ", b); }
2933    println!();
2934    let mut txt = String::new();
2935    for c in recovered.clone()
2936        { write!(txt, "{:02X} ", c); }
2937    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
2938
2939    let mut converted = String::new();
2940    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2941    converted.truncate(len as usize);
2942
2943    println!("Bb =\t{}", converted);
2944    assert_eq!(converted, "7 bytes");
2945    assert_eq!(converted, message);
2946    println!();
2947
2948    // Normal case for the message of 8 bytes
2949    let key = 0x_1234567890ABCDEF_u64;
2950    println!("K =\t{:#016X}", key);
2951    let mut a_des = DES::new_with_key_u64(key);
2952
2953    let message = "I am OK.";
2954    println!("M =\t{}", message);
2955    let mut cipher = Vec::<u8>::new();
2956    a_des.encrypt_str_into_vec(&message, &mut cipher);
2957    print!("C =\t");
2958    for c in cipher.clone()
2959        { print!("{:02X} ", c); }
2960    println!();
2961    let mut txt = String::new();
2962    for c in cipher.clone()
2963        { write!(txt, "{:02X} ", c); }
2964    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2965    
2966    let mut recovered = vec![0; 16];
2967    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2968    print!("Ba =\t");
2969    for b in recovered.clone()
2970        { print!("{:02X} ", b); }
2971    println!();
2972    let mut txt = String::new();
2973    for c in recovered.clone()
2974        { write!(txt, "{:02X} ", c); }
2975    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
2976
2977    let mut converted = String::new();
2978    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2979    converted.truncate(len as usize);
2980    
2981    println!("Bb =\t{}", converted);
2982    assert_eq!(converted, "I am OK.");
2983    assert_eq!(converted, message);
2984    println!();
2985
2986    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2987    let key = 0x_1234567890ABCDEF_u64;
2988    println!("K =\t{:#016X}", key);
2989    let mut a_des = DES::new_with_key_u64(key);
2990
2991    let message = "PARK Youngho";
2992    println!("M =\t{}", message);
2993    let mut cipher = Vec::<u8>::new();
2994    a_des.encrypt_str_into_vec(&message, &mut cipher);
2995    print!("C =\t");
2996    for c in cipher.clone()
2997        { print!("{:02X} ", c); }
2998    println!();
2999    let mut txt = String::new();
3000    for c in cipher.clone()
3001        { write!(txt, "{:02X} ", c); }
3002    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3003
3004    let mut recovered = vec![0; 16];
3005    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3006    print!("Ba =\t");
3007    for b in recovered.clone()
3008        { print!("{:02X} ", b); }
3009    println!();
3010    let mut txt = String::new();
3011    for c in recovered.clone()
3012        { write!(txt, "{:02X} ", c); }
3013    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3014
3015    let mut converted = String::new();
3016    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3017    converted.truncate(len as usize);
3018    
3019    println!("Bb =\t{}", converted);
3020    assert_eq!(converted, "PARK Youngho");
3021    assert_eq!(converted, message);
3022    println!();
3023
3024
3025    // Normal case for the message of 16 bytes
3026    let key = 0x_1234567890ABCDEF_u64;
3027    println!("K =\t{:#016X}", key);
3028    let mut a_des = DES::new_with_key_u64(key);
3029
3030    let message = "고맙습니다.";
3031    println!("M =\t{}", message);
3032    let mut cipher = Vec::<u8>::new();
3033    a_des.encrypt_str_into_vec(&message, &mut cipher);
3034    print!("C =\t");
3035    for c in cipher.clone()
3036        { print!("{:02X} ", c); }
3037    println!();
3038    let mut txt = String::new();
3039    for c in cipher.clone()
3040        { write!(txt, "{:02X} ", c); }
3041    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3042
3043    let mut recovered = vec![0; 24];
3044    let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3045    print!("Ba =\t");
3046    for b in recovered.clone()
3047        { print!("{:02X} ", b); }
3048    println!();
3049    let mut txt = String::new();
3050    for c in recovered.clone()
3051        { write!(txt, "{:02X} ", c); }
3052    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3053
3054    let mut converted = String::new();
3055    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3056    converted.truncate(len as usize);
3057    
3058    println!("Bb =\t{}", converted);
3059    assert_eq!(converted, "고맙습니다.");
3060    assert_eq!(converted, message);
3061    println!("-------------------------------");
3062}
3063
3064fn des_decrypt_with_padding_iso_ecb_into_vec()
3065{
3066    println!("des_decrypt_with_padding_iso_ecb_into_vec()");
3067    use std::io::Write;
3068    use std::fmt::Write as _;
3069    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3070
3071    // Normal case
3072    let key = 0x_1234567890ABCDEF_u64;
3073    println!("K =\t{:#016X}", key);
3074    let mut a_des = DES::new_with_key_u64(key);
3075
3076    let message = "In the beginning God created the heavens and the earth.";
3077    println!("M =\t{}", message);
3078    let mut cipher = Vec::<u8>::new();
3079    a_des.encrypt_str_into_vec(&message, &mut cipher);
3080    print!("C (16 rounds) =\t");
3081    for c in cipher.clone()
3082        { print!("{:02X} ", c); }
3083    println!();
3084    let mut txt = String::new();
3085    for c in cipher.clone()
3086        { write!(txt, "{:02X} ", c); }
3087    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3088
3089    let mut recovered = Vec::<u8>::new();
3090    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3091    print!("Ba (16 rounds) =\t");
3092    for b in recovered.clone()
3093        { print!("{:02X} ", b); }
3094    println!();
3095    let mut txt = String::new();
3096    for c in recovered.clone()
3097        { write!(txt, "{:02X} ", c); }
3098    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3099
3100    let mut converted = String::new();
3101    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3102    
3103    println!("Bb (16 rounds) =\t{}", converted);
3104    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3105    assert_eq!(converted, message);
3106    println!();
3107
3108    // Expanded case for 128 rounds
3109    let key = 0x_1234567890ABCDEF_u64;
3110    println!("K =\t{:#016X}", key);
3111    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3112
3113    let message = "In the beginning God created the heavens and the earth.";
3114    println!("M =\t{}", message);
3115    let mut cipher = Vec::<u8>::new();
3116    a_des.encrypt_str_into_vec(&message, &mut cipher);
3117    print!("C (128 rounds) =\t");
3118    for c in cipher.clone()
3119        { print!("{:02X} ", c); }
3120    println!();
3121    let mut txt = String::new();
3122    for c in cipher.clone()
3123        { write!(txt, "{:02X} ", c); }
3124    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3125
3126    let mut recovered = Vec::<u8>::new();
3127    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3128    print!("Ba (128 rounds) =\t");
3129    for b in recovered.clone()
3130        { print!("{:02X} ", b); }
3131    println!();
3132    let mut txt = String::new();
3133    for c in recovered.clone()
3134        { write!(txt, "{:02X} ", c); }
3135    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3136
3137    let mut converted = String::new();
3138    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139    
3140    println!("Bb (128 rounds) =\t{}", converted);
3141    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3142    assert_eq!(converted, message);
3143    println!();
3144
3145    // Expanded case for 0 rounds which means that key is meaningless
3146    let key1 = 0x_1234567890ABCDEF_u64;
3147    let key2 = 0_u64;
3148    println!("K =\t{:#016X}", key);
3149    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3150    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3151
3152    let message = "In the beginning God created the heavens and the earth.";
3153    println!("M =\t{}", message);
3154    let mut cipher1 = Vec::<u8>::new();
3155    let mut cipher2 = Vec::<u8>::new();
3156    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3157    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3158    print!("C (0 rounds) =\t");
3159    for c in cipher1.clone()
3160        { print!("{:02X} ", c); }
3161    println!();
3162    let mut txt = String::new();
3163    for c in cipher1.clone()
3164        { write!(txt, "{:02X} ", c); }
3165    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3166    print!("D (0 rounds) =\t");
3167    for c in cipher2.clone()
3168        { print!("{:02X} ", c); }
3169    println!();
3170    let mut txt = String::new();
3171    for c in cipher2.clone()
3172        { write!(txt, "{:02X} ", c); }
3173    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3174
3175    let mut recovered1 = Vec::<u8>::new();
3176    let mut recovered2 = Vec::<u8>::new();
3177    c_des.decrypt_into_vec(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3178    d_des.decrypt_into_vec(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3179    print!("B1a (0 rounds) =\t");
3180    for b in recovered1.clone()
3181        { print!("{:02X} ", b); }
3182    println!();
3183    let mut txt = String::new();
3184    for c in recovered1.clone()
3185        { write!(txt, "{:02X} ", c); }
3186    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3187    print!("B2a (0 rounds) =\t");
3188    for b in recovered2.clone()
3189        { print!("{:02X} ", b); }
3190    println!();
3191    let mut txt = String::new();
3192    for c in recovered2.clone()
3193        { write!(txt, "{:02X} ", c); }
3194    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3195
3196    let mut converted1 = String::new();
3197    let mut converted2 = String::new();
3198    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3199    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3200    
3201    println!("B1b (0 rounds) =\t{}", converted1);
3202    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3203    assert_eq!(converted1, message);
3204    println!("B2b (0 rounds) =\t{}", converted2);
3205    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3206    assert_eq!(converted2, message);
3207    assert_eq!(converted1, converted1);
3208    println!();
3209
3210    // Normal case for the message of 0 bytes
3211    let key = 0x_1234567890ABCDEF_u64;
3212    println!("K =\t{:#016X}", key);
3213    let mut a_des = DES::new_with_key_u64(key);
3214
3215    let message = "";
3216    println!("M =\t{}", message);
3217    let mut cipher = Vec::<u8>::new();
3218    a_des.encrypt_str_into_vec(&message, &mut cipher);
3219    print!("C =\t");
3220    for c in cipher.clone()
3221        { print!("{:02X} ", c); }
3222    println!();
3223    let mut txt = String::new();
3224    for c in cipher.clone()
3225        { write!(txt, "{:02X} ", c); }
3226    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3227
3228    let mut recovered = Vec::<u8>::new();
3229    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3230    print!("Ba =\t");
3231    for b in recovered.clone()
3232        { print!("{:02X} ", b); }
3233    println!();
3234    let mut txt = String::new();
3235    for c in recovered.clone()
3236        { write!(txt, "{:02X} ", c); }
3237    assert_eq!(txt, "");
3238
3239    let mut converted = String::new();
3240    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3241    
3242    println!("Bb =\t{}", converted);
3243    assert_eq!(converted, "");
3244    assert_eq!(converted, message);
3245    println!();
3246
3247    // Normal case for the message shorter than 8 bytes
3248    let key = 0x_1234567890ABCDEF_u64;
3249    println!("K =\t{:#016X}", key);
3250    let mut a_des = DES::new_with_key_u64(key);
3251
3252    let message = "7 bytes";
3253    println!("M =\t{}", message);
3254    let mut cipher = Vec::<u8>::new();
3255    a_des.encrypt_str_into_vec(&message, &mut cipher);
3256    print!("C =\t");
3257    for c in cipher.clone()
3258        { print!("{:02X} ", c); }
3259    println!();
3260    let mut txt = String::new();
3261    for c in cipher.clone()
3262        { write!(txt, "{:02X} ", c); }
3263    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3264    
3265    let mut recovered = Vec::<u8>::new();
3266    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3267    print!("Ba =\t");
3268    for b in recovered.clone()
3269        { print!("{:02X} ", b); }
3270    println!();
3271    let mut txt = String::new();
3272    for c in recovered.clone()
3273        { write!(txt, "{:02X} ", c); }
3274    assert_eq!(txt, "37 20 62 79 74 65 73 ");
3275
3276    let mut converted = String::new();
3277    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3278    
3279    println!("Bb =\t{}", converted);
3280    assert_eq!(converted, "7 bytes");
3281    assert_eq!(converted, message);
3282    println!();
3283
3284    // Normal case for the message of 8 bytes
3285    let key = 0x_1234567890ABCDEF_u64;
3286    println!("K =\t{:#016X}", key);
3287    let mut a_des = DES::new_with_key_u64(key);
3288
3289    let message = "I am OK.";
3290    println!("M =\t{}", message);
3291    let mut cipher = Vec::<u8>::new();
3292    a_des.encrypt_str_into_vec(&message, &mut cipher);
3293    print!("C =\t");
3294    for c in cipher.clone()
3295        { print!("{:02X} ", c); }
3296    println!();
3297    let mut txt = String::new();
3298    for c in cipher.clone()
3299        { write!(txt, "{:02X} ", c); }
3300    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3301    
3302    let mut recovered = Vec::<u8>::new();
3303    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3304    print!("Ba =\t");
3305    for b in recovered.clone()
3306        { print!("{:02X} ", b); }
3307    println!();
3308    let mut txt = String::new();
3309    for c in recovered.clone()
3310        { write!(txt, "{:02X} ", c); }
3311    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3312
3313    let mut converted = String::new();
3314    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3315    
3316    println!("Bb =\t{}", converted);
3317    assert_eq!(converted, "I am OK.");
3318    assert_eq!(converted, message);
3319    println!();
3320
3321    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3322    let key = 0x_1234567890ABCDEF_u64;
3323    println!("K =\t{:#016X}", key);
3324    let mut a_des = DES::new_with_key_u64(key);
3325
3326    let message = "PARK Youngho";
3327    println!("M =\t{}", message);
3328    let mut cipher = Vec::<u8>::new();
3329    a_des.encrypt_str_into_vec(&message, &mut cipher);
3330    print!("C =\t");
3331    for c in cipher.clone()
3332        { print!("{:02X} ", c); }
3333    println!();
3334    let mut txt = String::new();
3335    for c in cipher.clone()
3336        { write!(txt, "{:02X} ", c); }
3337    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3338
3339    let mut recovered = Vec::<u8>::new();
3340    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3341    print!("Ba =\t");
3342    for b in recovered.clone()
3343        { print!("{:02X} ", b); }
3344    println!();
3345    let mut txt = String::new();
3346    for c in recovered.clone()
3347        { write!(txt, "{:02X} ", c); }
3348    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3349
3350    let mut converted = String::new();
3351    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3352    
3353    println!("Bb =\t{}", converted);
3354    assert_eq!(converted, "PARK Youngho");
3355    assert_eq!(converted, message);
3356    println!();
3357
3358    // Normal case for the message of 16 bytes
3359    let key = 0x_1234567890ABCDEF_u64;
3360    println!("K =\t{:#016X}", key);
3361    let mut a_des = DES::new_with_key_u64(key);
3362
3363    let message = "고맙습니다.";
3364    println!("M =\t{}", message);
3365    let mut cipher = Vec::<u8>::new();
3366    a_des.encrypt_str_into_vec(&message, &mut cipher);
3367    print!("C =\t");
3368    for c in cipher.clone()
3369        { print!("{:02X} ", c); }
3370    println!();
3371    let mut txt = String::new();
3372    for c in cipher.clone()
3373        { write!(txt, "{:02X} ", c); }
3374    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3375
3376    let mut recovered = Vec::<u8>::new();
3377    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3378    print!("Ba =\t");
3379    for b in recovered.clone()
3380        { print!("{:02X} ", b); }
3381    println!();
3382    let mut txt = String::new();
3383    for c in recovered.clone()
3384        { write!(txt, "{:02X} ", c); }
3385    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3386
3387    let mut converted = String::new();
3388    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3389    
3390    println!("Bb =\t{}", converted);
3391    assert_eq!(converted, "고맙습니다.");
3392    assert_eq!(converted, message);
3393    println!("-------------------------------");
3394}
3395
3396fn des_decrypt_with_padding_iso_ecb_into_array()
3397{
3398    println!("des_decrypt_with_padding_iso_ecb_into_array()");
3399    use std::io::Write;
3400    use std::fmt::Write as _;
3401    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3402
3403    // Normal case
3404    let key = 0x_1234567890ABCDEF_u64;
3405    println!("K =\t{:#016X}", key);
3406    let mut a_des = DES::new_with_key_u64(key);
3407
3408    let message = "In the beginning God created the heavens and the earth.";
3409    println!("M =\t{}", message);
3410    let mut cipher = Vec::<u8>::new();
3411    a_des.encrypt_str_into_vec(&message, &mut cipher);
3412    print!("C (16 rounds) =\t");
3413    for c in cipher.clone()
3414        { print!("{:02X} ", c); }
3415    println!();
3416    let mut txt = String::new();
3417    for c in cipher.clone()
3418        { write!(txt, "{:02X} ", c); }
3419    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3420
3421    let mut recovered = [0u8; 56];
3422    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3423    print!("Ba (16 rounds) =\t");
3424    for b in recovered.clone()
3425        { print!("{:02X} ", b); }
3426    println!();
3427    let mut txt = String::new();
3428    for c in recovered.clone()
3429        { write!(txt, "{:02X} ", c); }
3430    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3431
3432    let mut converted = String::new();
3433    unsafe { converted.as_mut_vec() }.write(&recovered);
3434    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3435    println!("Bb (16 rounds) =\t{}", converted);
3436    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3437    assert_eq!(converted, message);
3438    println!();
3439
3440    // Expanded case for 128 rounds
3441    let key = 0x_1234567890ABCDEF_u64;
3442    println!("K =\t{:#016X}", key);
3443    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3444
3445    let message = "In the beginning God created the heavens and the earth.";
3446    println!("M =\t{}", message);
3447    let mut cipher = Vec::<u8>::new();
3448    a_des.encrypt_str_into_vec(&message, &mut cipher);
3449    print!("C (128 rounds) =\t");
3450    for c in cipher.clone()
3451        { print!("{:02X} ", c); }
3452    println!();
3453    let mut txt = String::new();
3454    for c in cipher.clone()
3455        { write!(txt, "{:02X} ", c); }
3456    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3457
3458    let mut recovered = [0u8; 56];
3459    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3460    print!("Ba (16 rounds) =\t");
3461    for b in recovered.clone()
3462        { print!("{:02X} ", b); }
3463    println!();
3464    let mut txt = String::new();
3465    for c in recovered.clone()
3466        { write!(txt, "{:02X} ", c); }
3467    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3468
3469    let mut converted = String::new();
3470    unsafe { converted.as_mut_vec() }.write(&recovered);
3471    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3472    println!("Bb (16 rounds) =\t{}", converted);
3473    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3474    assert_eq!(converted, message);
3475    println!();
3476
3477    // Expanded case for 0 rounds which means that key is meaningless
3478    let key1 = 0x_1234567890ABCDEF_u64;
3479    let key2 = 0_u64;
3480    println!("K =\t{:#016X}", key);
3481    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3482    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3483
3484    let message = "In the beginning God created the heavens and the earth.";
3485    println!("M =\t{}", message);
3486    let mut cipher1 = Vec::<u8>::new();
3487    let mut cipher2 = Vec::<u8>::new();
3488    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3489    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3490    print!("C (0 rounds) =\t");
3491    for c in cipher1.clone()
3492        { print!("{:02X} ", c); }
3493    println!();
3494    let mut txt = String::new();
3495    for c in cipher1.clone()
3496        { write!(txt, "{:02X} ", c); }
3497    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3498    print!("D (0 rounds) =\t");
3499    for c in cipher2.clone()
3500        { print!("{:02X} ", c); }
3501    println!();
3502    let mut txt = String::new();
3503    for c in cipher2.clone()
3504        { write!(txt, "{:02X} ", c); }
3505    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3506
3507    let mut recovered1 = [0u8; 56];
3508    let mut recovered2 = [0u8; 56];
3509    let len1 = c_des.decrypt_into_array(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3510    let len2 = d_des.decrypt_into_array(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3511    print!("B1a (0 rounds) =\t");
3512    for b in recovered1.clone()
3513        { print!("{:02X} ", b); }
3514    println!();
3515    let mut txt = String::new();
3516    for c in recovered1.clone()
3517        { write!(txt, "{:02X} ", c); }
3518    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3519    print!("B2a (0 rounds) =\t");
3520    for b in recovered2.clone()
3521        { print!("{:02X} ", b); }
3522    println!();
3523    let mut txt = String::new();
3524    for c in recovered.clone()
3525        { write!(txt, "{:02X} ", c); }
3526    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3527
3528    let mut converted1 = String::new();
3529    let mut converted2 = String::new();
3530    unsafe { converted1.as_mut_vec() }.write(&recovered1);
3531    unsafe { converted2.as_mut_vec() }.write(&recovered2);
3532    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3533    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3534    println!("B1b (0 rounds) =\t{}", converted1);
3535    println!("B2b (0 rounds) =\t{}", converted2);
3536    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3537    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3538    assert_eq!(converted1, message);
3539    assert_eq!(converted2, message);
3540    assert_eq!(converted1, converted2);
3541    println!();
3542
3543    // Normal case for the message of 0 bytes
3544    let key = 0x_1234567890ABCDEF_u64;
3545    println!("K =\t{:#016X}", key);
3546    let mut a_des = DES::new_with_key_u64(key);
3547
3548    let message = "";
3549    println!("M =\t{}", message);
3550    let mut cipher = Vec::<u8>::new();
3551    a_des.encrypt_str_into_vec(&message, &mut cipher);
3552    print!("C =\t");
3553    for c in cipher.clone()
3554        { print!("{:02X} ", c); }
3555    println!();
3556    let mut txt = String::new();
3557    for c in cipher.clone()
3558        { write!(txt, "{:02X} ", c); }
3559    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3560
3561    let mut recovered = [0u8; 8];
3562    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3563
3564    print!("Ba =\t");
3565    for b in recovered.clone()
3566        { print!("{:02X} ", b); }
3567    println!();
3568    let mut txt = String::new();
3569    for c in recovered.clone()
3570        { write!(txt, "{:02X} ", c); }
3571    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3572
3573    let mut converted = String::new();
3574    unsafe { converted.as_mut_vec() }.write(&recovered);
3575    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3576    println!("Bb =\t{}", converted);
3577    assert_eq!(converted, "");
3578    assert_eq!(converted, message);
3579    println!();
3580
3581    // Normal case for the message shorter than 8 bytes
3582    let key = 0x_1234567890ABCDEF_u64;
3583    println!("K =\t{:#016X}", key);
3584    let mut a_des = DES::new_with_key_u64(key);
3585
3586    let message = "7 bytes";
3587    println!("M =\t{}", message);
3588    let mut cipher = Vec::<u8>::new();
3589    a_des.encrypt_str_into_vec(&message, &mut cipher);
3590    print!("C =\t");
3591    for c in cipher.clone()
3592        { print!("{:02X} ", c); }
3593    println!();
3594    let mut txt = String::new();
3595    for c in cipher.clone()
3596        { write!(txt, "{:02X} ", c); }
3597    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3598
3599    let mut recovered = [0u8; 8];
3600    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3601
3602    print!("Ba =\t");
3603    for b in recovered.clone()
3604        { print!("{:02X} ", b); }
3605    println!();
3606    let mut txt = String::new();
3607    for c in recovered.clone()
3608        { write!(txt, "{:02X} ", c); }
3609    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3610
3611    let mut converted = String::new();
3612    unsafe { converted.as_mut_vec() }.write(&recovered);
3613    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3614    println!("Bb =\t{}", converted);
3615    assert_eq!(converted, "7 bytes");
3616    assert_eq!(converted, message);
3617    println!();
3618
3619    // Normal case for the message of 8 bytes
3620    let key = 0x_1234567890ABCDEF_u64;
3621    println!("K =\t{:#016X}", key);
3622    let mut a_des = DES::new_with_key_u64(key);
3623
3624    let message = "I am OK.";
3625    println!("M =\t{}", message);
3626    let mut cipher = Vec::<u8>::new();
3627    a_des.encrypt_str_into_vec(&message, &mut cipher);
3628    print!("C =\t");
3629    for c in cipher.clone()
3630        { print!("{:02X} ", c); }
3631    println!();
3632    let mut txt = String::new();
3633    for c in cipher.clone()
3634        { write!(txt, "{:02X} ", c); }
3635    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3636
3637    let mut recovered = [0u8; 16];
3638    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3639
3640    print!("Ba =\t");
3641    for b in recovered.clone()
3642        { print!("{:02X} ", b); }
3643    println!();
3644    let mut txt = String::new();
3645    for c in recovered.clone()
3646        { write!(txt, "{:02X} ", c); }
3647    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3648
3649    let mut converted = String::new();
3650    unsafe { converted.as_mut_vec() }.write(&recovered);
3651    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3652    println!("Bb =\t{}", converted);
3653    assert_eq!(converted, "I am OK.");
3654    assert_eq!(converted, message);
3655    println!();
3656
3657    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3658    let key = 0x_1234567890ABCDEF_u64;
3659    println!("K =\t{:#016X}", key);
3660    let mut a_des = DES::new_with_key_u64(key);
3661
3662    let message = "PARK Youngho";
3663    println!("M =\t{}", message);
3664    let mut cipher = Vec::<u8>::new();
3665    a_des.encrypt_str_into_vec(&message, &mut cipher);
3666    print!("C =\t");
3667    for c in cipher.clone()
3668        { print!("{:02X} ", c); }
3669    println!();
3670    let mut txt = String::new();
3671    for c in cipher.clone()
3672        { write!(txt, "{:02X} ", c); }
3673    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3674
3675    let mut recovered = [0u8; 16];
3676    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3677
3678    print!("Ba =\t");
3679    for b in recovered.clone()
3680        { print!("{:02X} ", b); }
3681    println!();
3682    let mut txt = String::new();
3683    for c in recovered.clone()
3684        { write!(txt, "{:02X} ", c); }
3685    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3686
3687    let mut converted = String::new();
3688    unsafe { converted.as_mut_vec() }.write(&recovered);
3689    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3690    println!("Bb =\t{}", converted);
3691    assert_eq!(converted, "PARK Youngho");
3692    assert_eq!(converted, message);
3693    println!();
3694
3695    // Normal case for the message of 16 bytes
3696    let key = 0x_1234567890ABCDEF_u64;
3697    println!("K =\t{:#016X}", key);
3698    let mut a_des = DES::new_with_key_u64(key);
3699
3700    let message = "고맙습니다.";
3701    println!("M =\t{}", message);
3702    let mut cipher = Vec::<u8>::new();
3703    a_des.encrypt_str_into_vec(&message, &mut cipher);
3704    print!("C =\t");
3705    for c in cipher.clone()
3706        { print!("{:02X} ", c); }
3707    println!();
3708    let mut txt = String::new();
3709    for c in cipher.clone()
3710        { write!(txt, "{:02X} ", c); }
3711    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3712
3713    let mut recovered = [0u8; 24];
3714    let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3715
3716    print!("Ba =\t");
3717    for b in recovered.clone()
3718        { print!("{:02X} ", b); }
3719    println!();
3720    let mut txt = String::new();
3721    for c in recovered.clone()
3722        { write!(txt, "{:02X} ", c); }
3723    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3724
3725    let mut converted = String::new();
3726    unsafe { converted.as_mut_vec() }.write(&recovered);
3727    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3728    println!("Bb =\t{}", converted);
3729    assert_eq!(converted, "고맙습니다.");
3730    assert_eq!(converted, message);
3731    println!("-------------------------------");
3732}
3733
3734fn des_decrypt_with_padding_iso_ecb_into_string()
3735{
3736    println!("des_decrypt_with_padding_iso_ecb_into_string()");
3737    use std::io::Write;
3738    use std::fmt::Write as _;
3739    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3740
3741    // Normal case
3742    let key = 0x_1234567890ABCDEF_u64;
3743    println!("K =\t{:#016X}", key);
3744    let mut a_des = DES::new_with_key_u64(key);
3745
3746    let message = "In the beginning God created the heavens and the earth.";
3747    println!("M =\t{}", message);
3748    let mut cipher = Vec::<u8>::new();
3749    a_des.encrypt_str_into_vec(&message, &mut cipher);
3750    print!("C (16 rounds) =\t");
3751    for c in cipher.clone()
3752        { print!("{:02X} ", c); }
3753    println!();
3754    let mut txt = String::new();
3755    for c in cipher.clone()
3756        { write!(txt, "{:02X} ", c); }
3757    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3758
3759    let mut recovered = String::new();
3760    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3761    println!("B (16 rounds) =\t{}", recovered);
3762    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3763    assert_eq!(recovered, message);
3764    println!();
3765
3766    // Expanded case for 128 rounds
3767    let key = 0x_1234567890ABCDEF_u64;
3768    println!("K =\t{:#016X}", key);
3769    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3770
3771    let message = "In the beginning God created the heavens and the earth.";
3772    println!("M =\t{}", message);
3773    let mut cipher = Vec::<u8>::new();
3774    a_des.encrypt_str_into_vec(&message, &mut cipher);
3775    print!("C (128 rounds) =\t");
3776    for c in cipher.clone()
3777        { print!("{:02X} ", c); }
3778    println!();
3779    let mut txt = String::new();
3780    for c in cipher.clone()
3781        { write!(txt, "{:02X} ", c); }
3782    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3783
3784    let mut recovered = String::new();
3785    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3786    println!("B (128 rounds) =\t{}", recovered);
3787    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3788    assert_eq!(recovered, message);
3789    println!();
3790
3791    // Expanded case for 0 rounds which means that key is meaningless
3792    let key1 = 0x_1234567890ABCDEF_u64;
3793    let key2 = 0_u64;
3794    println!("K =\t{:#016X}", key);
3795    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3796    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3797
3798    let message = "In the beginning God created the heavens and the earth.";
3799    println!("M =\t{}", message);
3800    let mut cipher1 = Vec::<u8>::new();
3801    let mut cipher2 = Vec::<u8>::new();
3802    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3803    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3804    print!("C (0 rounds) =\t");
3805    for c in cipher1.clone()
3806        { print!("{:02X} ", c); }
3807    println!();
3808    let mut txt = String::new();
3809    for c in cipher1.clone()
3810        { write!(txt, "{:02X} ", c); }
3811    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3812    print!("D (0 rounds) =\t");
3813    for c in cipher2.clone()
3814        { print!("{:02X} ", c); }
3815    println!();
3816    let mut txt = String::new();
3817    for c in cipher2.clone()
3818        { write!(txt, "{:02X} ", c); }
3819    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3820
3821    let mut recovered1 = String::new();
3822    let mut recovered2 = String::new();
3823    c_des.decrypt_into_string(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3824    d_des.decrypt_into_string(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3825    println!("B1 (0 rounds) =\t{}", recovered1);
3826    println!("B2 (0 rounds) =\t{}", recovered2);
3827    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
3828    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
3829    assert_eq!(recovered1, message);
3830    assert_eq!(recovered2, message);
3831    assert_eq!(recovered1, recovered2);
3832    println!();
3833
3834    // Normal case for the message of 0 bytes
3835    let key = 0x_1234567890ABCDEF_u64;
3836    println!("K =\t{:#016X}", key);
3837    let mut a_des = DES::new_with_key_u64(key);
3838
3839    let message = "";
3840    println!("M =\t{}", message);
3841    let mut cipher = Vec::<u8>::new();
3842    a_des.encrypt_str_into_vec(&message, &mut cipher);
3843    print!("C =\t");
3844    for c in cipher.clone()
3845        { print!("{:02X} ", c); }
3846    println!();
3847    let mut txt = String::new();
3848    for c in cipher.clone()
3849        { write!(txt, "{:02X} ", c); }
3850    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3851
3852    let mut recovered = String::new();
3853    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3854    println!("B =\t{}", recovered);
3855    assert_eq!(recovered, "");
3856    assert_eq!(recovered, message);
3857    println!();
3858
3859    // Normal case for the message shorter than 8 bytes
3860    let key = 0x_1234567890ABCDEF_u64;
3861    println!("K =\t{:#016X}", key);
3862    let mut a_des = DES::new_with_key_u64(key);
3863
3864    let message = "7 bytes";
3865    println!("M =\t{}", message);
3866    let mut cipher = Vec::<u8>::new();
3867    a_des.encrypt_str_into_vec(&message, &mut cipher);
3868    print!("C =\t");
3869    for c in cipher.clone()
3870        { print!("{:02X} ", c); }
3871    println!();
3872    let mut txt = String::new();
3873    for c in cipher.clone()
3874        { write!(txt, "{:02X} ", c); }
3875    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3876
3877    let mut recovered = String::new();
3878    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3879    println!("B =\t{}", recovered);
3880    assert_eq!(recovered, "7 bytes");
3881    assert_eq!(recovered, message);
3882    println!();
3883
3884    // Normal case for the message of 8 bytes
3885    let key = 0x_1234567890ABCDEF_u64;
3886    println!("K =\t{:#016X}", key);
3887    let mut a_des = DES::new_with_key_u64(key);
3888
3889    let message = "I am OK.";
3890    println!("M =\t{}", message);
3891    let mut cipher = Vec::<u8>::new();
3892    a_des.encrypt_str_into_vec(&message, &mut cipher);
3893    print!("C =\t");
3894    for c in cipher.clone()
3895        { print!("{:02X} ", c); }
3896    println!();
3897    let mut txt = String::new();
3898    for c in cipher.clone()
3899        { write!(txt, "{:02X} ", c); }
3900    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3901
3902    let mut recovered = String::new();
3903    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3904    println!("B =\t{}", recovered);
3905    assert_eq!(recovered, "I am OK.");
3906    assert_eq!(recovered, message);
3907    println!();
3908
3909    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3910    let key = 0x_1234567890ABCDEF_u64;
3911    println!("K =\t{:#016X}", key);
3912    let mut a_des = DES::new_with_key_u64(key);
3913
3914    let message = "PARK Youngho";
3915    println!("M =\t{}", message);
3916    let mut cipher = Vec::<u8>::new();
3917    a_des.encrypt_str_into_vec(&message, &mut cipher);
3918    print!("C =\t");
3919    for c in cipher.clone()
3920        { print!("{:02X} ", c); }
3921    println!();
3922    let mut txt = String::new();
3923    for c in cipher.clone()
3924        { write!(txt, "{:02X} ", c); }
3925    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3926
3927    let mut recovered = String::new();
3928    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3929    println!("B =\t{}", recovered);
3930    assert_eq!(recovered, "PARK Youngho");
3931    assert_eq!(recovered, message);
3932    println!();
3933
3934    // Normal case for the message of 16 bytes
3935    let key = 0x_1234567890ABCDEF_u64;
3936    println!("K =\t{:#016X}", key);
3937    let mut a_des = DES::new_with_key_u64(key);
3938
3939    let message = "고맙습니다.";
3940    println!("M =\t{}", message);
3941    let mut cipher = Vec::<u8>::new();
3942    a_des.encrypt_str_into_vec(&message, &mut cipher);
3943    print!("C =\t");
3944    for c in cipher.clone()
3945        { print!("{:02X} ", c); }
3946    println!();
3947    let mut txt = String::new();
3948    for c in cipher.clone()
3949        { write!(txt, "{:02X} ", c); }
3950    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3951
3952    let mut recovered = String::new();
3953    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3954    println!("B =\t{}", recovered);
3955    assert_eq!(recovered, "고맙습니다.");
3956    assert_eq!(recovered, message);
3957    println!("-------------------------------");
3958}
3959
3960fn des_decrypt_vec_with_padding_iso_ecb()
3961{
3962    println!("des_decrypt_vec_with_padding_iso_ecb()");
3963    use std::io::Write;
3964    use std::fmt::Write as _;
3965    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3966
3967    // Normal case
3968    let key = 0x_1234567890ABCDEF_u64;
3969    println!("K =\t{:#016X}", key);
3970    let mut a_des = DES::new_with_key_u64(key);
3971
3972    let message = "In the beginning God created the heavens and the earth.";
3973    println!("M =\t{}", message);
3974    let mut cipher = Vec::<u8>::new();
3975    a_des.encrypt_str_into_vec(&message, &mut cipher);
3976    print!("C (16 rounds) =\t");
3977    for c in cipher.clone()
3978        { print!("{:02X} ", c); }
3979    println!();
3980    let mut txt = String::new();
3981    for c in cipher.clone()
3982        { write!(txt, "{:02X} ", c); }
3983    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3984
3985    let mut recovered = vec![0; 55];
3986    a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
3987    print!("Ba (16 rounds) =\t");
3988    for b in recovered.clone()
3989        { print!("{:02X} ", b); }
3990    println!();
3991    let mut txt = String::new();
3992    for c in recovered.clone()
3993        { write!(txt, "{:02X} ", c); }
3994    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3995
3996    let mut converted = String::new();
3997    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3998    
3999    println!("Bb (16 rounds) =\t{}", converted);
4000    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4001    assert_eq!(converted, message);
4002    println!();
4003
4004    // Expanded case for 128 rounds
4005    let key = 0x_1234567890ABCDEF_u64;
4006    println!("K =\t{:#016X}", key);
4007    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4008
4009    let message = "In the beginning God created the heavens and the earth.";
4010    println!("M =\t{}", message);
4011    let mut cipher = Vec::<u8>::new();
4012    a_des.encrypt_str_into_vec(&message, &mut cipher);
4013    print!("C (128 rounds) =\t");
4014    for c in cipher.clone()
4015        { print!("{:02X} ", c); }
4016    println!();
4017    let mut txt = String::new();
4018    for c in cipher.clone()
4019        { write!(txt, "{:02X} ", c); }
4020    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4021
4022    let mut recovered = vec![0; 55];
4023    a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4024    print!("Ba (128 rounds) =\t");
4025    for b in recovered.clone()
4026        { print!("{:02X} ", b); }
4027    println!();
4028    let mut txt = String::new();
4029    for c in recovered.clone()
4030        { write!(txt, "{:02X} ", c); }
4031    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4032
4033    let mut converted = String::new();
4034    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4035    
4036    println!("Bb (128 rounds) =\t{}", converted);
4037    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4038    assert_eq!(converted, message);
4039    println!();
4040
4041    // Expanded case for 0 rounds which means that key is meaningless
4042    let key1 = 0x_1234567890ABCDEF_u64;
4043    let key2 = 0_u64;
4044    println!("K =\t{:#016X}", key);
4045    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4046    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4047
4048    let message = "In the beginning God created the heavens and the earth.";
4049    println!("M =\t{}", message);
4050    let mut cipher1 = Vec::<u8>::new();
4051    let mut cipher2 = Vec::<u8>::new();
4052    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4053    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4054    print!("C (0 rounds) =\t");
4055    for c in cipher1.clone()
4056        { print!("{:02X} ", c); }
4057    println!();
4058    let mut txt = String::new();
4059    for c in cipher1.clone()
4060        { write!(txt, "{:02X} ", c); }
4061    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4062    print!("D (0 rounds) =\t");
4063    for c in cipher2.clone()
4064        { print!("{:02X} ", c); }
4065    println!();
4066    let mut txt = String::new();
4067    for c in cipher2.clone()
4068        { write!(txt, "{:02X} ", c); }
4069    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4070
4071    let mut recovered1 = vec![0; 55];
4072    let mut recovered2 = vec![0; 55];
4073    c_des.decrypt_vec(&cipher1, recovered1.as_mut_ptr());
4074    d_des.decrypt_vec(&cipher2, recovered2.as_mut_ptr());
4075    print!("B1a (0 rounds) =\t");
4076    for b in recovered1.clone()
4077        { print!("{:02X} ", b); }
4078    println!();
4079    let mut txt = String::new();
4080    for c in recovered1.clone()
4081        { write!(txt, "{:02X} ", c); }
4082    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4083    print!("B2a (0 rounds) =\t");
4084    for b in recovered2.clone()
4085        { print!("{:02X} ", b); }
4086    println!();
4087    let mut txt = String::new();
4088    for c in recovered2.clone()
4089        { write!(txt, "{:02X} ", c); }
4090    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4091
4092    let mut converted1 = String::new();
4093    let mut converted2 = String::new();
4094    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4095    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4096    
4097    println!("B1b (0 rounds) =\t{}", converted1);
4098    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4099    assert_eq!(converted1, message);
4100    println!("B2b (0 rounds) =\t{}", converted2);
4101    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4102    assert_eq!(converted2, message);
4103    assert_eq!(converted1, converted1);
4104    println!();
4105
4106    // Normal case for the message of 0 bytes
4107    let key = 0x_1234567890ABCDEF_u64;
4108    println!("K =\t{:#016X}", key);
4109    let mut a_des = DES::new_with_key_u64(key);
4110
4111    let message = "";
4112    println!("M =\t{}", message);
4113    let mut cipher = Vec::<u8>::new();
4114    a_des.encrypt_str_into_vec(&message, &mut cipher);
4115    print!("C =\t");
4116    for c in cipher.clone()
4117        { print!("{:02X} ", c); }
4118    println!();
4119    let mut txt = String::new();
4120    for c in cipher.clone()
4121        { write!(txt, "{:02X} ", c); }
4122    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4123
4124    let mut recovered = vec![0; 8];
4125    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4126    print!("Ba =\t");
4127    for b in recovered.clone()
4128        { print!("{:02X} ", b); }
4129    println!();
4130    let mut txt = String::new();
4131    for c in recovered.clone()
4132        { write!(txt, "{:02X} ", c); }
4133    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4134
4135    let mut converted = String::new();
4136    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4137    converted.truncate(len as usize);
4138    
4139    println!("Bb =\t{}", converted);
4140    assert_eq!(converted, "");
4141    assert_eq!(converted, message);
4142    println!();
4143
4144    // Normal case for the message shorter than 8 bytes
4145    let key = 0x_1234567890ABCDEF_u64;
4146    println!("K =\t{:#016X}", key);
4147    let mut a_des = DES::new_with_key_u64(key);
4148
4149    let message = "7 bytes";
4150    println!("M =\t{}", message);
4151    let mut cipher = Vec::<u8>::new();
4152    a_des.encrypt_str_into_vec(&message, &mut cipher);
4153    print!("C =\t");
4154    for c in cipher.clone()
4155        { print!("{:02X} ", c); }
4156    println!();
4157    let mut txt = String::new();
4158    for c in cipher.clone()
4159        { write!(txt, "{:02X} ", c); }
4160    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4161    
4162    let mut recovered = vec![0; 8];
4163    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4164    print!("Ba =\t");
4165    for b in recovered.clone()
4166        { print!("{:02X} ", b); }
4167    println!();
4168    let mut txt = String::new();
4169    for c in recovered.clone()
4170        { write!(txt, "{:02X} ", c); }
4171    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4172
4173    let mut converted = String::new();
4174    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4175    converted.truncate(len as usize);
4176
4177    println!("Bb =\t{}", converted);
4178    assert_eq!(converted, "7 bytes");
4179    assert_eq!(converted, message);
4180    println!();
4181
4182    // Normal case for the message of 8 bytes
4183    let key = 0x_1234567890ABCDEF_u64;
4184    println!("K =\t{:#016X}", key);
4185    let mut a_des = DES::new_with_key_u64(key);
4186
4187    let message = "I am OK.";
4188    println!("M =\t{}", message);
4189    let mut cipher = Vec::<u8>::new();
4190    a_des.encrypt_str_into_vec(&message, &mut cipher);
4191    print!("C =\t");
4192    for c in cipher.clone()
4193        { print!("{:02X} ", c); }
4194    println!();
4195    let mut txt = String::new();
4196    for c in cipher.clone()
4197        { write!(txt, "{:02X} ", c); }
4198    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4199    
4200    let mut recovered = vec![0; 16];
4201    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4202    print!("Ba =\t");
4203    for b in recovered.clone()
4204        { print!("{:02X} ", b); }
4205    println!();
4206    let mut txt = String::new();
4207    for c in recovered.clone()
4208        { write!(txt, "{:02X} ", c); }
4209    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4210
4211    let mut converted = String::new();
4212    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4213    converted.truncate(len as usize);
4214    
4215    println!("Bb =\t{}", converted);
4216    assert_eq!(converted, "I am OK.");
4217    assert_eq!(converted, message);
4218    println!();
4219
4220    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4221    let key = 0x_1234567890ABCDEF_u64;
4222    println!("K =\t{:#016X}", key);
4223    let mut a_des = DES::new_with_key_u64(key);
4224
4225    let message = "PARK Youngho";
4226    println!("M =\t{}", message);
4227    let mut cipher = Vec::<u8>::new();
4228    a_des.encrypt_str_into_vec(&message, &mut cipher);
4229    print!("C =\t");
4230    for c in cipher.clone()
4231        { print!("{:02X} ", c); }
4232    println!();
4233    let mut txt = String::new();
4234    for c in cipher.clone()
4235        { write!(txt, "{:02X} ", c); }
4236    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4237
4238    let mut recovered = vec![0; 16];
4239    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4240    print!("Ba =\t");
4241    for b in recovered.clone()
4242        { print!("{:02X} ", b); }
4243    println!();
4244    let mut txt = String::new();
4245    for c in recovered.clone()
4246        { write!(txt, "{:02X} ", c); }
4247    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4248
4249    let mut converted = String::new();
4250    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4251    converted.truncate(len as usize);
4252    
4253    println!("Bb =\t{}", converted);
4254    assert_eq!(converted, "PARK Youngho");
4255    assert_eq!(converted, message);
4256    println!();
4257
4258    // Normal case for the message of 16 bytes
4259    let key = 0x_1234567890ABCDEF_u64;
4260    println!("K =\t{:#016X}", key);
4261    let mut a_des = DES::new_with_key_u64(key);
4262
4263    let message = "고맙습니다.";
4264    println!("M =\t{}", message);
4265    let mut cipher = Vec::<u8>::new();
4266    a_des.encrypt_str_into_vec(&message, &mut cipher);
4267    print!("C =\t");
4268    for c in cipher.clone()
4269        { print!("{:02X} ", c); }
4270    println!();
4271    let mut txt = String::new();
4272    for c in cipher.clone()
4273        { write!(txt, "{:02X} ", c); }
4274    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4275
4276    let mut recovered = vec![0; 24];
4277    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4278    print!("Ba =\t");
4279    for b in recovered.clone()
4280        { print!("{:02X} ", b); }
4281    println!();
4282    let mut txt = String::new();
4283    for c in recovered.clone()
4284        { write!(txt, "{:02X} ", c); }
4285    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4286
4287    let mut converted = String::new();
4288    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4289    converted.truncate(len as usize);
4290    
4291    println!("Bb =\t{}", converted);
4292    assert_eq!(converted, "고맙습니다.");
4293    assert_eq!(converted, message);
4294    println!("-------------------------------");
4295}
4296
4297fn des_decrypt_vec_with_padding_iso_ecb_into_vec()
4298{
4299    println!("des_decrypt_vec_with_padding_iso_ecb_into_vec()");
4300    use std::io::Write;
4301    use std::fmt::Write as _;
4302    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4303
4304    // Normal case
4305    let key = 0x_1234567890ABCDEF_u64;
4306    println!("K =\t{:#016X}", key);
4307    let mut a_des = DES::new_with_key_u64(key);
4308
4309    let message = "In the beginning God created the heavens and the earth.";
4310    println!("M =\t{}", message);
4311    let mut cipher = Vec::<u8>::new();
4312    a_des.encrypt_str_into_vec(&message, &mut cipher);
4313    print!("C (16 rounds) =\t");
4314    for c in cipher.clone()
4315        { print!("{:02X} ", c); }
4316    println!();
4317    let mut txt = String::new();
4318    for c in cipher.clone()
4319        { write!(txt, "{:02X} ", c); }
4320    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4321
4322    let mut recovered = Vec::<u8>::new();
4323    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4324    print!("Ba (16 rounds) =\t");
4325    for b in recovered.clone()
4326        { print!("{:02X} ", b); }
4327    println!();
4328    let mut txt = String::new();
4329    for c in recovered.clone()
4330        { write!(txt, "{:02X} ", c); }
4331    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4332
4333    let mut converted = String::new();
4334    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4335    
4336    println!("Bb (16 rounds) =\t{}", converted);
4337    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4338    assert_eq!(converted, message);
4339    println!();
4340
4341    // Expanded case for 128 rounds
4342    let key = 0x_1234567890ABCDEF_u64;
4343    println!("K =\t{:#016X}", key);
4344    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4345
4346    let message = "In the beginning God created the heavens and the earth.";
4347    println!("M =\t{}", message);
4348    let mut cipher = Vec::<u8>::new();
4349    a_des.encrypt_str_into_vec(&message, &mut cipher);
4350    print!("C (128 rounds) =\t");
4351    for c in cipher.clone()
4352        { print!("{:02X} ", c); }
4353    println!();
4354    let mut txt = String::new();
4355    for c in cipher.clone()
4356        { write!(txt, "{:02X} ", c); }
4357    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4358
4359    let mut recovered = Vec::<u8>::new();
4360    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4361    print!("Ba (128 rounds) =\t");
4362    for b in recovered.clone()
4363        { print!("{:02X} ", b); }
4364    println!();
4365    let mut txt = String::new();
4366    for c in recovered.clone()
4367        { write!(txt, "{:02X} ", c); }
4368    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4369
4370    let mut converted = String::new();
4371    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4372    
4373    println!("Bb (128 rounds) =\t{}", converted);
4374    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4375    assert_eq!(converted, message);
4376    println!();
4377
4378    // Expanded case for 0 rounds which means that key is meaningless
4379    let key1 = 0x_1234567890ABCDEF_u64;
4380    let key2 = 0_u64;
4381    println!("K =\t{:#016X}", key);
4382    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4383    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4384
4385    let message = "In the beginning God created the heavens and the earth.";
4386    println!("M =\t{}", message);
4387    let mut cipher1 = Vec::<u8>::new();
4388    let mut cipher2 = Vec::<u8>::new();
4389    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4390    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4391    print!("C (0 rounds) =\t");
4392    for c in cipher1.clone()
4393        { print!("{:02X} ", c); }
4394    println!();
4395    let mut txt = String::new();
4396    for c in cipher1.clone()
4397        { write!(txt, "{:02X} ", c); }
4398    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4399    print!("D (0 rounds) =\t");
4400    for c in cipher2.clone()
4401        { print!("{:02X} ", c); }
4402    println!();
4403    let mut txt = String::new();
4404    for c in cipher2.clone()
4405        { write!(txt, "{:02X} ", c); }
4406    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4407
4408    let mut recovered1 = Vec::<u8>::new();
4409    let mut recovered2 = Vec::<u8>::new();
4410    c_des.decrypt_vec_into_vec(&cipher1, &mut recovered1);
4411    d_des.decrypt_vec_into_vec(&cipher2, &mut recovered2);
4412    print!("B1a (0 rounds) =\t");
4413    for b in recovered1.clone()
4414        { print!("{:02X} ", b); }
4415    println!();
4416    let mut txt = String::new();
4417    for c in recovered1.clone()
4418        { write!(txt, "{:02X} ", c); }
4419    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4420    print!("B2a (0 rounds) =\t");
4421    for b in recovered2.clone()
4422        { print!("{:02X} ", b); }
4423    println!();
4424    let mut txt = String::new();
4425    for c in recovered2.clone()
4426        { write!(txt, "{:02X} ", c); }
4427    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4428
4429    let mut converted1 = String::new();
4430    let mut converted2 = String::new();
4431    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4432    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4433    
4434    println!("B1b (0 rounds) =\t{}", converted1);
4435    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4436    assert_eq!(converted1, message);
4437    println!("B2b (0 rounds) =\t{}", converted2);
4438    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4439    assert_eq!(converted2, message);
4440    assert_eq!(converted1, converted1);
4441    println!();
4442
4443    // Normal case for the message of 0 bytes
4444    let key = 0x_1234567890ABCDEF_u64;
4445    println!("K =\t{:#016X}", key);
4446    let mut a_des = DES::new_with_key_u64(key);
4447
4448    let message = "";
4449    println!("M =\t{}", message);
4450    let mut cipher = Vec::<u8>::new();
4451    a_des.encrypt_str_into_vec(&message, &mut cipher);
4452    print!("C =\t");
4453    for c in cipher.clone()
4454        { print!("{:02X} ", c); }
4455    println!();
4456    let mut txt = String::new();
4457    for c in cipher.clone()
4458        { write!(txt, "{:02X} ", c); }
4459    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4460
4461    let mut recovered = Vec::<u8>::new();
4462    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4463    print!("Ba =\t");
4464    for b in recovered.clone()
4465        { print!("{:02X} ", b); }
4466    println!();
4467    let mut txt = String::new();
4468    for c in recovered.clone()
4469        { write!(txt, "{:02X} ", c); }
4470    assert_eq!(txt, "");
4471
4472    let mut converted = String::new();
4473    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4474    
4475    println!("Bb =\t{}", converted);
4476    assert_eq!(converted, "");
4477    assert_eq!(converted, message);
4478    println!();
4479
4480    // Normal case for the message shorter than 8 bytes
4481    let key = 0x_1234567890ABCDEF_u64;
4482    println!("K =\t{:#016X}", key);
4483    let mut a_des = DES::new_with_key_u64(key);
4484
4485    let message = "7 bytes";
4486    println!("M =\t{}", message);
4487    let mut cipher = Vec::<u8>::new();
4488    a_des.encrypt_str_into_vec(&message, &mut cipher);
4489    print!("C =\t");
4490    for c in cipher.clone()
4491        { print!("{:02X} ", c); }
4492    println!();
4493    let mut txt = String::new();
4494    for c in cipher.clone()
4495        { write!(txt, "{:02X} ", c); }
4496    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4497    
4498    let mut recovered = Vec::<u8>::new();
4499    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4500    print!("Ba =\t");
4501    for b in recovered.clone()
4502        { print!("{:02X} ", b); }
4503    println!();
4504    let mut txt = String::new();
4505    for c in recovered.clone()
4506        { write!(txt, "{:02X} ", c); }
4507    assert_eq!(txt, "37 20 62 79 74 65 73 ");
4508
4509    let mut converted = String::new();
4510    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4511    
4512    println!("Bb =\t{}", converted);
4513    assert_eq!(converted, "7 bytes");
4514    assert_eq!(converted, message);
4515    println!();
4516
4517    // Normal case for the message of 8 bytes
4518    let key = 0x_1234567890ABCDEF_u64;
4519    println!("K =\t{:#016X}", key);
4520    let mut a_des = DES::new_with_key_u64(key);
4521
4522    let message = "I am OK.";
4523    println!("M =\t{}", message);
4524    let mut cipher = Vec::<u8>::new();
4525    a_des.encrypt_str_into_vec(&message, &mut cipher);
4526    print!("C =\t");
4527    for c in cipher.clone()
4528        { print!("{:02X} ", c); }
4529    println!();
4530    let mut txt = String::new();
4531    for c in cipher.clone()
4532        { write!(txt, "{:02X} ", c); }
4533    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4534    
4535    let mut recovered = Vec::<u8>::new();
4536    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4537    print!("Ba =\t");
4538    for b in recovered.clone()
4539        { print!("{:02X} ", b); }
4540    println!();
4541    let mut txt = String::new();
4542    for c in recovered.clone()
4543        { write!(txt, "{:02X} ", c); }
4544    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4545
4546    let mut converted = String::new();
4547    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4548    
4549    println!("Bb =\t{}", converted);
4550    assert_eq!(converted, "I am OK.");
4551    assert_eq!(converted, message);
4552    println!();
4553
4554    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4555    let key = 0x_1234567890ABCDEF_u64;
4556    println!("K =\t{:#016X}", key);
4557    let mut a_des = DES::new_with_key_u64(key);
4558
4559    let message = "PARK Youngho";
4560    println!("M =\t{}", message);
4561    let mut cipher = Vec::<u8>::new();
4562    a_des.encrypt_str_into_vec(&message, &mut cipher);
4563    print!("C =\t");
4564    for c in cipher.clone()
4565        { print!("{:02X} ", c); }
4566    println!();
4567    let mut txt = String::new();
4568    for c in cipher.clone()
4569        { write!(txt, "{:02X} ", c); }
4570    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4571
4572    let mut recovered = Vec::<u8>::new();
4573    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4574    print!("Ba =\t");
4575    for b in recovered.clone()
4576        { print!("{:02X} ", b); }
4577    println!();
4578    let mut txt = String::new();
4579    for c in recovered.clone()
4580        { write!(txt, "{:02X} ", c); }
4581    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4582
4583    let mut converted = String::new();
4584    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4585    
4586    println!("Bb =\t{}", converted);
4587    assert_eq!(converted, "PARK Youngho");
4588    assert_eq!(converted, message);
4589    println!();
4590
4591    // Normal case for the message of 16 bytes
4592    let key = 0x_1234567890ABCDEF_u64;
4593    println!("K =\t{:#016X}", key);
4594    let mut a_des = DES::new_with_key_u64(key);
4595
4596    let message = "고맙습니다.";
4597    println!("M =\t{}", message);
4598    let mut cipher = Vec::<u8>::new();
4599    a_des.encrypt_str_into_vec(&message, &mut cipher);
4600    print!("C =\t");
4601    for c in cipher.clone()
4602        { print!("{:02X} ", c); }
4603    println!();
4604    let mut txt = String::new();
4605    for c in cipher.clone()
4606        { write!(txt, "{:02X} ", c); }
4607    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4608
4609    let mut recovered = Vec::<u8>::new();
4610    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4611    print!("Ba =\t");
4612    for b in recovered.clone()
4613        { print!("{:02X} ", b); }
4614    println!();
4615    let mut txt = String::new();
4616    for c in recovered.clone()
4617        { write!(txt, "{:02X} ", c); }
4618    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4619
4620    let mut converted = String::new();
4621    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4622    
4623    println!("Bb =\t{}", converted);
4624    assert_eq!(converted, "고맙습니다.");
4625    assert_eq!(converted, message);
4626    println!("-------------------------------");
4627}
4628
4629fn des_decrypt_vec_with_padding_iso_ecb_into_array()
4630{
4631    println!("des_decrypt_vec_with_padding_iso_ecb_into_array()");
4632    use std::io::Write;
4633    use std::fmt::Write as _;
4634    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4635
4636    // Normal case
4637    let key = 0x_1234567890ABCDEF_u64;
4638    println!("K =\t{:#016X}", key);
4639    let mut a_des = DES::new_with_key_u64(key);
4640
4641    let message = "In the beginning God created the heavens and the earth.";
4642    println!("M =\t{}", message);
4643    let mut cipher = Vec::<u8>::new();
4644    a_des.encrypt_str_into_vec(&message, &mut cipher);
4645    print!("C (16 rounds) =\t");
4646    for c in cipher.clone()
4647        { print!("{:02X} ", c); }
4648    println!();
4649    let mut txt = String::new();
4650    for c in cipher.clone()
4651        { write!(txt, "{:02X} ", c); }
4652    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4653
4654    let mut recovered = [0u8; 56];
4655    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4656    print!("Ba (16 rounds) =\t");
4657    for b in recovered.clone()
4658        { print!("{:02X} ", b); }
4659    println!();
4660    let mut txt = String::new();
4661    for c in recovered.clone()
4662        { write!(txt, "{:02X} ", c); }
4663    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4664
4665    let mut converted = String::new();
4666    unsafe { converted.as_mut_vec() }.write(&recovered);
4667    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4668    println!("Bb (16 rounds) =\t{}", converted);
4669    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4670    assert_eq!(converted, message);
4671    println!();
4672
4673    // Expanded case for 128 rounds
4674    let key = 0x_1234567890ABCDEF_u64;
4675    println!("K =\t{:#016X}", key);
4676    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4677
4678    let message = "In the beginning God created the heavens and the earth.";
4679    println!("M =\t{}", message);
4680    let mut cipher = Vec::<u8>::new();
4681    a_des.encrypt_str_into_vec(&message, &mut cipher);
4682    print!("C (128 rounds) =\t");
4683    for c in cipher.clone()
4684        { print!("{:02X} ", c); }
4685    println!();
4686    let mut txt = String::new();
4687    for c in cipher.clone()
4688        { write!(txt, "{:02X} ", c); }
4689    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4690
4691    let mut recovered = [0u8; 56];
4692    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4693    print!("Ba (16 rounds) =\t");
4694    for b in recovered.clone()
4695        { print!("{:02X} ", b); }
4696    println!();
4697    let mut txt = String::new();
4698    for c in recovered.clone()
4699        { write!(txt, "{:02X} ", c); }
4700    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4701
4702    let mut converted = String::new();
4703    unsafe { converted.as_mut_vec() }.write(&recovered);
4704    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4705    println!("Bb (16 rounds) =\t{}", converted);
4706    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4707    assert_eq!(converted, message);
4708    println!();
4709
4710    // Expanded case for 0 rounds which means that key is meaningless
4711    let key1 = 0x_1234567890ABCDEF_u64;
4712    let key2 = 0_u64;
4713    println!("K =\t{:#016X}", key);
4714    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4715    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4716
4717    let message = "In the beginning God created the heavens and the earth.";
4718    println!("M =\t{}", message);
4719    let mut cipher1 = Vec::<u8>::new();
4720    let mut cipher2 = Vec::<u8>::new();
4721    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4722    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4723    print!("C (0 rounds) =\t");
4724    for c in cipher1.clone()
4725        { print!("{:02X} ", c); }
4726    println!();
4727    let mut txt = String::new();
4728    for c in cipher1.clone()
4729        { write!(txt, "{:02X} ", c); }
4730    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4731    print!("D (0 rounds) =\t");
4732    for c in cipher2.clone()
4733        { print!("{:02X} ", c); }
4734    println!();
4735    let mut txt = String::new();
4736    for c in cipher2.clone()
4737        { write!(txt, "{:02X} ", c); }
4738    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4739
4740    let mut recovered1 = [0u8; 56];
4741    let mut recovered2 = [0u8; 56];
4742    let len1 = c_des.decrypt_vec_into_array(&cipher1, &mut recovered1);
4743    let len2 = d_des.decrypt_vec_into_array(&cipher2, &mut recovered2);
4744    print!("B1a (0 rounds) =\t");
4745    for b in recovered1.clone()
4746        { print!("{:02X} ", b); }
4747    println!();
4748    let mut txt = String::new();
4749    for c in recovered1.clone()
4750        { write!(txt, "{:02X} ", c); }
4751    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4752    print!("B2a (0 rounds) =\t");
4753    for b in recovered2.clone()
4754        { print!("{:02X} ", b); }
4755    println!();
4756    let mut txt = String::new();
4757    for c in recovered.clone()
4758        { write!(txt, "{:02X} ", c); }
4759    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4760
4761    let mut converted1 = String::new();
4762    let mut converted2 = String::new();
4763    unsafe { converted1.as_mut_vec() }.write(&recovered1);
4764    unsafe { converted2.as_mut_vec() }.write(&recovered2);
4765    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
4766    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
4767    println!("B1b (0 rounds) =\t{}", converted1);
4768    println!("B2b (0 rounds) =\t{}", converted2);
4769    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4770    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4771    assert_eq!(converted1, message);
4772    assert_eq!(converted2, message);
4773    assert_eq!(converted1, converted2);
4774    println!();
4775
4776    // Normal case for the message of 0 bytes
4777    let key = 0x_1234567890ABCDEF_u64;
4778    println!("K =\t{:#016X}", key);
4779    let mut a_des = DES::new_with_key_u64(key);
4780
4781    let message = "";
4782    println!("M =\t{}", message);
4783    let mut cipher = Vec::<u8>::new();
4784    a_des.encrypt_str_into_vec(&message, &mut cipher);
4785    print!("C =\t");
4786    for c in cipher.clone()
4787        { print!("{:02X} ", c); }
4788    println!();
4789    let mut txt = String::new();
4790    for c in cipher.clone()
4791        { write!(txt, "{:02X} ", c); }
4792    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4793
4794    let mut recovered = [0u8; 8];
4795    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4796
4797    print!("Ba =\t");
4798    for b in recovered.clone()
4799        { print!("{:02X} ", b); }
4800    println!();
4801    let mut txt = String::new();
4802    for c in recovered.clone()
4803        { write!(txt, "{:02X} ", c); }
4804    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4805
4806    let mut converted = String::new();
4807    unsafe { converted.as_mut_vec() }.write(&recovered);
4808    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4809    println!("Bb =\t{}", converted);
4810    assert_eq!(converted, "");
4811    assert_eq!(converted, message);
4812    println!();
4813
4814    // Normal case for the message shorter than 8 bytes
4815    let key = 0x_1234567890ABCDEF_u64;
4816    println!("K =\t{:#016X}", key);
4817    let mut a_des = DES::new_with_key_u64(key);
4818
4819    let message = "7 bytes";
4820    println!("M =\t{}", message);
4821    let mut cipher = Vec::<u8>::new();
4822    a_des.encrypt_str_into_vec(&message, &mut cipher);
4823    print!("C =\t");
4824    for c in cipher.clone()
4825        { print!("{:02X} ", c); }
4826    println!();
4827    let mut txt = String::new();
4828    for c in cipher.clone()
4829        { write!(txt, "{:02X} ", c); }
4830    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4831
4832    let mut recovered = [0u8; 8];
4833    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4834
4835    print!("Ba =\t");
4836    for b in recovered.clone()
4837        { print!("{:02X} ", b); }
4838    println!();
4839    let mut txt = String::new();
4840    for c in recovered.clone()
4841        { write!(txt, "{:02X} ", c); }
4842    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4843
4844    let mut converted = String::new();
4845    unsafe { converted.as_mut_vec() }.write(&recovered);
4846    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4847    println!("Bb =\t{}", converted);
4848    assert_eq!(converted, "7 bytes");
4849    assert_eq!(converted, message);
4850    println!();
4851
4852    // Normal case for the message of 8 bytes
4853    let key = 0x_1234567890ABCDEF_u64;
4854    println!("K =\t{:#016X}", key);
4855    let mut a_des = DES::new_with_key_u64(key);
4856
4857    let message = "I am OK.";
4858    println!("M =\t{}", message);
4859    let mut cipher = Vec::<u8>::new();
4860    a_des.encrypt_str_into_vec(&message, &mut cipher);
4861    print!("C =\t");
4862    for c in cipher.clone()
4863        { print!("{:02X} ", c); }
4864    println!();
4865    let mut txt = String::new();
4866    for c in cipher.clone()
4867        { write!(txt, "{:02X} ", c); }
4868    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4869
4870    let mut recovered = [0u8; 16];
4871    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4872
4873    print!("Ba =\t");
4874    for b in recovered.clone()
4875        { print!("{:02X} ", b); }
4876    println!();
4877    let mut txt = String::new();
4878    for c in recovered.clone()
4879        { write!(txt, "{:02X} ", c); }
4880    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4881
4882    let mut converted = String::new();
4883    unsafe { converted.as_mut_vec() }.write(&recovered);
4884    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4885    println!("Bb =\t{}", converted);
4886    assert_eq!(converted, "I am OK.");
4887    assert_eq!(converted, message);
4888    println!();
4889
4890    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4891    let key = 0x_1234567890ABCDEF_u64;
4892    println!("K =\t{:#016X}", key);
4893    let mut a_des = DES::new_with_key_u64(key);
4894
4895    let message = "PARK Youngho";
4896    println!("M =\t{}", message);
4897    let mut cipher = Vec::<u8>::new();
4898    a_des.encrypt_str_into_vec(&message, &mut cipher);
4899    print!("C =\t");
4900    for c in cipher.clone()
4901        { print!("{:02X} ", c); }
4902    println!();
4903    let mut txt = String::new();
4904    for c in cipher.clone()
4905        { write!(txt, "{:02X} ", c); }
4906    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4907
4908    let mut recovered = [0u8; 16];
4909    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4910
4911    print!("Ba =\t");
4912    for b in recovered.clone()
4913        { print!("{:02X} ", b); }
4914    println!();
4915    let mut txt = String::new();
4916    for c in recovered.clone()
4917        { write!(txt, "{:02X} ", c); }
4918    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4919
4920    let mut converted = String::new();
4921    unsafe { converted.as_mut_vec() }.write(&recovered);
4922    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4923    println!("Bb =\t{}", converted);
4924    assert_eq!(converted, "PARK Youngho");
4925    assert_eq!(converted, message);
4926    println!();
4927
4928    // Normal case for the message of 16 bytes
4929    let key = 0x_1234567890ABCDEF_u64;
4930    println!("K =\t{:#016X}", key);
4931    let mut a_des = DES::new_with_key_u64(key);
4932
4933    let message = "고맙습니다.";
4934    println!("M =\t{}", message);
4935    let mut cipher = Vec::<u8>::new();
4936    a_des.encrypt_str_into_vec(&message, &mut cipher);
4937    print!("C =\t");
4938    for c in cipher.clone()
4939        { print!("{:02X} ", c); }
4940    println!();
4941    let mut txt = String::new();
4942    for c in cipher.clone()
4943        { write!(txt, "{:02X} ", c); }
4944    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4945
4946    let mut recovered = [0u8; 24];
4947    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4948
4949    print!("Ba =\t");
4950    for b in recovered.clone()
4951        { print!("{:02X} ", b); }
4952    println!();
4953    let mut txt = String::new();
4954    for c in recovered.clone()
4955        { write!(txt, "{:02X} ", c); }
4956    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4957
4958    let mut converted = String::new();
4959    unsafe { converted.as_mut_vec() }.write(&recovered);
4960    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4961    println!("Bb =\t{}", converted);
4962    assert_eq!(converted, "고맙습니다.");
4963    assert_eq!(converted, message);
4964    println!("-------------------------------");
4965}
4966
4967fn des_decrypt_vec_with_padding_iso_ecb_into_string()
4968{
4969    println!("des_decrypt_vec_with_padding_iso_ecb_into_string()");
4970    use std::io::Write;
4971    use std::fmt::Write as _;
4972    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4973
4974    // Normal case
4975    let key = 0x_1234567890ABCDEF_u64;
4976    println!("K =\t{:#016X}", key);
4977    let mut a_des = DES::new_with_key_u64(key);
4978
4979    let message = "In the beginning God created the heavens and the earth.";
4980    println!("M =\t{}", message);
4981    let mut cipher = Vec::<u8>::new();
4982    a_des.encrypt_str_into_vec(&message, &mut cipher);
4983    print!("C (16 rounds) =\t");
4984    for c in cipher.clone()
4985        { print!("{:02X} ", c); }
4986    println!();
4987    let mut txt = String::new();
4988    for c in cipher.clone()
4989        { write!(txt, "{:02X} ", c); }
4990    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4991
4992    let mut recovered = String::new();
4993    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
4994    println!("B (16 rounds) =\t{}", recovered);
4995    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4996    assert_eq!(recovered, message);
4997    println!();
4998
4999    // Expanded case for 128 rounds
5000    let key = 0x_1234567890ABCDEF_u64;
5001    println!("K =\t{:#016X}", key);
5002    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5003
5004    let message = "In the beginning God created the heavens and the earth.";
5005    println!("M =\t{}", message);
5006    let mut cipher = Vec::<u8>::new();
5007    a_des.encrypt_str_into_vec(&message, &mut cipher);
5008    print!("C (128 rounds) =\t");
5009    for c in cipher.clone()
5010        { print!("{:02X} ", c); }
5011    println!();
5012    let mut txt = String::new();
5013    for c in cipher.clone()
5014        { write!(txt, "{:02X} ", c); }
5015    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5016
5017    let mut recovered = String::new();
5018    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5019    println!("B (128 rounds) =\t{}", recovered);
5020    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5021    assert_eq!(recovered, message);
5022    println!();
5023
5024    // Expanded case for 0 rounds which means that key is meaningless
5025    let key1 = 0x_1234567890ABCDEF_u64;
5026    let key2 = 0_u64;
5027    println!("K =\t{:#016X}", key);
5028    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5029    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5030
5031    let message = "In the beginning God created the heavens and the earth.";
5032    println!("M =\t{}", message);
5033    let mut cipher1 = Vec::<u8>::new();
5034    let mut cipher2 = Vec::<u8>::new();
5035    c_des.encrypt_str_into_vec(&message, &mut cipher1);
5036    d_des.encrypt_str_into_vec(&message, &mut cipher2);
5037    print!("C (0 rounds) =\t");
5038    for c in cipher1.clone()
5039        { print!("{:02X} ", c); }
5040    println!();
5041    let mut txt = String::new();
5042    for c in cipher1.clone()
5043        { write!(txt, "{:02X} ", c); }
5044    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5045    print!("D (0 rounds) =\t");
5046    for c in cipher2.clone()
5047        { print!("{:02X} ", c); }
5048    println!();
5049    let mut txt = String::new();
5050    for c in cipher2.clone()
5051        { write!(txt, "{:02X} ", c); }
5052    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5053
5054    let mut recovered1 = String::new();
5055    let mut recovered2 = String::new();
5056    c_des.decrypt_vec_into_string(&cipher1, &mut recovered1);
5057    d_des.decrypt_vec_into_string(&cipher2, &mut recovered2);
5058    println!("B1 (0 rounds) =\t{}", recovered1);
5059    println!("B2 (0 rounds) =\t{}", recovered2);
5060    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5061    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5062    assert_eq!(recovered1, message);
5063    assert_eq!(recovered2, message);
5064    assert_eq!(recovered1, recovered2);
5065    println!();
5066
5067    // Normal case for the message of 0 bytes
5068    let key = 0x_1234567890ABCDEF_u64;
5069    println!("K =\t{:#016X}", key);
5070    let mut a_des = DES::new_with_key_u64(key);
5071
5072    let message = "";
5073    println!("M =\t{}", message);
5074    let mut cipher = Vec::<u8>::new();
5075    a_des.encrypt_str_into_vec(&message, &mut cipher);
5076    print!("C =\t");
5077    for c in cipher.clone()
5078        { print!("{:02X} ", c); }
5079    println!();
5080    let mut txt = String::new();
5081    for c in cipher.clone()
5082        { write!(txt, "{:02X} ", c); }
5083    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5084
5085    let mut recovered = String::new();
5086    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5087    println!("B =\t{}", recovered);
5088    assert_eq!(recovered, "");
5089    assert_eq!(recovered, message);
5090    println!();
5091
5092    // Normal case for the message shorter than 8 bytes
5093    let key = 0x_1234567890ABCDEF_u64;
5094    println!("K =\t{:#016X}", key);
5095    let mut a_des = DES::new_with_key_u64(key);
5096
5097    let message = "7 bytes";
5098    println!("M =\t{}", message);
5099    let mut cipher = Vec::<u8>::new();
5100    a_des.encrypt_str_into_vec(&message, &mut cipher);
5101    print!("C =\t");
5102    for c in cipher.clone()
5103        { print!("{:02X} ", c); }
5104    println!();
5105    let mut txt = String::new();
5106    for c in cipher.clone()
5107        { write!(txt, "{:02X} ", c); }
5108    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5109
5110    let mut recovered = String::new();
5111    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5112    println!("B =\t{}", recovered);
5113    assert_eq!(recovered, "7 bytes");
5114    assert_eq!(recovered, message);
5115    println!();
5116
5117    // Normal case for the message of 8 bytes
5118    let key = 0x_1234567890ABCDEF_u64;
5119    println!("K =\t{:#016X}", key);
5120    let mut a_des = DES::new_with_key_u64(key);
5121
5122    let message = "I am OK.";
5123    println!("M =\t{}", message);
5124    let mut cipher = Vec::<u8>::new();
5125    a_des.encrypt_str_into_vec(&message, &mut cipher);
5126    print!("C =\t");
5127    for c in cipher.clone()
5128        { print!("{:02X} ", c); }
5129    println!();
5130    let mut txt = String::new();
5131    for c in cipher.clone()
5132        { write!(txt, "{:02X} ", c); }
5133    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5134
5135    let mut recovered = String::new();
5136    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5137    println!("B =\t{}", recovered);
5138    assert_eq!(recovered, "I am OK.");
5139    assert_eq!(recovered, message);
5140    println!();
5141
5142    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5143    let key = 0x_1234567890ABCDEF_u64;
5144    println!("K =\t{:#016X}", key);
5145    let mut a_des = DES::new_with_key_u64(key);
5146
5147    let message = "PARK Youngho";
5148    println!("M =\t{}", message);
5149    let mut cipher = Vec::<u8>::new();
5150    a_des.encrypt_str_into_vec(&message, &mut cipher);
5151    print!("C =\t");
5152    for c in cipher.clone()
5153        { print!("{:02X} ", c); }
5154    println!();
5155    let mut txt = String::new();
5156    for c in cipher.clone()
5157        { write!(txt, "{:02X} ", c); }
5158    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5159
5160    let mut recovered = String::new();
5161    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5162    println!("B =\t{}", recovered);
5163    assert_eq!(recovered, "PARK Youngho");
5164    assert_eq!(recovered, message);
5165    println!();
5166
5167    // Normal case for the message of 16 bytes
5168    let key = 0x_1234567890ABCDEF_u64;
5169    println!("K =\t{:#016X}", key);
5170    let mut a_des = DES::new_with_key_u64(key);
5171
5172    let message = "고맙습니다.";
5173    println!("M =\t{}", message);
5174    let mut cipher = Vec::<u8>::new();
5175    a_des.encrypt_str_into_vec(&message, &mut cipher);
5176    print!("C =\t");
5177    for c in cipher.clone()
5178        { print!("{:02X} ", c); }
5179    println!();
5180    let mut txt = String::new();
5181    for c in cipher.clone()
5182        { write!(txt, "{:02X} ", c); }
5183    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5184
5185    let mut recovered = String::new();
5186    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5187    println!("B =\t{}", recovered);
5188    assert_eq!(recovered, "고맙습니다.");
5189    assert_eq!(recovered, message);
5190    println!("-------------------------------");
5191}
5192
5193fn des_decrypt_array_with_padding_iso_ecb()
5194{
5195    println!("des_decrypt_array_with_padding_iso_ecb()");
5196    use std::io::Write;
5197    use std::fmt::Write as _;
5198    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5199
5200    // Normal case
5201    let key = 0x_1234567890ABCDEF_u64;
5202    println!("K =\t{:#016X}", key);
5203    let mut a_des = DES::new_with_key_u64(key);
5204
5205    let message = "In the beginning God created the heavens and the earth.";
5206    println!("M =\t{}", message);
5207    let mut cipher = [0_u8; 56];
5208    a_des.encrypt_str_into_array(&message, &mut cipher);
5209    print!("C (16 rounds) =\t");
5210    for c in cipher.clone()
5211        { print!("{:02X} ", c); }
5212    println!();
5213    let mut txt = String::new();
5214    for c in cipher.clone()
5215        { write!(txt, "{:02X} ", c); }
5216    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5217
5218    let mut recovered = vec![0; 55];
5219    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5220    recovered.truncate(len as usize);
5221    print!("Ba (16 rounds) =\t");
5222    for b in recovered.clone()
5223        { print!("{:02X} ", b); }
5224    println!();
5225    let mut txt = String::new();
5226    for c in recovered.clone()
5227        { write!(txt, "{:02X} ", c); }
5228    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5229
5230    let mut converted = String::new();
5231    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5232    
5233    println!("Bb (16 rounds) =\t{}", converted);
5234    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5235    assert_eq!(converted, message);
5236    println!();
5237
5238    // Expanded case for 128 rounds
5239    let key = 0x_1234567890ABCDEF_u64;
5240    println!("K =\t{:#016X}", key);
5241    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5242
5243    let message = "In the beginning God created the heavens and the earth.";
5244    println!("M =\t{}", message);
5245    let mut cipher = [0_u8; 56];
5246    a_des.encrypt_str_into_array(&message, &mut cipher);
5247    print!("C (128 rounds) =\t");
5248    for c in cipher.clone()
5249        { print!("{:02X} ", c); }
5250    println!();
5251    let mut txt = String::new();
5252    for c in cipher.clone()
5253        { write!(txt, "{:02X} ", c); }
5254    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5255
5256    let mut recovered = vec![0; 55];
5257    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5258    recovered.truncate(len as usize);
5259    print!("Ba (128 rounds) =\t");
5260    for b in recovered.clone()
5261        { print!("{:02X} ", b); }
5262    println!();
5263    let mut txt = String::new();
5264    for c in recovered.clone()
5265        { write!(txt, "{:02X} ", c); }
5266    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5267
5268    let mut converted = String::new();
5269    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5270
5271    println!("Bb (128 rounds) =\t{}", converted);
5272    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5273    assert_eq!(converted, message);
5274    println!();
5275
5276    // Expanded case for 0 rounds which means that key is meaningless
5277    let key1 = 0x_1234567890ABCDEF_u64;
5278    let key2 = 0_u64;
5279    println!("K =\t{:#016X}", key);
5280    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5281    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5282
5283    let message = "In the beginning God created the heavens and the earth.";
5284    println!("M =\t{}", message);
5285    let mut cipher1 = [0_u8; 56];
5286    let mut cipher2 = [0_u8; 56];
5287    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5288    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5289    print!("C (0 rounds) =\t");
5290    for c in cipher1.clone()
5291        { print!("{:02X} ", c); }
5292    println!();
5293    let mut txt = String::new();
5294    for c in cipher1.clone()
5295        { write!(txt, "{:02X} ", c); }
5296    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5297    print!("D (0 rounds) =\t");
5298    for c in cipher2.clone()
5299        { print!("{:02X} ", c); }
5300    println!();
5301    let mut txt = String::new();
5302    for c in cipher2.clone()
5303        { write!(txt, "{:02X} ", c); }
5304    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5305
5306    let mut recovered1 = vec![0; 55];
5307    let mut recovered2 = vec![0; 55];
5308    let len1 = c_des.decrypt_array(&cipher1, recovered1.as_mut_ptr());
5309    let len2 = d_des.decrypt_array(&cipher2, recovered2.as_mut_ptr());
5310    recovered1.truncate(len1 as usize);
5311    recovered2.truncate(len2 as usize);
5312
5313    print!("B1a (0 rounds) =\t");
5314    for b in recovered1.clone()
5315        { print!("{:02X} ", b); }
5316    println!();
5317    let mut txt = String::new();
5318    for c in recovered1.clone()
5319        { write!(txt, "{:02X} ", c); }
5320    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5321    print!("B2a (0 rounds) =\t");
5322    for b in recovered2.clone()
5323        { print!("{:02X} ", b); }
5324    println!();
5325    let mut txt = String::new();
5326    for c in recovered2.clone()
5327        { write!(txt, "{:02X} ", c); }
5328    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5329
5330    let mut converted1 = String::new();
5331    let mut converted2 = String::new();
5332    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5333    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5334    
5335    println!("B1b (0 rounds) =\t{}", converted1);
5336    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5337    assert_eq!(converted1, message);
5338    println!("B2b (0 rounds) =\t{}", converted2);
5339    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5340    assert_eq!(converted2, message);
5341    assert_eq!(converted1, converted1);
5342    println!();
5343
5344    // Normal case for the message of 0 bytes
5345    let key = 0x_1234567890ABCDEF_u64;
5346    println!("K =\t{:#016X}", key);
5347    let mut a_des = DES::new_with_key_u64(key);
5348
5349    let message = "";
5350    println!("M =\t{}", message);
5351    let mut cipher = [0_u8; 8];
5352    a_des.encrypt_str_into_array(&message, &mut cipher);
5353    print!("C =\t");
5354    for c in cipher.clone()
5355        { print!("{:02X} ", c); }
5356    println!();
5357    let mut txt = String::new();
5358    for c in cipher.clone()
5359        { write!(txt, "{:02X} ", c); }
5360    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5361
5362    let mut recovered = vec![0; 8];
5363    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5364    recovered.truncate(len as usize);
5365
5366    print!("Ba =\t");
5367    for b in recovered.clone()
5368        { print!("{:02X} ", b); }
5369    println!();
5370    let mut txt = String::new();
5371    for c in recovered.clone()
5372        { write!(txt, "{:02X} ", c); }
5373    assert_eq!(txt, "");
5374
5375    let mut converted = String::new();
5376    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5377    
5378    println!("Bb =\t{}", converted);
5379    assert_eq!(converted, "");
5380    assert_eq!(converted, message);
5381    println!();
5382
5383    // Normal case for the message shorter than 8 bytes
5384    let key = 0x_1234567890ABCDEF_u64;
5385    println!("K =\t{:#016X}", key);
5386    let mut a_des = DES::new_with_key_u64(key);
5387
5388    let message = "7 bytes";
5389    println!("M =\t{}", message);
5390    let mut cipher = [0_u8; 8];
5391    a_des.encrypt_str_into_array(&message, &mut cipher);
5392    print!("C =\t");
5393    for c in cipher.clone()
5394        { print!("{:02X} ", c); }
5395    println!();
5396    let mut txt = String::new();
5397    for c in cipher.clone()
5398        { write!(txt, "{:02X} ", c); }
5399    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5400    
5401    let mut recovered = vec![0; 8];
5402    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5403    recovered.truncate(len as usize);
5404
5405    print!("Ba =\t");
5406    for b in recovered.clone()
5407        { print!("{:02X} ", b); }
5408    println!();
5409    let mut txt = String::new();
5410    for c in recovered.clone()
5411        { write!(txt, "{:02X} ", c); }
5412    assert_eq!(txt, "37 20 62 79 74 65 73 ");
5413
5414    let mut converted = String::new();
5415    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5416
5417    println!("Bb =\t{}", converted);
5418    assert_eq!(converted, "7 bytes");
5419    assert_eq!(converted, message);
5420    println!();
5421
5422    // Normal case for the message of 8 bytes
5423    let key = 0x_1234567890ABCDEF_u64;
5424    println!("K =\t{:#016X}", key);
5425    let mut a_des = DES::new_with_key_u64(key);
5426
5427    let message = "I am OK.";
5428    println!("M =\t{}", message);
5429    let mut cipher = [0_u8; 16];
5430    a_des.encrypt_str_into_array(&message, &mut cipher);
5431    print!("C =\t");
5432    for c in cipher.clone()
5433        { print!("{:02X} ", c); }
5434    println!();
5435    let mut txt = String::new();
5436    for c in cipher.clone()
5437        { write!(txt, "{:02X} ", c); }
5438    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5439    
5440    let mut recovered = vec![0; 16];
5441    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5442    recovered.truncate(len as usize);
5443
5444    print!("Ba =\t");
5445    for b in recovered.clone()
5446        { print!("{:02X} ", b); }
5447    println!();
5448    let mut txt = String::new();
5449    for c in recovered.clone()
5450        { write!(txt, "{:02X} ", c); }
5451    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5452
5453    let mut converted = String::new();
5454    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5455    
5456    println!("Bb =\t{}", converted);
5457    assert_eq!(converted, "I am OK.");
5458    assert_eq!(converted, message);
5459    println!();
5460
5461    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5462    let key = 0x_1234567890ABCDEF_u64;
5463    println!("K =\t{:#016X}", key);
5464    let mut a_des = DES::new_with_key_u64(key);
5465
5466    let message = "PARK Youngho";
5467    println!("M =\t{}", message);
5468    let mut cipher = [0_u8; 16];
5469    a_des.encrypt_str_into_array(&message, &mut cipher);
5470    print!("C =\t");
5471    for c in cipher.clone()
5472        { print!("{:02X} ", c); }
5473    println!();
5474    let mut txt = String::new();
5475    for c in cipher.clone()
5476        { write!(txt, "{:02X} ", c); }
5477    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5478
5479    let mut recovered = vec![0; 16];
5480    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5481    recovered.truncate(len as usize);
5482    print!("Ba =\t");
5483    for b in recovered.clone()
5484        { print!("{:02X} ", b); }
5485    println!();
5486    let mut txt = String::new();
5487    for c in recovered.clone()
5488        { write!(txt, "{:02X} ", c); }
5489    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5490
5491    let mut converted = String::new();
5492    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5493    
5494    println!("Bb =\t{}", converted);
5495    assert_eq!(converted, "PARK Youngho");
5496    assert_eq!(converted, message);
5497    println!();
5498
5499    // Normal case for the message of 16 bytes
5500    let key = 0x_1234567890ABCDEF_u64;
5501    println!("K =\t{:#016X}", key);
5502    let mut a_des = DES::new_with_key_u64(key);
5503
5504    let message = "고맙습니다.";
5505    println!("M =\t{}", message);
5506    let mut cipher = [0_u8; 24];
5507    a_des.encrypt_str_into_array(&message, &mut cipher);
5508    print!("C =\t");
5509    for c in cipher.clone()
5510        { print!("{:02X} ", c); }
5511    println!();
5512    let mut txt = String::new();
5513    for c in cipher.clone()
5514        { write!(txt, "{:02X} ", c); }
5515    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5516
5517    let mut recovered = vec![0; 24];
5518    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5519    recovered.truncate(len as usize);
5520
5521    print!("Ba =\t");
5522    for b in recovered.clone()
5523        { print!("{:02X} ", b); }
5524    println!();
5525    let mut txt = String::new();
5526    for c in recovered.clone()
5527        { write!(txt, "{:02X} ", c); }
5528    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5529
5530    let mut converted = String::new();
5531    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5532    
5533    println!("Bb =\t{}", converted);
5534    assert_eq!(converted, "고맙습니다.");
5535    assert_eq!(converted, message);
5536    println!("-------------------------------");
5537}
5538
5539fn des_decrypt_array_with_padding_iso_ecb_into_vec()
5540{
5541    println!("des_decrypt_array_with_padding_iso_ecb_into_vec()");
5542    use std::io::Write;
5543    use std::fmt::Write as _;
5544    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5545
5546    // Normal case
5547    let key = 0x_1234567890ABCDEF_u64;
5548    println!("K =\t{:#016X}", key);
5549    let mut a_des = DES::new_with_key_u64(key);
5550
5551    let message = "In the beginning God created the heavens and the earth.";
5552    println!("M =\t{}", message);
5553    let mut cipher = [0_u8; 56];
5554    a_des.encrypt_str_into_array(&message, &mut cipher);
5555    print!("C (16 rounds) =\t");
5556    for c in cipher.clone()
5557        { print!("{:02X} ", c); }
5558    println!();
5559    let mut txt = String::new();
5560    for c in cipher.clone()
5561        { write!(txt, "{:02X} ", c); }
5562    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5563
5564    let mut recovered = Vec::<u8>::new();
5565    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5566    print!("Ba (16 rounds) =\t");
5567    for b in recovered.clone()
5568        { print!("{:02X} ", b); }
5569    println!();
5570    let mut txt = String::new();
5571    for c in recovered.clone()
5572        { write!(txt, "{:02X} ", c); }
5573    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5574
5575    let mut converted = String::new();
5576    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5577    
5578    println!("Bb (16 rounds) =\t{}", converted);
5579    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5580    assert_eq!(converted, message);
5581    println!();
5582
5583    // Expanded case for 128 rounds
5584    let key = 0x_1234567890ABCDEF_u64;
5585    println!("K =\t{:#016X}", key);
5586    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5587
5588    let message = "In the beginning God created the heavens and the earth.";
5589    println!("M =\t{}", message);
5590    let mut cipher = [0_u8; 56];
5591    a_des.encrypt_str_into_array(&message, &mut cipher);
5592    print!("C (128 rounds) =\t");
5593    for c in cipher.clone()
5594        { print!("{:02X} ", c); }
5595    println!();
5596    let mut txt = String::new();
5597    for c in cipher.clone()
5598        { write!(txt, "{:02X} ", c); }
5599    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5600
5601    let mut recovered = Vec::<u8>::new();
5602    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5603    print!("Ba (128 rounds) =\t");
5604    for b in recovered.clone()
5605        { print!("{:02X} ", b); }
5606    println!();
5607    let mut txt = String::new();
5608    for c in recovered.clone()
5609        { write!(txt, "{:02X} ", c); }
5610    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5611
5612    let mut converted = String::new();
5613    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5614    
5615    println!("Bb (128 rounds) =\t{}", converted);
5616    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5617    assert_eq!(converted, message);
5618    println!();
5619
5620    // Expanded case for 0 rounds which means that key is meaningless
5621    let key1 = 0x_1234567890ABCDEF_u64;
5622    let key2 = 0_u64;
5623    println!("K =\t{:#016X}", key);
5624    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5625    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5626
5627    let message = "In the beginning God created the heavens and the earth.";
5628    println!("M =\t{}", message);
5629    let mut cipher1 = [0_u8; 56];
5630    let mut cipher2 = [0_u8; 56];
5631    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5632    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5633    print!("C (0 rounds) =\t");
5634    for c in cipher1.clone()
5635        { print!("{:02X} ", c); }
5636    println!();
5637    let mut txt = String::new();
5638    for c in cipher1.clone()
5639        { write!(txt, "{:02X} ", c); }
5640    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5641    print!("D (0 rounds) =\t");
5642    for c in cipher2.clone()
5643        { print!("{:02X} ", c); }
5644    println!();
5645    let mut txt = String::new();
5646    for c in cipher2.clone()
5647        { write!(txt, "{:02X} ", c); }
5648    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5649
5650    let mut recovered1 = Vec::<u8>::new();
5651    let mut recovered2 = Vec::<u8>::new();
5652    c_des.decrypt_array_into_vec(&cipher1, &mut recovered1);
5653    d_des.decrypt_array_into_vec(&cipher2, &mut recovered2);
5654    print!("B1a (0 rounds) =\t");
5655    for b in recovered1.clone()
5656        { print!("{:02X} ", b); }
5657    println!();
5658    let mut txt = String::new();
5659    for c in recovered1.clone()
5660        { write!(txt, "{:02X} ", c); }
5661    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5662    print!("B2a (0 rounds) =\t");
5663    for b in recovered2.clone()
5664        { print!("{:02X} ", b); }
5665    println!();
5666    let mut txt = String::new();
5667    for c in recovered2.clone()
5668        { write!(txt, "{:02X} ", c); }
5669    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5670
5671    let mut converted1 = String::new();
5672    let mut converted2 = String::new();
5673    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5674    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5675    
5676    println!("B1b (0 rounds) =\t{}", converted1);
5677    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5678    assert_eq!(converted1, message);
5679    println!("B2b (0 rounds) =\t{}", converted2);
5680    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5681    assert_eq!(converted2, message);
5682    assert_eq!(converted1, converted1);
5683    println!();
5684
5685    // Normal case for the message of 0 bytes
5686    let key = 0x_1234567890ABCDEF_u64;
5687    println!("K =\t{:#016X}", key);
5688    let mut a_des = DES::new_with_key_u64(key);
5689
5690    let message = "";
5691    println!("M =\t{}", message);
5692    let mut cipher = [0_u8; 8];
5693    a_des.encrypt_str_into_array(&message, &mut cipher);
5694    print!("C =\t");
5695    for c in cipher.clone()
5696        { print!("{:02X} ", c); }
5697    println!();
5698    let mut txt = String::new();
5699    for c in cipher.clone()
5700        { write!(txt, "{:02X} ", c); }
5701    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5702
5703    let mut recovered = Vec::<u8>::new();
5704    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5705    print!("Ba =\t");
5706    for b in recovered.clone()
5707        { print!("{:02X} ", b); }
5708    println!();
5709    let mut txt = String::new();
5710    for c in recovered.clone()
5711        { write!(txt, "{:02X} ", c); }
5712    assert_eq!(txt, "");
5713
5714    let mut converted = String::new();
5715    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5716    
5717    println!("Bb =\t{}", converted);
5718    assert_eq!(converted, "");
5719    assert_eq!(converted, message);
5720    println!();
5721
5722    // Normal case for the message shorter than 8 bytes
5723    let key = 0x_1234567890ABCDEF_u64;
5724    println!("K =\t{:#016X}", key);
5725    let mut a_des = DES::new_with_key_u64(key);
5726
5727    let message = "7 bytes";
5728    println!("M =\t{}", message);
5729    let mut cipher = [0_u8; 8];
5730    a_des.encrypt_str_into_array(&message, &mut cipher);
5731    print!("C =\t");
5732    for c in cipher.clone()
5733        { print!("{:02X} ", c); }
5734    println!();
5735    let mut txt = String::new();
5736    for c in cipher.clone()
5737        { write!(txt, "{:02X} ", c); }
5738    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5739    
5740    let mut recovered = Vec::<u8>::new();
5741    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5742    print!("Ba =\t");
5743    for b in recovered.clone()
5744        { print!("{:02X} ", b); }
5745    println!();
5746    let mut txt = String::new();
5747    for c in recovered.clone()
5748        { write!(txt, "{:02X} ", c); }
5749    assert_eq!(txt, "37 20 62 79 74 65 73 ");
5750
5751    let mut converted = String::new();
5752    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5753    
5754    println!("Bb =\t{}", converted);
5755    assert_eq!(converted, "7 bytes");
5756    assert_eq!(converted, message);
5757    println!();
5758
5759    // Normal case for the message of 8 bytes
5760    let key = 0x_1234567890ABCDEF_u64;
5761    println!("K =\t{:#016X}", key);
5762    let mut a_des = DES::new_with_key_u64(key);
5763
5764    let message = "I am OK.";
5765    println!("M =\t{}", message);
5766    let mut cipher = [0_u8; 16];
5767    a_des.encrypt_str_into_array(&message, &mut cipher);
5768    print!("C =\t");
5769    for c in cipher.clone()
5770        { print!("{:02X} ", c); }
5771    println!();
5772    let mut txt = String::new();
5773    for c in cipher.clone()
5774        { write!(txt, "{:02X} ", c); }
5775    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5776    
5777    let mut recovered = Vec::<u8>::new();
5778    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5779    print!("Ba =\t");
5780    for b in recovered.clone()
5781        { print!("{:02X} ", b); }
5782    println!();
5783    let mut txt = String::new();
5784    for c in recovered.clone()
5785        { write!(txt, "{:02X} ", c); }
5786    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5787
5788    let mut converted = String::new();
5789    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5790    
5791    println!("Bb =\t{}", converted);
5792    assert_eq!(converted, "I am OK.");
5793    assert_eq!(converted, message);
5794    println!();
5795
5796    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5797    let key = 0x_1234567890ABCDEF_u64;
5798    println!("K =\t{:#016X}", key);
5799    let mut a_des = DES::new_with_key_u64(key);
5800
5801    let message = "PARK Youngho";
5802    println!("M =\t{}", message);
5803    let mut cipher = [0_u8; 16];
5804    a_des.encrypt_str_into_array(&message, &mut cipher);
5805    print!("C =\t");
5806    for c in cipher.clone()
5807        { print!("{:02X} ", c); }
5808    println!();
5809    let mut txt = String::new();
5810    for c in cipher.clone()
5811        { write!(txt, "{:02X} ", c); }
5812    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5813
5814    let mut recovered = Vec::<u8>::new();
5815    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5816    print!("Ba =\t");
5817    for b in recovered.clone()
5818        { print!("{:02X} ", b); }
5819    println!();
5820    let mut txt = String::new();
5821    for c in recovered.clone()
5822        { write!(txt, "{:02X} ", c); }
5823    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5824
5825    let mut converted = String::new();
5826    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5827    
5828    println!("Bb =\t{}", converted);
5829    assert_eq!(converted, "PARK Youngho");
5830    assert_eq!(converted, message);
5831    println!();
5832
5833    // Normal case for the message of 16 bytes
5834    let key = 0x_1234567890ABCDEF_u64;
5835    println!("K =\t{:#016X}", key);
5836    let mut a_des = DES::new_with_key_u64(key);
5837
5838    let message = "고맙습니다.";
5839    println!("M =\t{}", message);
5840    let mut cipher = [0_u8; 24];
5841    a_des.encrypt_str_into_array(&message, &mut cipher);
5842    print!("C =\t");
5843    for c in cipher.clone()
5844        { print!("{:02X} ", c); }
5845    println!();
5846    let mut txt = String::new();
5847    for c in cipher.clone()
5848        { write!(txt, "{:02X} ", c); }
5849    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5850
5851    let mut recovered = Vec::<u8>::new();
5852    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5853    print!("Ba =\t");
5854    for b in recovered.clone()
5855        { print!("{:02X} ", b); }
5856    println!();
5857    let mut txt = String::new();
5858    for c in recovered.clone()
5859        { write!(txt, "{:02X} ", c); }
5860    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5861
5862    let mut converted = String::new();
5863    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5864    
5865    println!("Bb =\t{}", converted);
5866    assert_eq!(converted, "고맙습니다.");
5867    assert_eq!(converted, message);
5868    println!("-------------------------------");
5869}
5870
5871fn des_decrypt_array_with_padding_iso_ecb_into_array()
5872{
5873    println!("des_decrypt_array_with_padding_iso_ecb_into_array()");
5874    use std::io::Write;
5875    use std::fmt::Write as _;
5876    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5877
5878    // Normal case
5879    let key = 0x_1234567890ABCDEF_u64;
5880    println!("K =\t{:#016X}", key);
5881    let mut a_des = DES::new_with_key_u64(key);
5882
5883    let message = "In the beginning God created the heavens and the earth.";
5884    println!("M =\t{}", message);
5885    let mut cipher = [0_u8; 56];
5886    a_des.encrypt_str_into_array(&message, &mut cipher);
5887    print!("C (16 rounds) =\t");
5888    for c in cipher.clone()
5889        { print!("{:02X} ", c); }
5890    println!();
5891    let mut txt = String::new();
5892    for c in cipher.clone()
5893        { write!(txt, "{:02X} ", c); }
5894    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5895
5896    let mut recovered = [0u8; 56];
5897    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5898    print!("Ba (16 rounds) =\t");
5899    for b in recovered.clone()
5900        { print!("{:02X} ", b); }
5901    println!();
5902    let mut txt = String::new();
5903    for c in recovered.clone()
5904        { write!(txt, "{:02X} ", c); }
5905    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5906
5907    let mut converted = String::new();
5908    unsafe { converted.as_mut_vec() }.write(&recovered);
5909    unsafe { converted.as_mut_vec() }.truncate(len as usize);
5910    println!("Bb (16 rounds) =\t{}", converted);
5911    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5912    assert_eq!(converted, message);
5913    println!();
5914
5915    // Expanded case for 128 rounds
5916    let key = 0x_1234567890ABCDEF_u64;
5917    println!("K =\t{:#016X}", key);
5918    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5919
5920    let message = "In the beginning God created the heavens and the earth.";
5921    println!("M =\t{}", message);
5922    let mut cipher = [0_u8; 56];
5923    a_des.encrypt_str_into_array(&message, &mut cipher);
5924    print!("C (128 rounds) =\t");
5925    for c in cipher.clone()
5926        { print!("{:02X} ", c); }
5927    println!();
5928    let mut txt = String::new();
5929    for c in cipher.clone()
5930        { write!(txt, "{:02X} ", c); }
5931    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5932
5933    let mut recovered = [0u8; 56];
5934    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5935    print!("Ba (16 rounds) =\t");
5936    for b in recovered.clone()
5937        { print!("{:02X} ", b); }
5938    println!();
5939    let mut txt = String::new();
5940    for c in recovered.clone()
5941        { write!(txt, "{:02X} ", c); }
5942    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5943
5944    let mut converted = String::new();
5945    unsafe { converted.as_mut_vec() }.write(&recovered);
5946    unsafe { converted.as_mut_vec() }.truncate(len as usize);
5947    println!("Bb (16 rounds) =\t{}", converted);
5948    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5949    assert_eq!(converted, message);
5950    println!();
5951
5952    // Expanded case for 0 rounds which means that key is meaningless
5953    let key1 = 0x_1234567890ABCDEF_u64;
5954    let key2 = 0_u64;
5955    println!("K =\t{:#016X}", key);
5956    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5957    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5958
5959    let message = "In the beginning God created the heavens and the earth.";
5960    println!("M =\t{}", message);
5961    let mut cipher1 = [0_u8; 56];
5962    let mut cipher2 = [0_u8; 56];
5963    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5964    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5965    print!("C (0 rounds) =\t");
5966    for c in cipher1.clone()
5967        { print!("{:02X} ", c); }
5968    println!();
5969    let mut txt = String::new();
5970    for c in cipher1.clone()
5971        { write!(txt, "{:02X} ", c); }
5972    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5973    print!("D (0 rounds) =\t");
5974    for c in cipher2.clone()
5975        { print!("{:02X} ", c); }
5976    println!();
5977    let mut txt = String::new();
5978    for c in cipher2.clone()
5979        { write!(txt, "{:02X} ", c); }
5980    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5981
5982    let mut recovered1 = [0u8; 56];
5983    let mut recovered2 = [0u8; 56];
5984    let len1 = c_des.decrypt_array_into_array(&cipher1, &mut recovered1);
5985    let len2 = d_des.decrypt_array_into_array(&cipher2, &mut recovered2);
5986    print!("B1a (0 rounds) =\t");
5987    for b in recovered1.clone()
5988        { print!("{:02X} ", b); }
5989    println!();
5990    let mut txt = String::new();
5991    for c in recovered1.clone()
5992        { write!(txt, "{:02X} ", c); }
5993    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5994    print!("B2a (0 rounds) =\t");
5995    for b in recovered2.clone()
5996        { print!("{:02X} ", b); }
5997    println!();
5998    let mut txt = String::new();
5999    for c in recovered.clone()
6000        { write!(txt, "{:02X} ", c); }
6001    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6002
6003    let mut converted1 = String::new();
6004    let mut converted2 = String::new();
6005    unsafe { converted1.as_mut_vec() }.write(&recovered1);
6006    unsafe { converted2.as_mut_vec() }.write(&recovered2);
6007    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6008    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6009    println!("B1b (0 rounds) =\t{}", converted1);
6010    println!("B2b (0 rounds) =\t{}", converted2);
6011    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6012    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6013    assert_eq!(converted1, message);
6014    assert_eq!(converted2, message);
6015    assert_eq!(converted1, converted2);
6016    println!();
6017
6018    // Normal case for the message of 0 bytes
6019    let key = 0x_1234567890ABCDEF_u64;
6020    println!("K =\t{:#016X}", key);
6021    let mut a_des = DES::new_with_key_u64(key);
6022
6023    let message = "";
6024    println!("M =\t{}", message);
6025    let mut cipher = [0_u8; 8];
6026    a_des.encrypt_str_into_array(&message, &mut cipher);
6027    print!("C =\t");
6028    for c in cipher.clone()
6029        { print!("{:02X} ", c); }
6030    println!();
6031    let mut txt = String::new();
6032    for c in cipher.clone()
6033        { write!(txt, "{:02X} ", c); }
6034    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
6035
6036    let mut recovered = [0u8; 8];
6037    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6038
6039    print!("Ba =\t");
6040    for b in recovered.clone()
6041        { print!("{:02X} ", b); }
6042    println!();
6043    let mut txt = String::new();
6044    for c in recovered.clone()
6045        { write!(txt, "{:02X} ", c); }
6046    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6047
6048    let mut converted = String::new();
6049    unsafe { converted.as_mut_vec() }.write(&recovered);
6050    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6051    println!("Bb =\t{}", converted);
6052    assert_eq!(converted, "");
6053    assert_eq!(converted, message);
6054    println!();
6055
6056    // Normal case for the message shorter than 8 bytes
6057    let key = 0x_1234567890ABCDEF_u64;
6058    println!("K =\t{:#016X}", key);
6059    let mut a_des = DES::new_with_key_u64(key);
6060
6061    let message = "7 bytes";
6062    println!("M =\t{}", message);
6063    let mut cipher = [0_u8; 8];
6064    a_des.encrypt_str_into_array(&message, &mut cipher);
6065    print!("C =\t");
6066    for c in cipher.clone()
6067        { print!("{:02X} ", c); }
6068    println!();
6069    let mut txt = String::new();
6070    for c in cipher.clone()
6071        { write!(txt, "{:02X} ", c); }
6072    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
6073
6074    let mut recovered = [0u8; 8];
6075    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6076
6077    print!("Ba =\t");
6078    for b in recovered.clone()
6079        { print!("{:02X} ", b); }
6080    println!();
6081    let mut txt = String::new();
6082    for c in recovered.clone()
6083        { write!(txt, "{:02X} ", c); }
6084    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6085
6086    let mut converted = String::new();
6087    unsafe { converted.as_mut_vec() }.write(&recovered);
6088    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6089    println!("Bb =\t{}", converted);
6090    assert_eq!(converted, "7 bytes");
6091    assert_eq!(converted, message);
6092    println!();
6093
6094    // Normal case for the message of 8 bytes
6095    let key = 0x_1234567890ABCDEF_u64;
6096    println!("K =\t{:#016X}", key);
6097    let mut a_des = DES::new_with_key_u64(key);
6098
6099    let message = "I am OK.";
6100    println!("M =\t{}", message);
6101    let mut cipher = [0_u8; 16];
6102    a_des.encrypt_str_into_array(&message, &mut cipher);
6103    print!("C =\t");
6104    for c in cipher.clone()
6105        { print!("{:02X} ", c); }
6106    println!();
6107    let mut txt = String::new();
6108    for c in cipher.clone()
6109        { write!(txt, "{:02X} ", c); }
6110    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
6111
6112    let mut recovered = [0u8; 16];
6113    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6114
6115    print!("Ba =\t");
6116    for b in recovered.clone()
6117        { print!("{:02X} ", b); }
6118    println!();
6119    let mut txt = String::new();
6120    for c in recovered.clone()
6121        { write!(txt, "{:02X} ", c); }
6122    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6123
6124    let mut converted = String::new();
6125    unsafe { converted.as_mut_vec() }.write(&recovered);
6126    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6127    println!("Bb =\t{}", converted);
6128    assert_eq!(converted, "I am OK.");
6129    assert_eq!(converted, message);
6130    println!();
6131
6132    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6133    let key = 0x_1234567890ABCDEF_u64;
6134    println!("K =\t{:#016X}", key);
6135    let mut a_des = DES::new_with_key_u64(key);
6136
6137    let message = "PARK Youngho";
6138    println!("M =\t{}", message);
6139    let mut cipher = [0_u8; 16];
6140    a_des.encrypt_str_into_array(&message, &mut cipher);
6141    print!("C =\t");
6142    for c in cipher.clone()
6143        { print!("{:02X} ", c); }
6144    println!();
6145    let mut txt = String::new();
6146    for c in cipher.clone()
6147        { write!(txt, "{:02X} ", c); }
6148    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
6149
6150    let mut recovered = [0u8; 16];
6151    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6152
6153    print!("Ba =\t");
6154    for b in recovered.clone()
6155        { print!("{:02X} ", b); }
6156    println!();
6157    let mut txt = String::new();
6158    for c in recovered.clone()
6159        { write!(txt, "{:02X} ", c); }
6160    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6161
6162    let mut converted = String::new();
6163    unsafe { converted.as_mut_vec() }.write(&recovered);
6164    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6165    println!("Bb =\t{}", converted);
6166    assert_eq!(converted, "PARK Youngho");
6167    assert_eq!(converted, message);
6168    println!();
6169
6170    // Normal case for the message of 16 bytes
6171    let key = 0x_1234567890ABCDEF_u64;
6172    println!("K =\t{:#016X}", key);
6173    let mut a_des = DES::new_with_key_u64(key);
6174
6175    let message = "고맙습니다.";
6176    println!("M =\t{}", message);
6177    let mut cipher = [0_u8; 24];
6178    a_des.encrypt_str_into_array(&message, &mut cipher);
6179    print!("C =\t");
6180    for c in cipher.clone()
6181        { print!("{:02X} ", c); }
6182    println!();
6183    let mut txt = String::new();
6184    for c in cipher.clone()
6185        { write!(txt, "{:02X} ", c); }
6186    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
6187
6188    let mut recovered = [0u8; 24];
6189    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6190
6191    print!("Ba =\t");
6192    for b in recovered.clone()
6193        { print!("{:02X} ", b); }
6194    println!();
6195    let mut txt = String::new();
6196    for c in recovered.clone()
6197        { write!(txt, "{:02X} ", c); }
6198    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6199
6200    let mut converted = String::new();
6201    unsafe { converted.as_mut_vec() }.write(&recovered);
6202    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6203    println!("Bb =\t{}", converted);
6204    assert_eq!(converted, "고맙습니다.");
6205    assert_eq!(converted, message);
6206    println!("-------------------------------");
6207}
6208
6209fn des_decrypt_array_with_padding_iso_ecb_into_string()
6210{
6211    println!("des_decrypt_array_with_padding_iso_ecb_into_string()");
6212    use std::io::Write;
6213    use std::fmt::Write as _;
6214    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
6215
6216    // Normal case
6217    let key = 0x_1234567890ABCDEF_u64;
6218    println!("K =\t{:#016X}", key);
6219    let mut a_des = DES::new_with_key_u64(key);
6220
6221    let message = "In the beginning God created the heavens and the earth.";
6222    println!("M =\t{}", message);
6223    let mut cipher = [0_u8; 56];
6224    a_des.encrypt_str_into_array(&message, &mut cipher);
6225    print!("C (16 rounds) =\t");
6226    for c in cipher.clone()
6227        { print!("{:02X} ", c); }
6228    println!();
6229    let mut txt = String::new();
6230    for c in cipher.clone()
6231        { write!(txt, "{:02X} ", c); }
6232    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
6233
6234    let mut recovered = String::new();
6235    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6236    println!("B (16 rounds) =\t{}", recovered);
6237    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6238    assert_eq!(recovered, message);
6239    println!();
6240
6241    // Expanded case for 128 rounds
6242    let key = 0x_1234567890ABCDEF_u64;
6243    println!("K =\t{:#016X}", key);
6244    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6245
6246    let message = "In the beginning God created the heavens and the earth.";
6247    println!("M =\t{}", message);
6248    let mut cipher = [0_u8; 56];
6249    a_des.encrypt_str_into_array(&message, &mut cipher);
6250    print!("C (128 rounds) =\t");
6251    for c in cipher.clone()
6252        { print!("{:02X} ", c); }
6253    println!();
6254    let mut txt = String::new();
6255    for c in cipher.clone()
6256        { write!(txt, "{:02X} ", c); }
6257    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
6258
6259    let mut recovered = String::new();
6260    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6261    println!("B (128 rounds) =\t{}", recovered);
6262    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6263    assert_eq!(recovered, message);
6264    println!();
6265
6266    // Expanded case for 0 rounds which means that key is meaningless
6267    let key1 = 0x_1234567890ABCDEF_u64;
6268    let key2 = 0_u64;
6269    println!("K =\t{:#016X}", key);
6270    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6271    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6272
6273    let message = "In the beginning God created the heavens and the earth.";
6274    println!("M =\t{}", message);
6275    let mut cipher1 = [0_u8; 56];
6276    let mut cipher2 = [0_u8; 56];
6277    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
6278    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
6279    print!("C (0 rounds) =\t");
6280    for c in cipher1.clone()
6281        { print!("{:02X} ", c); }
6282    println!();
6283    let mut txt = String::new();
6284    for c in cipher1.clone()
6285        { write!(txt, "{:02X} ", c); }
6286    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
6287    print!("D (0 rounds) =\t");
6288    for c in cipher2.clone()
6289        { print!("{:02X} ", c); }
6290    println!();
6291    let mut txt = String::new();
6292    for c in cipher2.clone()
6293        { write!(txt, "{:02X} ", c); }
6294    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
6295
6296    let mut recovered1 = String::new();
6297    let mut recovered2 = String::new();
6298    c_des.decrypt_array_into_string(&cipher1, &mut recovered1);
6299    d_des.decrypt_array_into_string(&cipher2, &mut recovered2);
6300    println!("B1 (0 rounds) =\t{}", recovered1);
6301    println!("B2 (0 rounds) =\t{}", recovered2);
6302    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6303    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6304    assert_eq!(recovered1, message);
6305    assert_eq!(recovered2, message);
6306    assert_eq!(recovered1, recovered2);
6307    println!();
6308
6309    // Normal case for the message of 0 bytes
6310    let key = 0x_1234567890ABCDEF_u64;
6311    println!("K =\t{:#016X}", key);
6312    let mut a_des = DES::new_with_key_u64(key);
6313
6314    let message = "";
6315    println!("M =\t{}", message);
6316    let mut cipher = [0_u8; 8];
6317    a_des.encrypt_str_into_array(&message, &mut cipher);
6318    print!("C =\t");
6319    for c in cipher.clone()
6320        { print!("{:02X} ", c); }
6321    println!();
6322    let mut txt = String::new();
6323    for c in cipher.clone()
6324        { write!(txt, "{:02X} ", c); }
6325    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
6326
6327    let mut recovered = String::new();
6328    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6329    println!("B =\t{}", recovered);
6330    assert_eq!(recovered, "");
6331    assert_eq!(recovered, message);
6332    println!();
6333
6334    // Normal case for the message shorter than 8 bytes
6335    let key = 0x_1234567890ABCDEF_u64;
6336    println!("K =\t{:#016X}", key);
6337    let mut a_des = DES::new_with_key_u64(key);
6338
6339    let message = "7 bytes";
6340    println!("M =\t{}", message);
6341    let mut cipher = [0_u8; 8];
6342    a_des.encrypt_str_into_array(&message, &mut cipher);
6343    print!("C =\t");
6344    for c in cipher.clone()
6345        { print!("{:02X} ", c); }
6346    println!();
6347    let mut txt = String::new();
6348    for c in cipher.clone()
6349        { write!(txt, "{:02X} ", c); }
6350    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
6351
6352    let mut recovered = String::new();
6353    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6354    println!("B =\t{}", recovered);
6355    assert_eq!(recovered, "7 bytes");
6356    assert_eq!(recovered, message);
6357    println!();
6358
6359    // Normal case for the message of 8 bytes
6360    let key = 0x_1234567890ABCDEF_u64;
6361    println!("K =\t{:#016X}", key);
6362    let mut a_des = DES::new_with_key_u64(key);
6363
6364    let message = "I am OK.";
6365    println!("M =\t{}", message);
6366    let mut cipher = [0_u8; 16];
6367    a_des.encrypt_str_into_array(&message, &mut cipher);
6368    print!("C =\t");
6369    for c in cipher.clone()
6370        { print!("{:02X} ", c); }
6371    println!();
6372    let mut txt = String::new();
6373    for c in cipher.clone()
6374        { write!(txt, "{:02X} ", c); }
6375    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
6376
6377    let mut recovered = String::new();
6378    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6379    println!("B =\t{}", recovered);
6380    assert_eq!(recovered, "I am OK.");
6381    assert_eq!(recovered, message);
6382    println!();
6383
6384    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6385    let key = 0x_1234567890ABCDEF_u64;
6386    println!("K =\t{:#016X}", key);
6387    let mut a_des = DES::new_with_key_u64(key);
6388
6389    let message = "PARK Youngho";
6390    println!("M =\t{}", message);
6391    let mut cipher = [0_u8; 16];
6392    a_des.encrypt_str_into_array(&message, &mut cipher);
6393    print!("C =\t");
6394    for c in cipher.clone()
6395        { print!("{:02X} ", c); }
6396    println!();
6397    let mut txt = String::new();
6398    for c in cipher.clone()
6399        { write!(txt, "{:02X} ", c); }
6400    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
6401
6402    let mut recovered = String::new();
6403    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6404    println!("B =\t{}", recovered);
6405    assert_eq!(recovered, "PARK Youngho");
6406    assert_eq!(recovered, message);
6407    println!();
6408
6409    // Normal case for the message of 16 bytes
6410    let key = 0x_1234567890ABCDEF_u64;
6411    println!("K =\t{:#016X}", key);
6412    let mut a_des = DES::new_with_key_u64(key);
6413
6414    let message = "고맙습니다.";
6415    println!("M =\t{}", message);
6416    let mut cipher = [0_u8; 24];
6417    a_des.encrypt_str_into_array(&message, &mut cipher);
6418    print!("C =\t");
6419    for c in cipher.clone()
6420        { print!("{:02X} ", c); }
6421    println!();
6422    let mut txt = String::new();
6423    for c in cipher.clone()
6424        { write!(txt, "{:02X} ", c); }
6425    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
6426
6427    let mut recovered = String::new();
6428    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6429    println!("B =\t{}", recovered);
6430    assert_eq!(recovered, "고맙습니다.");
6431    assert_eq!(recovered, message);
6432    println!("-------------------------------");
6433}
Source

fn encrypt_string(&mut self, message: &String, cipher: *mut u8) -> u64

Encrypts the data stored in a String object with the padding according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • message is an immutable reference to String object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable pointer to u8 which is *mut u8, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_string_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • If message is a String object that has a null string “”, only padding bytes will be encrypted, and stored in the memory area that starts from cipher.
  • The size of the memory area which starts at cipher is assumed to be enough to store the ciphertext.
  • The size of the area for ciphertext should be prepared to be (message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.".to_string();
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_string(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.".to_string();
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_string(&message, cipher.as_mut_ptr());
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.".to_string();
let mut cipher = [0_u8; 64];
taes.encrypt_string(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.".to_string();
let mut cipher = [0_u8; 56];
tdes.encrypt_string(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 221)
208fn bigcryptor64_encrypt_string_with_padding_iso_ecb()
209{
210    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb()");
211    use std::io::Write;
212    use std::fmt::Write as _;
213    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
214
215    // TDES case
216    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219    let message = "In the beginning God created the heavens and the earth.".to_string();
220    let mut cipher = [0_u8; 56];
221    tdes.encrypt_string(&message, cipher.as_mut_ptr());
222    print!("C =\t");
223    for c in cipher.clone()
224        { print!("{:02X} ", c); }
225    println!();
226    let mut txt = String::new();
227    for c in cipher.clone()
228        { write!(txt, "{:02X} ", c); }
229    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230    println!("-------------------------------");
231}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 235)
220fn bigcryptor128_encrypt_string_with_padding_iso_ecb()
221{
222    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb()");
223    use std::io::Write;
224    use std::fmt::Write as _;
225    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
226
227    // TAES_128 case
228    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
229                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
230                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
231    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
232    println!("IV =	{:#034X}", iv);
233    let message = "In the beginning God created the heavens and the earth.".to_string();
234    let mut cipher = [0_u8; 64];
235    taes.encrypt_string(&message, cipher.as_mut_ptr());
236    print!("C =\t");
237    for c in cipher.clone()
238        { print!("{:02X} ", c); }
239    println!();
240    let mut txt = String::new();
241    for c in cipher.clone()
242        { write!(txt, "{:02X} ", c); }
243    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
244    println!("-------------------------------");
245}
examples/aes_ecb_iso_examples.rs (line 772)
757fn aes_encrypt_string_with_padding_iso_ecb()
758{
759    println!("aes_encrypt_string_with_padding_iso_ecb()");
760    use std::io::Write;
761    use std::fmt::Write as _;
762    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
763
764    // Normal case for AES-128
765    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
766    println!("K =\t{:#016X}", key);
767    let mut a_aes = AES_128::new_with_key_u128(key);
768
769    let message = "In the beginning God created the heavens and the earth.".to_string();
770    println!("M =\t{}", message);
771    let mut cipher = [0_u8; 64];
772    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
773    print!("C =\t");
774    for c in cipher.clone()
775        { print!("{:02X} ", c); }
776    println!();
777    let mut txt = String::new();
778    for c in cipher.clone()
779        { write!(txt, "{:02X} ", c); }
780    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
781    println!();
782
783    // Normal case for AES-192
784    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
785    print!("K =\t");
786    for i in 0..24
787        { print!("{:02X}", key[i]); }
788    println!();
789    let mut a_aes = AES_192::new_with_key(&key);
790
791    let message = "In the beginning God created the heavens and the earth.".to_string();
792    println!("M =\t{}", message);
793    let mut cipher = [0_u8; 64];
794    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
795    print!("C =\t");
796    for c in cipher.clone()
797        { print!("{:02X} ", c); }
798    println!();
799    let mut txt = String::new();
800    for c in cipher.clone()
801        { write!(txt, "{:02X} ", c); }
802    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
803    println!();
804
805    // Normal case for AES-256
806    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
807    print!("K =\t");
808    for i in 0..32
809        { print!("{:02X}", key[i]); }
810    println!();
811    let mut a_aes = AES_256::new_with_key(&key);
812
813    let message = "In the beginning God created the heavens and the earth.".to_string();
814    println!("M =\t{}", message);
815    let mut cipher = [0_u8; 64];
816    a_aes.encrypt_string(&message, cipher.as_mut_ptr());
817    print!("C =\t");
818    for c in cipher.clone()
819        { print!("{:02X} ", c); }
820    println!();
821    let mut txt = String::new();
822    for c in cipher.clone()
823        { write!(txt, "{:02X} ", c); }
824    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
825    println!();
826
827    // Normal case for Rijndael-256-256
828    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
829    print!("K =\t");
830    for i in 0..32
831        { print!("{:02X}", key[i]); }
832    println!();
833    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
834
835    let message = "In the beginning God created the heavens and the earth.".to_string();
836    println!("M =\t{}", message);
837    let mut cipher = [0_u8; 64];
838    a_rijndael.encrypt_string(&message, cipher.as_mut_ptr());
839    print!("C =\t");
840    for c in cipher.clone()
841        { print!("{:02X} ", c); }
842    println!();
843    let mut txt = String::new();
844    for c in cipher.clone()
845        { write!(txt, "{:02X} ", c); }
846    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
847    println!();
848
849    // Normal case for Rijndael-512-512 for post-quantum
850    use cryptocol::number::SharedArrays;
851    use cryptocol::hash::SHA3_512;
852    let mut sha3 = SHA3_512::new();
853    sha3.absorb_str("Post-quantum");
854    let key: [u8; 64] = sha3.get_hash_value_in_array();
855    print!("K =\t");
856    for i in 0..64
857        { print!("{:02X}", key[i]); }
858    println!();
859    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
860
861    let message = "In the beginning God created the heavens and the earth.".to_string();
862    println!("M =\t{}", message);
863    let mut cipher = [0_u8; 64];
864    a_rijndael.encrypt_string(&message, cipher.as_mut_ptr());
865    print!("C =\t");
866    for c in cipher.clone()
867        { print!("{:02X} ", c); }
868    println!();
869    let mut txt = String::new();
870    for c in cipher.clone()
871        { write!(txt, "{:02X} ", c); }
872    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
873    println!("-------------------------------");
874}
examples/des_ecb_iso_examples.rs (line 1106)
1091fn des_encrypt_string_with_padding_iso_ecb()
1092{
1093    println!("des_encrypt_string_with_padding_iso_ecb()");
1094    use std::io::Write;
1095    use std::fmt::Write as _;
1096    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1097
1098    // Normal case
1099    let key = 0x_1234567890ABCDEF_u64;
1100    println!("K =\t{:#016X}", key);
1101    let mut a_des = DES::new_with_key_u64(key);
1102
1103    let message = "In the beginning God created the heavens and the earth.".to_string();
1104    println!("M =\t{}", message);
1105    let mut cipher = [0_u8; 56];
1106    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1107    print!("C (16 rounds) =\t");
1108    for c in cipher.clone()
1109        { print!("{:02X} ", c); }
1110    println!();
1111    let mut txt = String::new();
1112    for c in cipher.clone()
1113        { write!(txt, "{:02X} ", c); }
1114    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1115    println!();
1116
1117    // Expanded case for 128 rounds
1118    let key = 0x_1234567890ABCDEF_u64;
1119    println!("K =\t{:#016X}", key);
1120    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1121
1122    let message = "In the beginning God created the heavens and the earth.".to_string();
1123    println!("M =\t{}", message);
1124    let mut cipher = [0_u8; 56];
1125    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1126    print!("C (128 rounds) =\t");
1127    for c in cipher.clone()
1128        { print!("{:02X} ", c); }
1129    println!();
1130    let mut txt = String::new();
1131    for c in cipher.clone()
1132        { write!(txt, "{:02X} ", c); }
1133    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1134    println!();
1135
1136    // Expanded case for 0 rounds which means that key is meaningless
1137    let key1 = 0x_1234567890ABCDEF_u64;
1138    let key2 = 0_u64;
1139    println!("K =\t{:#016X}", key);
1140    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1141    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1142
1143    let message = "In the beginning God created the heavens and the earth.".to_string();
1144    println!("M =\t{}", message);
1145    let mut cipher1 = [0_u8; 56];
1146    let mut cipher2 = [0_u8; 56];
1147    c_des.encrypt_string(&message, cipher1.as_mut_ptr());
1148    d_des.encrypt_string(&message, cipher2.as_mut_ptr());
1149    print!("C (0 rounds) =\t");
1150    for c in cipher1.clone()
1151        { print!("{:02X} ", c); }
1152    println!();
1153    let mut txt = String::new();
1154    for c in cipher1.clone()
1155        { write!(txt, "{:02X} ", c); }
1156    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1157    print!("D (0 rounds) =\t");
1158    for c in cipher2.clone()
1159        { print!("{:02X} ", c); }
1160    println!();
1161    let mut txt = String::new();
1162    for c in cipher2.clone()
1163        { write!(txt, "{:02X} ", c); }
1164    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1165    println!();
1166
1167    // Normal case for the message of 0 bytes
1168    let key = 0x_1234567890ABCDEF_u64;
1169    println!("K =\t{:#016X}", key);
1170    let mut a_des = DES::new_with_key_u64(key);
1171
1172    let message = "".to_string();
1173    println!("M =\t{}", message);
1174    let mut cipher = [0_u8; 8];
1175    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1176    print!("C =\t");
1177    for c in cipher.clone()
1178        { print!("{:02X} ", c); }
1179    println!();
1180    let mut txt = String::new();
1181    for c in cipher.clone()
1182        { write!(txt, "{:02X} ", c); }
1183    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1184    println!();
1185
1186    // Normal case for the message shorter than 8 bytes
1187    let key = 0x_1234567890ABCDEF_u64;
1188    println!("K =\t{:#016X}", key);
1189    let mut a_des = DES::new_with_key_u64(key);
1190
1191    let message = "7 bytes".to_string();
1192    println!("M =\t{}", message);
1193    let mut cipher = [0_u8; 8];
1194    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1195    print!("C =\t");
1196    for c in cipher.clone()
1197        { print!("{:02X} ", c); }
1198    println!();
1199    let mut txt = String::new();
1200    for c in cipher.clone()
1201        { write!(txt, "{:02X} ", c); }
1202    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1203    println!();
1204
1205    // Normal case for the message of 8 bytes
1206    let key = 0x_1234567890ABCDEF_u64;
1207    println!("K =\t{:#016X}", key);
1208    let mut a_des = DES::new_with_key_u64(key);
1209
1210    let message = "I am OK.".to_string();
1211    println!("M =\t{}", message);
1212    let mut cipher = [0_u8; 16];
1213    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1214    print!("C =\t");
1215    for c in cipher.clone()
1216        { print!("{:02X} ", c); }
1217    println!();
1218    let mut txt = String::new();
1219    for c in cipher.clone()
1220        { write!(txt, "{:02X} ", c); }
1221    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1222    println!();
1223
1224    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1225    let key = 0x_1234567890ABCDEF_u64;
1226    println!("K =\t{:#016X}", key);
1227    let mut a_des = DES::new_with_key_u64(key);
1228
1229    let message = "PARK Youngho".to_string();
1230    println!("M =\t{}", message);
1231    let mut cipher = [0_u8; 16];
1232    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1233    print!("C =\t");
1234    for c in cipher.clone()
1235        { print!("{:02X} ", c); }
1236    println!();
1237    let mut txt = String::new();
1238    for c in cipher.clone()
1239        { write!(txt, "{:02X} ", c); }
1240    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1241    println!();
1242
1243
1244    // Normal case for the message of 16 bytes
1245    let key = 0x_1234567890ABCDEF_u64;
1246    println!("K =\t{:#016X}", key);
1247    let mut a_des = DES::new_with_key_u64(key);
1248
1249    let message = "고맙습니다.".to_string();
1250    println!("M =\t{}", message);
1251    let mut cipher = [0_u8; 24];
1252    a_des.encrypt_string(&message, cipher.as_mut_ptr());
1253    print!("C =\t");
1254    for c in cipher.clone()
1255        { print!("{:02X} ", c); }
1256    println!();
1257    let mut txt = String::new();
1258    for c in cipher.clone()
1259        { write!(txt, "{:02X} ", c); }
1260    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1261    println!("-------------------------------");
1262}
Source

fn encrypt_string_into_vec<U>( &mut self, message: &String, cipher: &mut Vec<U>, ) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data stored in a String object with the padding according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in Vec<U>.

§Arguments
  • message is an immutable reference to String object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to Vec<U> object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is a String object that has a null string “”, only padding bytes will be encrypted, and stored in the Vec<U> object which is referred to as cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.".to_string();
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_string_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.".to_string();
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_string_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.".to_string();
let mut cipher = Vec::<u8>::new();
taes.encrypt_string_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.".to_string();
let mut cipher = Vec::<u8>::new();
tdes.encrypt_string_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 246)
233fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()
234{
235    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()");
236    use std::io::Write;
237    use std::fmt::Write as _;
238    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
239
240    // TDES case
241    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244    let message = "In the beginning God created the heavens and the earth.".to_string();
245    let mut cipher = Vec::<u8>::new();
246    tdes.encrypt_string_into_vec(&message, &mut cipher);
247    print!("C =\t");
248    for c in cipher.clone()
249        { print!("{:02X} ", c); }
250    println!();
251    let mut txt = String::new();
252    for c in cipher.clone()
253        { write!(txt, "{:02X} ", c); }
254    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255    println!("-------------------------------");
256}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 262)
247fn bigcryptor128_encrypt_string_with_padding_iso_ecb_into_vec()
248{
249    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb_into_vec()");
250    use std::io::Write;
251    use std::fmt::Write as _;
252    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
253
254    // TAES_128 case
255    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
256                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
257                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
258    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
259    println!("IV =	{:#034X}", iv);
260    let message = "In the beginning God created the heavens and the earth.".to_string();
261    let mut cipher = Vec::<u8>::new();
262    taes.encrypt_string_into_vec(&message, &mut cipher);
263    print!("C =\t");
264    for c in cipher.clone()
265        { print!("{:02X} ", c); }
266    println!();
267    let mut txt = String::new();
268    for c in cipher.clone()
269        { write!(txt, "{:02X} ", c); }
270    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
271    println!("-------------------------------");
272}
examples/aes_ecb_iso_examples.rs (line 891)
876fn aes_encrypt_string_with_padding_iso_ecb_into_vec()
877{
878    println!("aes_encrypt_string_with_padding_iso_ecb_into_vec()");
879    use std::io::Write;
880    use std::fmt::Write as _;
881    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
882
883    // Normal case for AES-128
884    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
885    println!("K =\t{:#016X}", key);
886    let mut a_aes = AES_128::new_with_key_u128(key);
887
888    let message = "In the beginning God created the heavens and the earth.".to_string();
889    println!("M =\t{}", message);
890    let mut cipher = Vec::<u8>::new();
891    a_aes.encrypt_string_into_vec(&message, &mut cipher);
892    print!("C =\t");
893    for c in cipher.clone()
894        { print!("{:02X} ", c); }
895    println!();
896    let mut txt = String::new();
897    for c in cipher.clone()
898        { write!(txt, "{:02X} ", c); }
899    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
900    println!();
901
902    // Normal case for AES-192
903    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
904    print!("K =\t");
905    for i in 0..24
906        { print!("{:02X}", key[i]); }
907    println!();
908    let mut a_aes = AES_192::new_with_key(&key);
909
910    let message = "In the beginning God created the heavens and the earth.".to_string();
911    println!("M =\t{}", message);
912    let mut cipher = Vec::<u8>::new();
913    a_aes.encrypt_string_into_vec(&message, &mut cipher);
914    print!("C =\t");
915    for c in cipher.clone()
916        { print!("{:02X} ", c); }
917    println!();
918    let mut txt = String::new();
919    for c in cipher.clone()
920        { write!(txt, "{:02X} ", c); }
921    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
922    println!();
923
924    // Normal case for AES-256
925    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
926    print!("K =\t");
927    for i in 0..32
928        { print!("{:02X}", key[i]); }
929    println!();
930    let mut a_aes = AES_256::new_with_key(&key);
931
932    let message = "In the beginning God created the heavens and the earth.".to_string();
933    println!("M =\t{}", message);
934    let mut cipher = Vec::<u8>::new();
935    a_aes.encrypt_string_into_vec(&message, &mut cipher);
936    print!("C =\t");
937    for c in cipher.clone()
938        { print!("{:02X} ", c); }
939    println!();
940    let mut txt = String::new();
941    for c in cipher.clone()
942        { write!(txt, "{:02X} ", c); }
943    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
944    println!();
945
946    // Normal case for Rijndael-256-256
947    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
948    print!("K =\t");
949    for i in 0..32
950        { print!("{:02X}", key[i]); }
951    println!();
952    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
953
954    let message = "In the beginning God created the heavens and the earth.".to_string();
955    println!("M =\t{}", message);
956    let mut cipher = Vec::<u8>::new();
957    a_rijndael.encrypt_string_into_vec(&message, &mut cipher);
958    print!("C =\t");
959    for c in cipher.clone()
960        { print!("{:02X} ", c); }
961    println!();
962    let mut txt = String::new();
963    for c in cipher.clone()
964        { write!(txt, "{:02X} ", c); }
965    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
966    println!();
967
968    // Normal case for Rijndael-512-512 for post-quantum
969    use cryptocol::number::SharedArrays;
970    use cryptocol::hash::SHA3_512;
971    let mut sha3 = SHA3_512::new();
972    sha3.absorb_str("Post-quantum");
973    let key: [u8; 64] = sha3.get_hash_value_in_array();
974    print!("K =\t");
975    for i in 0..64
976        { print!("{:02X}", key[i]); }
977    println!();
978    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
979    let message = "In the beginning God created the heavens and the earth.".to_string();
980    println!("M =\t{}", message);
981    let mut cipher = Vec::<u8>::new();
982    a_rijndael.encrypt_string_into_vec(&message, &mut cipher);
983    print!("C =\t");
984    for c in cipher.clone()
985        { print!("{:02X} ", c); }
986    println!();
987    let mut txt = String::new();
988    for c in cipher.clone()
989        { write!(txt, "{:02X} ", c); }
990    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
991    println!("-------------------------------");
992}
examples/des_ecb_iso_examples.rs (line 1279)
1264fn des_encrypt_string_with_padding_iso_ecb_into_vec()
1265{
1266    println!("des_encrypt_string_with_padding_iso_ecb_into_vec()");
1267    use std::io::Write;
1268    use std::fmt::Write as _;
1269    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1270
1271    // Normal case
1272    let key = 0x_1234567890ABCDEF_u64;
1273    println!("K =\t{:#016X}", key);
1274    let mut a_des = DES::new_with_key_u64(key);
1275
1276    let message = "In the beginning God created the heavens and the earth.".to_string();
1277    println!("M =\t{}", message);
1278    let mut cipher = Vec::<u8>::new();
1279    a_des.encrypt_string_into_vec(&message, &mut cipher);
1280    print!("C (16 rounds) =\t");
1281    for c in cipher.clone()
1282        { print!("{:02X} ", c); }
1283    println!();
1284    let mut txt = String::new();
1285    for c in cipher.clone()
1286        { write!(txt, "{:02X} ", c); }
1287    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1288    println!();
1289
1290    // Expanded case for 128 rounds
1291    let key = 0x_1234567890ABCDEF_u64;
1292    println!("K =\t{:#016X}", key);
1293    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1294
1295    let message = "In the beginning God created the heavens and the earth.".to_string();
1296    println!("M =\t{}", message);
1297    let mut cipher = Vec::<u8>::new();
1298    a_des.encrypt_string_into_vec(&message, &mut cipher);
1299    print!("C (128 rounds) =\t");
1300    for c in cipher.clone()
1301        { print!("{:02X} ", c); }
1302    println!();
1303    let mut txt = String::new();
1304    for c in cipher.clone()
1305        { write!(txt, "{:02X} ", c); }
1306    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1307    println!();
1308
1309    // Expanded case for 0 rounds which means that key is meaningless
1310    let key1 = 0x_1234567890ABCDEF_u64;
1311    let key2 = 0_u64;
1312    println!("K =\t{:#016X}", key);
1313    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1314    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1315
1316    let message = "In the beginning God created the heavens and the earth.".to_string();
1317    println!("M =\t{}", message);
1318    let mut cipher1 = Vec::<u8>::new();
1319    let mut cipher2 = Vec::<u8>::new();
1320    c_des.encrypt_string_into_vec(&message, &mut cipher1);
1321    d_des.encrypt_string_into_vec(&message, &mut cipher2);
1322    print!("C (0 rounds) =\t");
1323    for c in cipher1.clone()
1324        { print!("{:02X} ", c); }
1325    println!();
1326    let mut txt = String::new();
1327    for c in cipher1.clone()
1328        { write!(txt, "{:02X} ", c); }
1329    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1330    print!("D (0 rounds) =\t");
1331    for c in cipher2.clone()
1332        { print!("{:02X} ", c); }
1333    println!();
1334    let mut txt = String::new();
1335    for c in cipher2.clone()
1336        { write!(txt, "{:02X} ", c); }
1337    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1338    println!();
1339
1340    // Normal case for the message of 0 bytes
1341    let key = 0x_1234567890ABCDEF_u64;
1342    println!("K =\t{:#016X}", key);
1343    let mut a_des = DES::new_with_key_u64(key);
1344
1345    let message = "".to_string();
1346    println!("M =\t{}", message);
1347    let mut cipher = Vec::<u8>::new();
1348    a_des.encrypt_string_into_vec(&message, &mut cipher);
1349    print!("C =\t");
1350    for c in cipher.clone()
1351        { print!("{:02X} ", c); }
1352    println!();
1353    let mut txt = String::new();
1354    for c in cipher.clone()
1355        { write!(txt, "{:02X} ", c); }
1356    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1357    println!();
1358
1359    // Normal case for the message shorter than 8 bytes
1360    let key = 0x_1234567890ABCDEF_u64;
1361    println!("K =\t{:#016X}", key);
1362    let mut a_des = DES::new_with_key_u64(key);
1363
1364    let message = "7 bytes".to_string();
1365    println!("M =\t{}", message);
1366    let mut cipher = Vec::<u8>::new();
1367    a_des.encrypt_string_into_vec(&message, &mut cipher);
1368    print!("C =\t");
1369    for c in cipher.clone()
1370        { print!("{:02X} ", c); }
1371    println!();
1372    let mut txt = String::new();
1373    for c in cipher.clone()
1374        { write!(txt, "{:02X} ", c); }
1375    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1376    println!();
1377
1378    // Normal case for the message of 8 bytes
1379    let key = 0x_1234567890ABCDEF_u64;
1380    println!("K =\t{:#016X}", key);
1381    let mut a_des = DES::new_with_key_u64(key);
1382
1383    let message = "I am OK.".to_string();
1384    println!("M =\t{}", message);
1385    let mut cipher = Vec::<u8>::new();
1386    a_des.encrypt_string_into_vec(&message, &mut cipher);
1387    print!("C =\t");
1388    for c in cipher.clone()
1389        { print!("{:02X} ", c); }
1390    println!();
1391    let mut txt = String::new();
1392    for c in cipher.clone()
1393        { write!(txt, "{:02X} ", c); }
1394    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1395    println!();
1396
1397    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1398    let key = 0x_1234567890ABCDEF_u64;
1399    println!("K =\t{:#016X}", key);
1400    let mut a_des = DES::new_with_key_u64(key);
1401
1402    let message = "PARK Youngho".to_string();
1403    println!("M =\t{}", message);
1404    let mut cipher = Vec::<u8>::new();
1405    a_des.encrypt_string_into_vec(&message, &mut cipher);
1406    print!("C =\t");
1407    for c in cipher.clone()
1408        { print!("{:02X} ", c); }
1409    println!();
1410    let mut txt = String::new();
1411    for c in cipher.clone()
1412        { write!(txt, "{:02X} ", c); }
1413    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1414    println!();
1415
1416
1417    // Normal case for the message of 16 bytes
1418    let key = 0x_1234567890ABCDEF_u64;
1419    println!("K =\t{:#016X}", key);
1420    let mut a_des = DES::new_with_key_u64(key);
1421
1422    let message = "고맙습니다.".to_string();
1423    println!("M =\t{}", message);
1424    let mut cipher = Vec::<u8>::new();
1425    a_des.encrypt_string_into_vec(&message, &mut cipher);
1426    print!("C =\t");
1427    for c in cipher.clone()
1428        { print!("{:02X} ", c); }
1429    println!();
1430    let mut txt = String::new();
1431    for c in cipher.clone()
1432        { write!(txt, "{:02X} ", c); }
1433    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1434    println!("-------------------------------");
1435}
Source

fn encrypt_string_into_array<U, const N: usize>( &mut self, message: &String, cipher: &mut [U; N], ) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data stored in a String object with the padding according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in array [U; N].

§Arguments
  • message is an immutable reference to String object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to an array [U; N] object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is a String object that has a null string “”, only padding bytes will be encrypted, and stored in the array [U; N] object cipher.
  • If size_of::<U>() * N is less than message.len()’s next multiple of size_of::<T>(), this method does not perform encryption but returns zero.
  • If size_of::<U>() * N is equal to message.len()’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and returns the size of the ciphertext including padding bits in bytes.
  • If size_of::<U>() * N is greater than message.len()’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and then fills the rest of the elements of the array cipher with zeros, and returns the size of the ciphertext including padding bits in bytes.
  • The size of the area for ciphertext should be prepared to be (message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.".to_string();
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_string_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.".to_string();
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_string_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
println!();
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.".to_string();
let mut cipher = [0_u8; 64];
taes.encrypt_string_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.".to_string();
let mut cipher = [0_u8; 56];
tdes.encrypt_string_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 271)
258fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()
259{
260    println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()");
261    use std::io::Write;
262    use std::fmt::Write as _;
263    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
264
265    // TDES case
266    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269    let message = "In the beginning God created the heavens and the earth.".to_string();
270    let mut cipher = [0_u8; 56];
271    tdes.encrypt_string_into_array(&message, &mut cipher);
272    print!("C =\t");
273    for c in cipher.clone()
274        { print!("{:02X} ", c); }
275    println!();
276    let mut txt = String::new();
277    for c in cipher.clone()
278        { write!(txt, "{:02X} ", c); }
279    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280    println!("-------------------------------");
281}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 289)
274fn bigcryptor128_encrypt_string_with_padding_iso_ecb_into_array()
275{
276    println!("bigcryptor128_encrypt_string_with_padding_iso_ecb_into_array()");
277    use std::io::Write;
278    use std::fmt::Write as _;
279    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
280
281    // TAES_128 case
282    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
283                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
284                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
285    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
286    println!("IV =	{:#034X}", iv);
287    let message = "In the beginning God created the heavens and the earth.".to_string();
288    let mut cipher = [0_u8; 64];
289    taes.encrypt_string_into_array(&message, &mut cipher);
290    print!("C =\t");
291    for c in cipher.clone()
292        { print!("{:02X} ", c); }
293    println!();
294    let mut txt = String::new();
295    for c in cipher.clone()
296        { write!(txt, "{:02X} ", c); }
297    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
298    println!("-------------------------------");
299}
examples/aes_ecb_iso_examples.rs (line 1009)
994fn aes_encrypt_string_with_padding_iso_ecb_into_array()
995{
996    println!("aes_encrypt_string_with_padding_iso_ecb_into_array()");
997    use std::io::Write;
998    use std::fmt::Write as _;
999    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1000
1001    // Normal case for AES-128
1002    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1003    println!("K =\t{:#016X}", key);
1004    let mut a_aes = AES_128::new_with_key_u128(key);
1005
1006    let message = "In the beginning God created the heavens and the earth.".to_string();
1007    println!("M =\t{}", message);
1008    let mut cipher = [0_u8; 64];
1009    a_aes.encrypt_string_into_array(&message, &mut cipher);
1010    print!("C =\t");
1011    for c in cipher.clone()
1012        { print!("{:02X} ", c); }
1013    println!();
1014    let mut txt = String::new();
1015    for c in cipher.clone()
1016        { write!(txt, "{:02X} ", c); }
1017    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1018    println!();
1019
1020    // Normal case for AES-192
1021    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1022    print!("K =\t");
1023    for i in 0..24
1024        { print!("{:02X}", key[i]); }
1025    println!();
1026    let mut a_aes = AES_192::new_with_key(&key);
1027
1028    let message = "In the beginning God created the heavens and the earth.".to_string();
1029    println!("M =\t{}", message);
1030    let mut cipher = [0_u8; 64];
1031    a_aes.encrypt_string_into_array(&message, &mut cipher);
1032    print!("C =\t");
1033    for c in cipher.clone()
1034        { print!("{:02X} ", c); }
1035    println!();
1036    let mut txt = String::new();
1037    for c in cipher.clone()
1038        { write!(txt, "{:02X} ", c); }
1039    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1040    println!();
1041
1042    // Normal case for AES-256
1043    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1044    print!("K =\t");
1045    for i in 0..32
1046        { print!("{:02X}", key[i]); }
1047    println!();
1048    let mut a_aes = AES_256::new_with_key(&key);
1049
1050    let message = "In the beginning God created the heavens and the earth.".to_string();
1051    println!("M =\t{}", message);
1052    let mut cipher = [0_u8; 64];
1053    a_aes.encrypt_string_into_array(&message, &mut cipher);
1054    print!("C =\t");
1055    for c in cipher.clone()
1056        { print!("{:02X} ", c); }
1057    println!();
1058    let mut txt = String::new();
1059    for c in cipher.clone()
1060        { write!(txt, "{:02X} ", c); }
1061    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1062    println!();
1063
1064    // Normal case for Rijndael-256-256
1065    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1066    print!("K =\t");
1067    for i in 0..32
1068        { print!("{:02X}", key[i]); }
1069    println!();
1070    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1071
1072    let message = "In the beginning God created the heavens and the earth.".to_string();
1073    println!("M =\t{}", message);
1074    let mut cipher = [0_u8; 64];
1075    a_rijndael.encrypt_string_into_array(&message, &mut cipher);
1076    print!("C =\t");
1077    for c in cipher.clone()
1078        { print!("{:02X} ", c); }
1079    println!();
1080    let mut txt = String::new();
1081    for c in cipher.clone()
1082        { write!(txt, "{:02X} ", c); }
1083    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1084    println!();
1085
1086    // Normal case for Rijndael-512-512 for post-quantum
1087    use cryptocol::number::SharedArrays;
1088    use cryptocol::hash::SHA3_512;
1089    let mut sha3 = SHA3_512::new();
1090    sha3.absorb_str("Post-quantum");
1091    let key: [u8; 64] = sha3.get_hash_value_in_array();
1092    print!("K =\t");
1093    for i in 0..64
1094        { print!("{:02X}", key[i]); }
1095    println!();
1096    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1097    let message = "In the beginning God created the heavens and the earth.".to_string();
1098    println!("M =\t{}", message);
1099    let mut cipher = [0_u8; 64];
1100    a_rijndael.encrypt_string_into_array(&message, &mut cipher);
1101    print!("C =\t");
1102    for c in cipher.clone()
1103        { print!("{:02X} ", c); }
1104    println!();
1105    let mut txt = String::new();
1106    for c in cipher.clone()
1107        { write!(txt, "{:02X} ", c); }
1108    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1109    println!("-------------------------------");
1110}
examples/des_ecb_iso_examples.rs (line 1452)
1437fn des_encrypt_string_with_padding_iso_ecb_into_array()
1438{
1439    println!("des_encrypt_string_with_padding_iso_ecb_into_array()");
1440    use std::io::Write;
1441    use std::fmt::Write as _;
1442    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1443
1444    // Normal case
1445    let key = 0x_1234567890ABCDEF_u64;
1446    println!("K =\t{:#016X}", key);
1447    let mut a_des = DES::new_with_key_u64(key);
1448
1449    let message = "In the beginning God created the heavens and the earth.".to_string();
1450    println!("M =\t{}", message);
1451    let mut cipher = [0_u8; 56];
1452    a_des.encrypt_string_into_array(&message, &mut cipher);
1453    print!("C (16 rounds) =\t");
1454    for c in cipher.clone()
1455        { print!("{:02X} ", c); }
1456    println!();
1457    let mut txt = String::new();
1458    for c in cipher.clone()
1459        { write!(txt, "{:02X} ", c); }
1460    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1461    println!();
1462
1463    // Expanded case for 128 rounds
1464    let key = 0x_1234567890ABCDEF_u64;
1465    println!("K =\t{:#016X}", key);
1466    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1467
1468    let message = "In the beginning God created the heavens and the earth.".to_string();
1469    println!("M =\t{}", message);
1470    let mut cipher = [0_u8; 56];
1471    a_des.encrypt_string_into_array(&message, &mut cipher);
1472    print!("C (128 rounds) =\t");
1473    for c in cipher.clone()
1474        { print!("{:02X} ", c); }
1475    println!();
1476    let mut txt = String::new();
1477    for c in cipher.clone()
1478        { write!(txt, "{:02X} ", c); }
1479    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1480    println!();
1481
1482    // Expanded case for 0 rounds which means that key is meaningless
1483    let key1 = 0x_1234567890ABCDEF_u64;
1484    let key2 = 0_u64;
1485    println!("K =\t{:#016X}", key);
1486    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1487    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1488
1489    let message = "In the beginning God created the heavens and the earth.".to_string();
1490    println!("M =\t{}", message);
1491    let mut cipher1 = [0_u8; 56];
1492    let mut cipher2 = [0_u8; 56];
1493    c_des.encrypt_string_into_array(&message, &mut cipher1);
1494    d_des.encrypt_string_into_array(&message, &mut cipher2);
1495    print!("C (0 rounds) =\t");
1496    for c in cipher1.clone()
1497        { print!("{:02X} ", c); }
1498    println!();
1499    let mut txt = String::new();
1500    for c in cipher1.clone()
1501        { write!(txt, "{:02X} ", c); }
1502    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1503    print!("D (0 rounds) =\t");
1504    for c in cipher2.clone()
1505        { print!("{:02X} ", c); }
1506    println!();
1507    let mut txt = String::new();
1508    for c in cipher2.clone()
1509        { write!(txt, "{:02X} ", c); }
1510    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1511    println!();
1512
1513    // Normal case for the message of 0 bytes
1514    let key = 0x_1234567890ABCDEF_u64;
1515    println!("K =\t{:#016X}", key);
1516    let mut a_des = DES::new_with_key_u64(key);
1517
1518    let message = "".to_string();
1519    println!("M =\t{}", message);
1520    let mut cipher = [0_u8; 8];
1521    a_des.encrypt_string_into_array(&message, &mut cipher);
1522    print!("C =\t");
1523    for c in cipher.clone()
1524        { print!("{:02X} ", c); }
1525    println!();
1526    let mut txt = String::new();
1527    for c in cipher.clone()
1528        { write!(txt, "{:02X} ", c); }
1529    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1530    println!();
1531
1532    // Normal case for the message shorter than 8 bytes
1533    let key = 0x_1234567890ABCDEF_u64;
1534    println!("K =\t{:#016X}", key);
1535    let mut a_des = DES::new_with_key_u64(key);
1536
1537    let message = "7 bytes".to_string();
1538    println!("M =\t{}", message);
1539    let mut cipher = [0_u8; 8];
1540    a_des.encrypt_string_into_array(&message, &mut cipher);
1541    print!("C =\t");
1542    for c in cipher.clone()
1543        { print!("{:02X} ", c); }
1544    println!();
1545    let mut txt = String::new();
1546    for c in cipher.clone()
1547        { write!(txt, "{:02X} ", c); }
1548    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1549    println!();
1550
1551    // Normal case for the message of 8 bytes
1552    let key = 0x_1234567890ABCDEF_u64;
1553    println!("K =\t{:#016X}", key);
1554    let mut a_des = DES::new_with_key_u64(key);
1555
1556    let message = "I am OK.".to_string();
1557    println!("M =\t{}", message);
1558    let mut cipher = [0_u8; 16];
1559    a_des.encrypt_string_into_array(&message, &mut cipher);
1560    print!("C =\t");
1561    for c in cipher.clone()
1562        { print!("{:02X} ", c); }
1563    println!();
1564    let mut txt = String::new();
1565    for c in cipher.clone()
1566        { write!(txt, "{:02X} ", c); }
1567    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1568    println!();
1569
1570    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1571    let key = 0x_1234567890ABCDEF_u64;
1572    println!("K =\t{:#016X}", key);
1573    let mut a_des = DES::new_with_key_u64(key);
1574
1575    let message = "PARK Youngho".to_string();
1576    println!("M =\t{}", message);
1577    let mut cipher = [0_u8; 16];
1578    a_des.encrypt_string_into_array(&message, &mut cipher);
1579    print!("C =\t");
1580    for c in cipher.clone()
1581        { print!("{:02X} ", c); }
1582    println!();
1583    let mut txt = String::new();
1584    for c in cipher.clone()
1585        { write!(txt, "{:02X} ", c); }
1586    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1587    println!();
1588
1589    // Normal case for the message of 16 bytes
1590    let key = 0x_1234567890ABCDEF_u64;
1591    println!("K =\t{:#016X}", key);
1592    let mut a_des = DES::new_with_key_u64(key);
1593
1594    let message = "고맙습니다.".to_string();
1595    println!("M =\t{}", message);
1596    let mut cipher = [0_u8; 24];
1597    a_des.encrypt_string_into_array(&message, &mut cipher);
1598    print!("C =\t");
1599    for c in cipher.clone()
1600        { print!("{:02X} ", c); }
1601    println!();
1602    let mut txt = String::new();
1603    for c in cipher.clone()
1604        { write!(txt, "{:02X} ", c); }
1605    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1606    println!("-------------------------------");
1607}
Source

fn encrypt_vec<U>(&mut self, message: &Vec<U>, cipher: *mut u8) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data stored in a Vec<U> object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • message is an immutable reference to Vec<U> object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable pointer to u8 which is *mut u8, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_vec_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • The size of the memory area which starts at cipher is assumed to be enough to store the ciphertext.
  • The size of the area for ciphertext should be prepared to be (size_of::<U>() * message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • If message is an empty Vec<U> object Vec::<U>::new(), only padding bytes will be encrypted, and stored in the memory area that starts from cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 64];
a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 56];
a_des.encrypt_vec(&message, cipher.as_mut_ptr());
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 64];
taes.encrypt_vec(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 56];
tdes.encrypt_vec(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 298)
283fn bigcryptor64_encrypt_vec_with_padding_iso_ecb()
284{
285    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb()");
286    use std::io::Write;
287    use std::fmt::Write as _;
288    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
289
290    // TDES case
291    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294    let message = "In the beginning God created the heavens and the earth.";
295    println!("M =\t{}", message);
296    let message = unsafe { message.to_string().as_mut_vec().clone() };
297    let mut cipher = [0_u8; 56];
298    tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299    print!("C =\t");
300    for c in cipher.clone()
301        { print!("{:02X} ", c); }
302    println!();
303    let mut txt = String::new();
304    for c in cipher.clone()
305        { write!(txt, "{:02X} ", c); }
306    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307    println!("-------------------------------");
308}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 318)
301fn bigcryptor128_encrypt_vec_with_padding_iso_ecb()
302{
303    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb()");
304    use std::io::Write;
305    use std::fmt::Write as _;
306    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
307
308    // TAES_128 case
309    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
310                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
311                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
312    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
313    println!("IV =	{:#034X}", iv);
314    let message = "In the beginning God created the heavens and the earth.";
315    println!("M =\t{}", message);
316    let message = unsafe { message.to_string().as_mut_vec().clone() };
317    let mut cipher = [0_u8; 64];
318    taes.encrypt_vec(&message, cipher.as_mut_ptr());
319    print!("C =\t");
320    for c in cipher.clone()
321        { print!("{:02X} ", c); }
322    println!();
323    let mut txt = String::new();
324    for c in cipher.clone()
325        { write!(txt, "{:02X} ", c); }
326    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
327    println!("-------------------------------");
328}
examples/aes_ecb_iso_examples.rs (line 1128)
1112fn aes_encrypt_vec_with_padding_iso_ecb()
1113{
1114    println!("aes_encrypt_vec_with_padding_iso_ecb()");
1115    use std::io::Write;
1116    use std::fmt::Write as _;
1117    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1118
1119    // Normal case for AES-128
1120    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1121    println!("K =\t{:#016X}", key);
1122    let mut a_aes = AES_128::new_with_key_u128(key);
1123
1124    let message = "In the beginning God created the heavens and the earth.";
1125    println!("M =\t{}", message);
1126    let message = unsafe { message.to_string().as_mut_vec().clone() };
1127    let mut cipher = [0_u8; 64];
1128    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1129    print!("C =\t");
1130    for c in cipher.clone()
1131        { print!("{:02X} ", c); }
1132    println!();
1133    let mut txt = String::new();
1134    for c in cipher.clone()
1135        { write!(txt, "{:02X} ", c); }
1136    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1137    println!();
1138
1139    // Normal case for AES-192
1140    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1141    print!("K =\t");
1142    for i in 0..24
1143        { print!("{:02X}", key[i]); }
1144    println!();
1145    let mut a_aes = AES_192::new_with_key(&key);
1146
1147    let message = "In the beginning God created the heavens and the earth.";
1148    println!("M =\t{}", message);
1149    let message = unsafe { message.to_string().as_mut_vec().clone() };
1150    let mut cipher = [0_u8; 64];
1151    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1152    print!("C =\t");
1153    for c in cipher.clone()
1154        { print!("{:02X} ", c); }
1155    println!();
1156    let mut txt = String::new();
1157    for c in cipher.clone()
1158        { write!(txt, "{:02X} ", c); }
1159    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1160    println!();
1161
1162    // Normal case for AES-256
1163    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1164    print!("K =\t");
1165    for i in 0..32
1166        { print!("{:02X}", key[i]); }
1167    println!();
1168    let mut a_aes = AES_256::new_with_key(&key);
1169
1170    let message = "In the beginning God created the heavens and the earth.";
1171    println!("M =\t{}", message);
1172    let message = unsafe { message.to_string().as_mut_vec().clone() };
1173    let mut cipher = [0_u8; 64];
1174    a_aes.encrypt_vec(&message, cipher.as_mut_ptr());
1175    print!("C =\t");
1176    for c in cipher.clone()
1177        { print!("{:02X} ", c); }
1178    println!();
1179    let mut txt = String::new();
1180    for c in cipher.clone()
1181        { write!(txt, "{:02X} ", c); }
1182    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1183    println!();
1184
1185    // Normal case for Rijndael-256-256
1186    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1187    print!("K =\t");
1188    for i in 0..32
1189        { print!("{:02X}", key[i]); }
1190    println!();
1191    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1192
1193    let message = "In the beginning God created the heavens and the earth.";
1194    println!("M =\t{}", message);
1195    let message = unsafe { message.to_string().as_mut_vec().clone() };
1196    let mut cipher = [0_u8; 64];
1197    a_rijndael.encrypt_vec(&message, cipher.as_mut_ptr());
1198    print!("C =\t");
1199    for c in cipher.clone()
1200        { print!("{:02X} ", c); }
1201    println!();
1202    let mut txt = String::new();
1203    for c in cipher.clone()
1204        { write!(txt, "{:02X} ", c); }
1205    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1206    println!();
1207
1208    // Normal case for Rijndael-512-512 for post-quantum
1209    use cryptocol::number::SharedArrays;
1210    use cryptocol::hash::SHA3_512;
1211    let mut sha3 = SHA3_512::new();
1212    sha3.absorb_str("Post-quantum");
1213    let key: [u8; 64] = sha3.get_hash_value_in_array();
1214    print!("K =\t");
1215    for i in 0..64
1216        { print!("{:02X}", key[i]); }
1217    println!();
1218    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1219    let message = "In the beginning God created the heavens and the earth.";
1220    println!("M =\t{}", message);
1221    let message = unsafe { message.to_string().as_mut_vec().clone() };
1222    let mut cipher = [0_u8; 64];
1223    a_rijndael.encrypt_vec(&message, cipher.as_mut_ptr());
1224    print!("C =\t");
1225    for c in cipher.clone()
1226        { print!("{:02X} ", c); }
1227    println!();
1228    let mut txt = String::new();
1229    for c in cipher.clone()
1230        { write!(txt, "{:02X} ", c); }
1231    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1232    println!("-------------------------------");
1233}
examples/des_ecb_iso_examples.rs (line 1625)
1609fn des_encrypt_vec_with_padding_iso_ecb()
1610{
1611    println!("des_encrypt_vec_with_padding_iso_ecb()");
1612    use std::io::Write;
1613    use std::fmt::Write as _;
1614    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1615
1616    // Normal case
1617    let key = 0x_1234567890ABCDEF_u64;
1618    println!("K =\t{:#016X}", key);
1619    let mut a_des = DES::new_with_key_u64(key);
1620
1621    let message = "In the beginning God created the heavens and the earth.";
1622    println!("M =\t{}", message);
1623    let message = unsafe { message.to_string().as_mut_vec().clone() };
1624    let mut cipher = [0_u8; 56];
1625    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1626    print!("C (16 rounds) =\t");
1627    for c in cipher.clone()
1628        { print!("{:02X} ", c); }
1629    println!();
1630    let mut txt = String::new();
1631    for c in cipher.clone()
1632        { write!(txt, "{:02X} ", c); }
1633    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1634    println!();
1635
1636    // Expanded case for 128 rounds
1637    let key = 0x_1234567890ABCDEF_u64;
1638    println!("K =\t{:#016X}", key);
1639    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1640
1641    let message = "In the beginning God created the heavens and the earth.";
1642    println!("M =\t{}", message);
1643    let message = unsafe { message.to_string().as_mut_vec().clone() };
1644    let mut cipher = [0_u8; 56];
1645    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1646    print!("C (128 rounds) =\t");
1647    for c in cipher.clone()
1648        { print!("{:02X} ", c); }
1649    println!();
1650    let mut txt = String::new();
1651    for c in cipher.clone()
1652        { write!(txt, "{:02X} ", c); }
1653    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1654    println!();
1655
1656    // Expanded case for 0 rounds which means that key is meaningless
1657    let key1 = 0x_1234567890ABCDEF_u64;
1658    let key2 = 0_u64;
1659    println!("K1 =\t{:#016X}", key1);
1660    println!("K2 =\t{:#016X}", key2);
1661    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1662    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1663
1664    let message = "In the beginning God created the heavens and the earth.";
1665    println!("M =\t{}", message);
1666    let message = unsafe { message.to_string().as_mut_vec().clone() };
1667    let mut cipher1 = [0_u8; 56];
1668    let mut cipher2 = [0_u8; 56];
1669    c_des.encrypt_vec(&message, cipher1.as_mut_ptr());
1670    d_des.encrypt_vec(&message, cipher2.as_mut_ptr());
1671    print!("C (0 rounds) =\t");
1672    for c in cipher1.clone()
1673        { print!("{:02X} ", c); }
1674    println!();
1675    let mut txt = String::new();
1676    for c in cipher1.clone()
1677        { write!(txt, "{:02X} ", c); }
1678    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1679    print!("D (0 rounds) =\t");
1680    for c in cipher2.clone()
1681        { print!("{:02X} ", c); }
1682    println!();
1683    let mut txt = String::new();
1684    for c in cipher2.clone()
1685        { write!(txt, "{:02X} ", c); }
1686    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1687    println!();
1688
1689    // Normal case for the message of 0 bytes
1690    let key = 0x_1234567890ABCDEF_u64;
1691    println!("K =\t{:#016X}", key);
1692    let mut a_des = DES::new_with_key_u64(key);
1693
1694    let message = "";
1695    println!("M =\t{}", message);
1696    let message = unsafe { message.to_string().as_mut_vec().clone() };
1697    let mut cipher = [0_u8; 8];
1698    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1699    print!("C =\t");
1700    for c in cipher.clone()
1701        { print!("{:02X} ", c); }
1702    println!();
1703    let mut txt = String::new();
1704    for c in cipher.clone()
1705        { write!(txt, "{:02X} ", c); }
1706    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1707    println!();
1708
1709    // Normal case for the message shorter than 8 bytes
1710    let key = 0x_1234567890ABCDEF_u64;
1711    println!("K =\t{:#016X}", key);
1712    let mut a_des = DES::new_with_key_u64(key);
1713
1714    let message = "7 bytes";
1715    println!("M =\t{}", message);
1716    let message = unsafe { message.to_string().as_mut_vec().clone() };
1717    let mut cipher = [0_u8; 8];
1718    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1719    print!("C =\t");
1720    for c in cipher.clone()
1721        { print!("{:02X} ", c); }
1722    println!();
1723    let mut txt = String::new();
1724    for c in cipher.clone()
1725        { write!(txt, "{:02X} ", c); }
1726    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1727    println!();
1728
1729    // Normal case for the message of 8 bytes
1730    let key = 0x_1234567890ABCDEF_u64;
1731    println!("K =\t{:#016X}", key);
1732    let mut a_des = DES::new_with_key_u64(key);
1733
1734    let message = "I am OK.";
1735    println!("M =\t{}", message);
1736    let message = unsafe { message.to_string().as_mut_vec().clone() };
1737    let mut cipher = [0_u8; 16];
1738    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1739    print!("C =\t");
1740    for c in cipher.clone()
1741        { print!("{:02X} ", c); }
1742    println!();
1743    let mut txt = String::new();
1744    for c in cipher.clone()
1745        { write!(txt, "{:02X} ", c); }
1746    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1747    println!();
1748
1749    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1750    let key = 0x_1234567890ABCDEF_u64;
1751    println!("K =\t{:#016X}", key);
1752    let mut a_des = DES::new_with_key_u64(key);
1753
1754    let message = "PARK Youngho";
1755    println!("M =\t{}", message);
1756    let message = unsafe { message.to_string().as_mut_vec().clone() };
1757    let mut cipher = [0_u8; 16];
1758    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1759    print!("C =\t");
1760    for c in cipher.clone()
1761        { print!("{:02X} ", c); }
1762    println!();
1763    let mut txt = String::new();
1764    for c in cipher.clone()
1765        { write!(txt, "{:02X} ", c); }
1766    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1767    println!();
1768
1769
1770    // Normal case for the message of 16 bytes
1771    let key = 0x_1234567890ABCDEF_u64;
1772    println!("K =\t{:#016X}", key);
1773    let mut a_des = DES::new_with_key_u64(key);
1774
1775    let message = "고맙습니다.";
1776    println!("M =\t{}", message);
1777    let message = unsafe { message.to_string().as_mut_vec().clone() };
1778    let mut cipher = [0_u8; 24];
1779    a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1780    print!("C =\t");
1781    for c in cipher.clone()
1782        { print!("{:02X} ", c); }
1783    println!();
1784    let mut txt = String::new();
1785    for c in cipher.clone()
1786        { write!(txt, "{:02X} ", c); }
1787    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1788    println!("-------------------------------");
1789}
Source

fn encrypt_vec_into_vec<U, V>( &mut self, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Encrypts the data stored in a Vec<U> object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in Vec<V>.

§Arguments
  • message is an immutable reference to Vec<U> object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to Vec<U> object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is an empty Vec<U> object Vec::<U>::new(), only padding bytes will be encrypted, and stored in the Vec<U> object which is referred to as cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_vec_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = Vec::<u8>::new();
a_des.encrypt_vec_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = Vec::<u8>::new();
taes.encrypt_vec_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = Vec::<u8>::new();
tdes.encrypt_vec_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 325)
310fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()
311{
312    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()");
313    use std::io::Write;
314    use std::fmt::Write as _;
315    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
316
317    // TDES case
318    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321    let message = "In the beginning God created the heavens and the earth.";
322    println!("M =\t{}", message);
323    let message = unsafe { message.to_string().as_mut_vec().clone() };
324    let mut cipher = Vec::<u8>::new();
325    tdes.encrypt_vec_into_vec(&message, &mut cipher);
326    print!("C =\t");
327    for c in cipher.clone()
328        { print!("{:02X} ", c); }
329    println!();
330    let mut txt = String::new();
331    for c in cipher.clone()
332        { write!(txt, "{:02X} ", c); }
333    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334    println!("-------------------------------");
335}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 347)
330fn bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_vec()
331{
332    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_vec()");
333    use std::io::Write;
334    use std::fmt::Write as _;
335    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
336
337    // TAES_128 case
338    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
339                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
340                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
341    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
342    println!("IV =	{:#034X}", iv);
343    let message = "In the beginning God created the heavens and the earth.";
344    println!("M =\t{}", message);
345    let message = unsafe { message.to_string().as_mut_vec().clone() };
346    let mut cipher = Vec::<u8>::new();
347    taes.encrypt_vec_into_vec(&message, &mut cipher);
348    print!("C =\t");
349    for c in cipher.clone()
350        { print!("{:02X} ", c); }
351    println!();
352    let mut txt = String::new();
353    for c in cipher.clone()
354        { write!(txt, "{:02X} ", c); }
355    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
356    println!("-------------------------------");
357}
examples/aes_ecb_iso_examples.rs (line 1251)
1235fn aes_encrypt_vec_with_padding_iso_ecb_into_vec()
1236{
1237    println!("aes_encrypt_vec_with_padding_iso_ecb_into_vec()");
1238    use std::io::Write;
1239    use std::fmt::Write as _;
1240    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1241
1242    // Normal case for AES-128
1243    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1244    println!("K =\t{:#016X}", key);
1245    let mut a_aes = AES_128::new_with_key_u128(key);
1246
1247    let message = "In the beginning God created the heavens and the earth.";
1248    println!("M =\t{}", message);
1249    let message = unsafe { message.to_string().as_mut_vec().clone() };
1250    let mut cipher = Vec::<u8>::new();
1251    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1252    print!("C =\t");
1253    for c in cipher.clone()
1254        { print!("{:02X} ", c); }
1255    println!();
1256    let mut txt = String::new();
1257    for c in cipher.clone()
1258        { write!(txt, "{:02X} ", c); }
1259    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1260    println!();
1261
1262    // Normal case for AES-192
1263    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1264    print!("K =\t");
1265    for i in 0..24
1266        { print!("{:02X}", key[i]); }
1267    println!();
1268    let mut a_aes = AES_192::new_with_key(&key);
1269
1270    let message = "In the beginning God created the heavens and the earth.";
1271    println!("M =\t{}", message);
1272    let message = unsafe { message.to_string().as_mut_vec().clone() };
1273    let mut cipher = Vec::<u8>::new();
1274    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1275    print!("C =\t");
1276    for c in cipher.clone()
1277        { print!("{:02X} ", c); }
1278    println!();
1279    let mut txt = String::new();
1280    for c in cipher.clone()
1281        { write!(txt, "{:02X} ", c); }
1282    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1283    println!();
1284
1285    // Normal case for AES-256
1286    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1287    print!("K =\t");
1288    for i in 0..32
1289        { print!("{:02X}", key[i]); }
1290    println!();
1291    let mut a_aes = AES_256::new_with_key(&key);
1292
1293    let message = "In the beginning God created the heavens and the earth.";
1294    println!("M =\t{}", message);
1295    let message = unsafe { message.to_string().as_mut_vec().clone() };
1296    let mut cipher = Vec::<u8>::new();
1297    a_aes.encrypt_vec_into_vec(&message, &mut cipher);
1298    print!("C =\t");
1299    for c in cipher.clone()
1300        { print!("{:02X} ", c); }
1301    println!();
1302    let mut txt = String::new();
1303    for c in cipher.clone()
1304        { write!(txt, "{:02X} ", c); }
1305    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1306    println!();
1307
1308    // Normal case for Rijndael-256-256
1309    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1310    print!("K =\t");
1311    for i in 0..32
1312        { print!("{:02X}", key[i]); }
1313    println!();
1314    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1315
1316    let message = "In the beginning God created the heavens and the earth.";
1317    println!("M =\t{}", message);
1318    let message = unsafe { message.to_string().as_mut_vec().clone() };
1319    let mut cipher = Vec::<u8>::new();
1320    a_rijndael.encrypt_vec_into_vec(&message, &mut cipher);
1321    print!("C =\t");
1322    for c in cipher.clone()
1323        { print!("{:02X} ", c); }
1324    println!();
1325    let mut txt = String::new();
1326    for c in cipher.clone()
1327        { write!(txt, "{:02X} ", c); }
1328    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1329    println!();
1330
1331    // Normal case for Rijndael-512-512 for post-quantum
1332    use cryptocol::number::SharedArrays;
1333    use cryptocol::hash::SHA3_512;
1334    let mut sha3 = SHA3_512::new();
1335    sha3.absorb_str("Post-quantum");
1336    let key: [u8; 64] = sha3.get_hash_value_in_array();
1337    print!("K =\t");
1338    for i in 0..64
1339        { print!("{:02X}", key[i]); }
1340    println!();
1341    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1342    let message = "In the beginning God created the heavens and the earth.";
1343    println!("M =\t{}", message);
1344    let message = unsafe { message.to_string().as_mut_vec().clone() };
1345    let mut cipher = Vec::<u8>::new();
1346    a_rijndael.encrypt_vec_into_vec(&message, &mut cipher);
1347    print!("C =\t");
1348    for c in cipher.clone()
1349        { print!("{:02X} ", c); }
1350    println!();
1351    let mut txt = String::new();
1352    for c in cipher.clone()
1353        { write!(txt, "{:02X} ", c); }
1354    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1355    println!("-------------------------------");
1356}
examples/des_ecb_iso_examples.rs (line 1807)
1791fn des_encrypt_vec_with_padding_iso_ecb_into_vec()
1792{
1793    println!("des_encrypt_vec_with_padding_iso_ecb_into_vec()");
1794    use std::io::Write;
1795    use std::fmt::Write as _;
1796    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1797
1798    // Normal case
1799    let key = 0x_1234567890ABCDEF_u64;
1800    println!("K =\t{:#016X}", key);
1801    let mut a_des = DES::new_with_key_u64(key);
1802
1803    let message = "In the beginning God created the heavens and the earth.";
1804    println!("M =\t{}", message);
1805    let message = unsafe { message.to_string().as_mut_vec().clone() };
1806    let mut cipher = Vec::<u8>::new();
1807    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1808    print!("C (16 rounds) =\t");
1809    for c in cipher.clone()
1810        { print!("{:02X} ", c); }
1811    println!();
1812    let mut txt = String::new();
1813    for c in cipher.clone()
1814        { write!(txt, "{:02X} ", c); }
1815    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1816    println!();
1817
1818    // Expanded case for 128 rounds
1819    let key = 0x_1234567890ABCDEF_u64;
1820    println!("K =\t{:#016X}", key);
1821    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1822
1823    let message = "In the beginning God created the heavens and the earth.";
1824    println!("M =\t{}", message);
1825    let message = unsafe { message.to_string().as_mut_vec().clone() };
1826    let mut cipher = Vec::<u8>::new();
1827    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1828    print!("C (128 rounds) =\t");
1829    for c in cipher.clone()
1830        { print!("{:02X} ", c); }
1831    println!();
1832    let mut txt = String::new();
1833    for c in cipher.clone()
1834        { write!(txt, "{:02X} ", c); }
1835    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1836    println!();
1837
1838    // Expanded case for 0 rounds which means that key is meaningless
1839    let key1 = 0x_1234567890ABCDEF_u64;
1840    let key2 = 0_u64;
1841    println!("K1 =\t{:#016X}", key1);
1842    println!("K2 =\t{:#016X}", key2);
1843    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1844    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1845
1846    let message = "In the beginning God created the heavens and the earth.";
1847    println!("M =\t{}", message);
1848    let message = unsafe { message.to_string().as_mut_vec().clone() };
1849
1850    let mut cipher1 = Vec::<u8>::new();
1851    let mut cipher2 = Vec::<u8>::new();
1852    c_des.encrypt_vec_into_vec(&message, &mut cipher1);
1853    d_des.encrypt_vec_into_vec(&message, &mut cipher2);
1854    print!("C (0 rounds) =\t");
1855    for c in cipher1.clone()
1856        { print!("{:02X} ", c); }
1857    println!();
1858    let mut txt = String::new();
1859    for c in cipher1.clone()
1860        { write!(txt, "{:02X} ", c); }
1861    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1862    print!("D (0 rounds) =\t");
1863    for c in cipher2.clone()
1864        { print!("{:02X} ", c); }
1865    println!();
1866    let mut txt = String::new();
1867    for c in cipher2.clone()
1868        { write!(txt, "{:02X} ", c); }
1869    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1870    println!();
1871
1872    // Normal case for the message of 0 bytes
1873    let key = 0x_1234567890ABCDEF_u64;
1874    println!("K =\t{:#016X}", key);
1875    let mut a_des = DES::new_with_key_u64(key);
1876
1877    let message = "";
1878    println!("M =\t{}", message);
1879    let message = unsafe { message.to_string().as_mut_vec().clone() };
1880    let mut cipher = Vec::<u8>::new();
1881    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1882    print!("C =\t");
1883    for c in cipher.clone()
1884        { print!("{:02X} ", c); }
1885    println!();
1886    let mut txt = String::new();
1887    for c in cipher.clone()
1888        { write!(txt, "{:02X} ", c); }
1889    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1890    println!();
1891
1892    // Normal case for the message shorter than 8 bytes
1893    let key = 0x_1234567890ABCDEF_u64;
1894    println!("K =\t{:#016X}", key);
1895    let mut a_des = DES::new_with_key_u64(key);
1896
1897    let message = "7 bytes";
1898    println!("M =\t{}", message);
1899    let message = unsafe { message.to_string().as_mut_vec().clone() };
1900    let mut cipher = Vec::<u8>::new();
1901    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1902    print!("C =\t");
1903    for c in cipher.clone()
1904        { print!("{:02X} ", c); }
1905    println!();
1906    let mut txt = String::new();
1907    for c in cipher.clone()
1908        { write!(txt, "{:02X} ", c); }
1909    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1910    println!();
1911
1912    // Normal case for the message of 8 bytes
1913    let key = 0x_1234567890ABCDEF_u64;
1914    println!("K =\t{:#016X}", key);
1915    let mut a_des = DES::new_with_key_u64(key);
1916
1917    let message = "I am OK.";
1918    println!("M =\t{}", message);
1919    let message = unsafe { message.to_string().as_mut_vec().clone() };
1920    let mut cipher = Vec::<u8>::new();
1921    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1922    print!("C =\t");
1923    for c in cipher.clone()
1924        { print!("{:02X} ", c); }
1925    println!();
1926    let mut txt = String::new();
1927    for c in cipher.clone()
1928        { write!(txt, "{:02X} ", c); }
1929    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1930    println!();
1931
1932    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1933    let key = 0x_1234567890ABCDEF_u64;
1934    println!("K =\t{:#016X}", key);
1935    let mut a_des = DES::new_with_key_u64(key);
1936
1937    let message = "PARK Youngho";
1938    println!("M =\t{}", message);
1939    let message = unsafe { message.to_string().as_mut_vec().clone() };
1940    let mut cipher = Vec::<u8>::new();
1941    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1942    print!("C =\t");
1943    for c in cipher.clone()
1944        { print!("{:02X} ", c); }
1945    println!();
1946    let mut txt = String::new();
1947    for c in cipher.clone()
1948        { write!(txt, "{:02X} ", c); }
1949    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1950    println!();
1951
1952
1953    // Normal case for the message of 16 bytes
1954    let key = 0x_1234567890ABCDEF_u64;
1955    println!("K =\t{:#016X}", key);
1956    let mut a_des = DES::new_with_key_u64(key);
1957
1958    let message = "고맙습니다.";
1959    println!("M =\t{}", message);
1960    let message = unsafe { message.to_string().as_mut_vec().clone() };
1961    let mut cipher = Vec::<u8>::new();
1962    a_des.encrypt_vec_into_vec(&message, &mut cipher);
1963    print!("C =\t");
1964    for c in cipher.clone()
1965        { print!("{:02X} ", c); }
1966    println!();
1967    let mut txt = String::new();
1968    for c in cipher.clone()
1969        { write!(txt, "{:02X} ", c); }
1970    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1971    println!("-------------------------------");
1972}
Source

fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Encrypts the data stored in a Vec<U> object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in array [V; N].

§Arguments
  • message is an immutable reference to Vec<U> object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to an array [U; N] object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is an empty Vec<U> object Vec::<U>::new(), only padding bytes will be encrypted, and stored in the array [U; N] object cipher.
  • If size_of::<V>() * N is less than size_of::<U>() * message.len()’s next multiple of size_of::<T>(), this method does not perform encryption but returns zero.
  • If size_of::<V>() * N is equal to size_of::<U>() * message.len()’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and returns the size of the ciphertext including padding bits in bytes.
  • If size_of::<V>() * N is greater than size_of::<U>() * message.len()’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted data, and then fills the rest of the elements of the array cipher with zeros, and returns the size of the ciphertext including padding bits in bytes.
  • The size of the area for ciphertext should be prepared to be (size_of::<U>() * message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 64];
a_aes.encrypt_vec_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 56];
a_des.encrypt_vec_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 64];
taes.encrypt_vec_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let message = unsafe { message.to_string().as_mut_vec().clone() };
let mut cipher = [0_u8; 56];
tdes.encrypt_vec_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 352)
337fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()
338{
339    println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()");
340    use std::io::Write;
341    use std::fmt::Write as _;
342    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
343
344    // TDES case
345    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348    let message = "In the beginning God created the heavens and the earth.";
349    println!("M =\t{}", message);
350    let message = unsafe { message.to_string().as_mut_vec().clone() };
351    let mut cipher = [0_u8; 56];
352    tdes.encrypt_vec_into_array(&message, &mut cipher);
353    print!("C =\t");
354    for c in cipher.clone()
355        { print!("{:02X} ", c); }
356    println!();
357    let mut txt = String::new();
358    for c in cipher.clone()
359        { write!(txt, "{:02X} ", c); }
360    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361    println!("-------------------------------");
362}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 376)
359fn bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_array()
360{
361    println!("bigcryptor128_encrypt_vec_with_padding_iso_ecb_into_array()");
362    use std::io::Write;
363    use std::fmt::Write as _;
364    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
365
366    // TAES_128 case
367    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
368                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
369                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
370    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
371    println!("IV =	{:#034X}", iv);
372    let message = "In the beginning God created the heavens and the earth.";
373    println!("M =\t{}", message);
374    let message = unsafe { message.to_string().as_mut_vec().clone() };
375    let mut cipher = [0_u8; 64];
376    taes.encrypt_vec_into_array(&message, &mut cipher);
377    print!("C =\t");
378    for c in cipher.clone()
379        { print!("{:02X} ", c); }
380    println!();
381    let mut txt = String::new();
382    for c in cipher.clone()
383        { write!(txt, "{:02X} ", c); }
384    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
385    println!("-------------------------------");
386}
examples/aes_ecb_iso_examples.rs (line 1374)
1358fn aes_encrypt_vec_with_padding_iso_ecb_into_array()
1359{
1360    println!("aes_encrypt_vec_with_padding_iso_ecb_into_array()");
1361    use std::io::Write;
1362    use std::fmt::Write as _;
1363    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1364
1365    // Normal case for AES-128
1366    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1367    println!("K =\t{:#016X}", key);
1368    let mut a_aes = AES_128::new_with_key_u128(key);
1369
1370    let message = "In the beginning God created the heavens and the earth.";
1371    println!("M =\t{}", message);
1372    let message = unsafe { message.to_string().as_mut_vec().clone() };
1373    let mut cipher = [0_u8; 64];
1374    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1375    print!("C =\t");
1376    for c in cipher.clone()
1377        { print!("{:02X} ", c); }
1378    println!();
1379    let mut txt = String::new();
1380    for c in cipher.clone()
1381        { write!(txt, "{:02X} ", c); }
1382    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1383    println!();
1384
1385    // Normal case for AES-192
1386    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1387    print!("K =\t");
1388    for i in 0..24
1389        { print!("{:02X}", key[i]); }
1390    println!();
1391    let mut a_aes = AES_192::new_with_key(&key);
1392
1393    let message = "In the beginning God created the heavens and the earth.";
1394    println!("M =\t{}", message);
1395    let message = unsafe { message.to_string().as_mut_vec().clone() };
1396    let mut cipher = [0_u8; 64];
1397    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1398    print!("C =\t");
1399    for c in cipher.clone()
1400        { print!("{:02X} ", c); }
1401    println!();
1402    let mut txt = String::new();
1403    for c in cipher.clone()
1404        { write!(txt, "{:02X} ", c); }
1405    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1406    println!();
1407
1408    // Normal case for AES-256
1409    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1410    print!("K =\t");
1411    for i in 0..32
1412        { print!("{:02X}", key[i]); }
1413    println!();
1414    let mut a_aes = AES_256::new_with_key(&key);
1415
1416    let message = "In the beginning God created the heavens and the earth.";
1417    println!("M =\t{}", message);
1418    let message = unsafe { message.to_string().as_mut_vec().clone() };
1419    let mut cipher = [0_u8; 64];
1420    a_aes.encrypt_vec_into_array(&message, &mut cipher);
1421    print!("C =\t");
1422    for c in cipher.clone()
1423        { print!("{:02X} ", c); }
1424    println!();
1425    let mut txt = String::new();
1426    for c in cipher.clone()
1427        { write!(txt, "{:02X} ", c); }
1428    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1429    println!();
1430
1431    // Normal case for Rijndael-256-256
1432    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1433    print!("K =\t");
1434    for i in 0..32
1435        { print!("{:02X}", key[i]); }
1436    println!();
1437    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1438
1439    let message = "In the beginning God created the heavens and the earth.";
1440    println!("M =\t{}", message);
1441    let message = unsafe { message.to_string().as_mut_vec().clone() };
1442    let mut cipher = [0_u8; 64];
1443    a_rijndael.encrypt_vec_into_array(&message, &mut cipher);
1444    print!("C =\t");
1445    for c in cipher.clone()
1446        { print!("{:02X} ", c); }
1447    println!();
1448    let mut txt = String::new();
1449    for c in cipher.clone()
1450        { write!(txt, "{:02X} ", c); }
1451    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1452    println!();
1453
1454    // Normal case for Rijndael-512-512 for post-quantum
1455    use cryptocol::number::SharedArrays;
1456    use cryptocol::hash::SHA3_512;
1457    let mut sha3 = SHA3_512::new();
1458    sha3.absorb_str("Post-quantum");
1459    let key: [u8; 64] = sha3.get_hash_value_in_array();
1460    print!("K =\t");
1461    for i in 0..64
1462        { print!("{:02X}", key[i]); }
1463    println!();
1464    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1465    let message = "In the beginning God created the heavens and the earth.";
1466    println!("M =\t{}", message);
1467    let message = unsafe { message.to_string().as_mut_vec().clone() };
1468    let mut cipher = [0_u8; 64];
1469    a_rijndael.encrypt_vec_into_array(&message, &mut cipher);
1470    print!("C =\t");
1471    for c in cipher.clone()
1472        { print!("{:02X} ", c); }
1473    println!();
1474    let mut txt = String::new();
1475    for c in cipher.clone()
1476        { write!(txt, "{:02X} ", c); }
1477    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1478    println!("-------------------------------");
1479}
examples/des_ecb_iso_examples.rs (line 1990)
1974fn des_encrypt_vec_with_padding_iso_ecb_into_array()
1975{
1976    println!("des_encrypt_vec_with_padding_iso_ecb_into_array()");
1977    use std::io::Write;
1978    use std::fmt::Write as _;
1979    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1980
1981    // Normal case
1982    let key = 0x_1234567890ABCDEF_u64;
1983    println!("K =\t{:#016X}", key);
1984    let mut a_des = DES::new_with_key_u64(key);
1985
1986    let message = "In the beginning God created the heavens and the earth.";
1987    println!("M =\t{}", message);
1988    let message = unsafe { message.to_string().as_mut_vec().clone() };
1989    let mut cipher = [0_u8; 56];
1990    a_des.encrypt_vec_into_array(&message, &mut cipher);
1991    print!("C (16 rounds) =\t");
1992    for c in cipher.clone()
1993        { print!("{:02X} ", c); }
1994    println!();
1995    let mut txt = String::new();
1996    for c in cipher.clone()
1997        { write!(txt, "{:02X} ", c); }
1998    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1999    println!();
2000
2001    // Expanded case for 128 rounds
2002    let key = 0x_1234567890ABCDEF_u64;
2003    println!("K =\t{:#016X}", key);
2004    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2005
2006    let message = "In the beginning God created the heavens and the earth.";
2007    println!("M =\t{}", message);
2008    let message = unsafe { message.to_string().as_mut_vec().clone() };
2009    let mut cipher = [0_u8; 56];
2010    a_des.encrypt_vec_into_array(&message, &mut cipher);
2011    print!("C (128 rounds) =\t");
2012    for c in cipher.clone()
2013        { print!("{:02X} ", c); }
2014    println!();
2015    let mut txt = String::new();
2016    for c in cipher.clone()
2017        { write!(txt, "{:02X} ", c); }
2018    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2019    println!();
2020
2021    // Expanded case for 0 rounds which means that key is meaningless
2022    let key1 = 0x_1234567890ABCDEF_u64;
2023    let key2 = 0_u64;
2024    println!("K1 =\t{:#016X}", key1);
2025    println!("K2 =\t{:#016X}", key2);
2026    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2027    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2028
2029    let message = "In the beginning God created the heavens and the earth.";
2030    println!("M =\t{}", message);
2031    let message = unsafe { message.to_string().as_mut_vec().clone() };
2032    let mut cipher1 = [0_u8; 56];
2033    let mut cipher2 = [0_u8; 56];
2034    c_des.encrypt_vec_into_array(&message, &mut cipher1);
2035    d_des.encrypt_vec_into_array(&message, &mut cipher2);
2036    print!("C (0 rounds) =\t");
2037    for c in cipher1.clone()
2038        { print!("{:02X} ", c); }
2039    println!();
2040    let mut txt = String::new();
2041    for c in cipher1.clone()
2042        { write!(txt, "{:02X} ", c); }
2043    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2044    print!("D (0 rounds) =\t");
2045    for c in cipher2.clone()
2046        { print!("{:02X} ", c); }
2047    println!();
2048    let mut txt = String::new();
2049    for c in cipher2.clone()
2050        { write!(txt, "{:02X} ", c); }
2051    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2052    println!();
2053
2054    // Normal case for the message of 0 bytes
2055    let key = 0x_1234567890ABCDEF_u64;
2056    println!("K =\t{:#016X}", key);
2057    let mut a_des = DES::new_with_key_u64(key);
2058
2059    let message = "";
2060    println!("M =\t{}", message);
2061    let message = unsafe { message.to_string().as_mut_vec().clone() };
2062    let mut cipher = [0_u8; 8];
2063    a_des.encrypt_vec_into_array(&message, &mut cipher);
2064    print!("C =\t");
2065    for c in cipher.clone()
2066        { print!("{:02X} ", c); }
2067    println!();
2068    let mut txt = String::new();
2069    for c in cipher.clone()
2070        { write!(txt, "{:02X} ", c); }
2071    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2072    println!();
2073
2074    // Normal case for the message shorter than 8 bytes
2075    let key = 0x_1234567890ABCDEF_u64;
2076    println!("K =\t{:#016X}", key);
2077    let mut a_des = DES::new_with_key_u64(key);
2078
2079    let message = "7 bytes";
2080    println!("M =\t{}", message);
2081    let message = unsafe { message.to_string().as_mut_vec().clone() };
2082    let mut cipher = [0_u8; 8];
2083    a_des.encrypt_vec_into_array(&message, &mut cipher);
2084    print!("C =\t");
2085    for c in cipher.clone()
2086        { print!("{:02X} ", c); }
2087    println!();
2088    let mut txt = String::new();
2089    for c in cipher.clone()
2090        { write!(txt, "{:02X} ", c); }
2091    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2092    println!();
2093
2094    // Normal case for the message of 8 bytes
2095    let key = 0x_1234567890ABCDEF_u64;
2096    println!("K =\t{:#016X}", key);
2097    let mut a_des = DES::new_with_key_u64(key);
2098
2099    let message = "I am OK.";
2100    println!("M =\t{}", message);
2101    let message = unsafe { message.to_string().as_mut_vec().clone() };
2102    let mut cipher = [0_u8; 16];
2103    a_des.encrypt_vec_into_array(&message, &mut cipher);
2104    print!("C =\t");
2105    for c in cipher.clone()
2106        { print!("{:02X} ", c); }
2107    println!();
2108    let mut txt = String::new();
2109    for c in cipher.clone()
2110        { write!(txt, "{:02X} ", c); }
2111    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2112    println!();
2113
2114    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2115    let key = 0x_1234567890ABCDEF_u64;
2116    println!("K =\t{:#016X}", key);
2117    let mut a_des = DES::new_with_key_u64(key);
2118
2119    let message = "PARK Youngho";
2120    println!("M =\t{}", message);
2121    let message = unsafe { message.to_string().as_mut_vec().clone() };
2122    let mut cipher = [0_u8; 16];
2123    a_des.encrypt_vec_into_array(&message, &mut cipher);
2124    print!("C =\t");
2125    for c in cipher.clone()
2126        { print!("{:02X} ", c); }
2127    println!();
2128    let mut txt = String::new();
2129    for c in cipher.clone()
2130        { write!(txt, "{:02X} ", c); }
2131    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2132    println!();
2133
2134
2135    // Normal case for the message of 16 bytes
2136    let key = 0x_1234567890ABCDEF_u64;
2137    println!("K =\t{:#016X}", key);
2138    let mut a_des = DES::new_with_key_u64(key);
2139 
2140    let message = "고맙습니다.";
2141    println!("M =\t{}", message);
2142    let message = unsafe { message.to_string().as_mut_vec().clone() };
2143    let mut cipher = [0_u8; 24];
2144    a_des.encrypt_vec_into_array(&message, &mut cipher);
2145    print!("C =\t");
2146    for c in cipher.clone()
2147        { print!("{:02X} ", c); }
2148    println!();
2149    let mut txt = String::new();
2150    for c in cipher.clone()
2151        { write!(txt, "{:02X} ", c); }
2152    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2153    println!("-------------------------------");
2154}
Source

fn encrypt_array<U, const N: usize>( &mut self, message: &[U; N], cipher: *mut u8, ) -> u64
where U: SmallUInt + Copy + Clone,

Encrypts the data stored in an array [U; N] object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • message is an immutable reference to an array [U; N] object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable pointer to u8 which is *mut u8, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as encrypt_vec_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • The size of the memory area which starts at cipher is assumed to be enough to store the ciphertext.
  • The size of the area for ciphertext should be prepared to be (size_of::<U>() * N + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • If message is an empty array [U; 0] object, only padding bytes will be encrypted, and stored in the memory area that starts from cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 64];
a_aes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 56];
a_des.encrypt_array(&message, cipher.as_mut_ptr());
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 64];
taes.encrypt_array(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 56];
tdes.encrypt_array(&message, cipher.as_mut_ptr());
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 380)
364fn bigcryptor64_encrypt_array_with_padding_iso_ecb()
365{
366    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb()");
367    use std::io::Write;
368    use std::fmt::Write as _;
369    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
370
371    // TDES case
372    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375    let mes = "In the beginning God created the heavens and the earth.";
376    println!("M =\t{}", mes);
377    let mut message = [0_u8; 55];
378    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379    let mut cipher = [0_u8; 56];
380    tdes.encrypt_array(&message, cipher.as_mut_ptr());
381    print!("C =\t");
382    for c in cipher.clone()
383        { print!("{:02X} ", c); }
384    println!();
385    let mut txt = String::new();
386    for c in cipher.clone()
387        { write!(txt, "{:02X} ", c); }
388    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389    println!("-------------------------------");
390}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 406)
388fn bigcryptor128_encrypt_array_with_padding_iso_ecb()
389{
390    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb()");
391    use std::io::Write;
392    use std::fmt::Write as _;
393    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
394
395    // TAES_128 case
396    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
397                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
398                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
399    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
400    println!("IV =	{:#034X}", iv);
401    let mes = "In the beginning God created the heavens and the earth.";
402    println!("M =\t{}", mes);
403    let mut message = [0_u8; 55];
404    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405    let mut cipher = [0_u8; 64];
406    taes.encrypt_array(&message, cipher.as_mut_ptr());
407    print!("C =\t");
408    for c in cipher.clone()
409        { print!("{:02X} ", c); }
410    println!();
411    let mut txt = String::new();
412    for c in cipher.clone()
413        { write!(txt, "{:02X} ", c); }
414    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
415    println!("-------------------------------");
416}
examples/des_ecb_iso_examples.rs (line 2173)
2156fn des_encrypt_array_with_padding_iso_ecb()
2157{
2158    println!("des_encrypt_array_with_padding_iso_ecb()");
2159    use std::io::Write;
2160    use std::fmt::Write as _;
2161    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2162
2163    // Normal case
2164    let key = 0x_1234567890ABCDEF_u64;
2165    println!("K =\t{:#016X}", key);
2166    let mut a_des = DES::new_with_key_u64(key);
2167
2168    let mes = "In the beginning God created the heavens and the earth.";
2169    println!("M =\t{}", mes);
2170    let mut message = [0_u8; 55];
2171    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2172    let mut cipher = [0_u8; 56];
2173    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2174    print!("C (16 rounds) =\t");
2175    for c in cipher.clone()
2176        { print!("{:02X} ", c); }
2177    println!();
2178    let mut txt = String::new();
2179    for c in cipher.clone()
2180        { write!(txt, "{:02X} ", c); }
2181    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2182    println!();
2183
2184    // Expanded case for 128 rounds
2185    let key = 0x_1234567890ABCDEF_u64;
2186    println!("K =\t{:#016X}", key);
2187    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2188
2189    let mes = "In the beginning God created the heavens and the earth.";
2190    println!("M =\t{}", mes);
2191    let mut message = [0_u8; 55];
2192    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2193    let mut cipher = [0_u8; 56];
2194    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2195    print!("C (128 rounds) =\t");
2196    for c in cipher.clone()
2197        { print!("{:02X} ", c); }
2198    println!();
2199    let mut txt = String::new();
2200    for c in cipher.clone()
2201        { write!(txt, "{:02X} ", c); }
2202    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2203    println!();
2204
2205    // Expanded case for 0 rounds which means that key is meaningless
2206    let key1 = 0x_1234567890ABCDEF_u64;
2207    let key2 = 0_u64;
2208    println!("K1 =\t{:#016X}", key1);
2209    println!("K2 =\t{:#016X}", key2);
2210    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2211    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2212
2213    let mes = "In the beginning God created the heavens and the earth.";
2214    println!("M =\t{}", mes);
2215    let mut message = [0_u8; 55];
2216    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2217    let mut cipher1 = [0_u8; 56];
2218    let mut cipher2 = [0_u8; 56];
2219    c_des.encrypt_array(&message, cipher1.as_mut_ptr());
2220    d_des.encrypt_array(&message, cipher2.as_mut_ptr());
2221    print!("C (0 rounds) =\t");
2222    for c in cipher1.clone()
2223        { print!("{:02X} ", c); }
2224    println!();
2225    let mut txt = String::new();
2226    for c in cipher1.clone()
2227        { write!(txt, "{:02X} ", c); }
2228    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2229    print!("D (0 rounds) =\t");
2230    for c in cipher2.clone()
2231        { print!("{:02X} ", c); }
2232    println!();
2233    let mut txt = String::new();
2234    for c in cipher2.clone()
2235        { write!(txt, "{:02X} ", c); }
2236    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2237    println!();
2238
2239    // Normal case for the message of 0 bytes
2240    let key = 0x_1234567890ABCDEF_u64;
2241    println!("K =\t{:#016X}", key);
2242    let mut a_des = DES::new_with_key_u64(key);
2243
2244    let mes = "";
2245    println!("M =\t{}", mes);
2246    let mut message = [0_u8; 0];
2247    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2248    let mut cipher = [0_u8; 8];
2249    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2250    print!("C =\t");
2251    for c in cipher.clone()
2252        { print!("{:02X} ", c); }
2253    println!();
2254    let mut txt = String::new();
2255    for c in cipher.clone()
2256        { write!(txt, "{:02X} ", c); }
2257    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2258    println!();
2259
2260    // Normal case for the message shorter than 8 bytes
2261    let key = 0x_1234567890ABCDEF_u64;
2262    println!("K =\t{:#016X}", key);
2263    let mut a_des = DES::new_with_key_u64(key);
2264
2265    let mes = "7 bytes";
2266    println!("M =\t{}", mes);
2267    let mut message = [0_u8; 7];
2268    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2269    let mut cipher = [0_u8; 8];
2270    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2271    print!("C =\t");
2272    for c in cipher.clone()
2273        { print!("{:02X} ", c); }
2274    println!();
2275    let mut txt = String::new();
2276    for c in cipher.clone()
2277        { write!(txt, "{:02X} ", c); }
2278    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2279    println!();
2280
2281    // Normal case for the message of 8 bytes
2282    let key = 0x_1234567890ABCDEF_u64;
2283    println!("K =\t{:#016X}", key);
2284    let mut a_des = DES::new_with_key_u64(key);
2285
2286    let mes = "I am OK.";
2287    println!("M =\t{}", mes);
2288    let mut message = [0_u8; 8];
2289    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2290    let mut cipher = [0_u8; 16];
2291    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2292    print!("C =\t");
2293    for c in cipher.clone()
2294        { print!("{:02X} ", c); }
2295    println!();
2296    let mut txt = String::new();
2297    for c in cipher.clone()
2298        { write!(txt, "{:02X} ", c); }
2299    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2300    println!();
2301
2302    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2303    let key = 0x_1234567890ABCDEF_u64;
2304    println!("K =\t{:#016X}", key);
2305    let mut a_des = DES::new_with_key_u64(key);
2306
2307    let mes = "PARK Youngho";
2308    println!("M =\t{}", mes);
2309    let mut message = [0_u8; 12];
2310    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2311    let mut cipher = [0_u8; 16];
2312    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2313    print!("C =\t");
2314    for c in cipher.clone()
2315        { print!("{:02X} ", c); }
2316    println!();
2317    let mut txt = String::new();
2318    for c in cipher.clone()
2319        { write!(txt, "{:02X} ", c); }
2320    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2321    println!();
2322
2323
2324    // Normal case for the message of 16 bytes
2325    let key = 0x_1234567890ABCDEF_u64;
2326    println!("K =\t{:#016X}", key);
2327    let mut a_des = DES::new_with_key_u64(key);
2328
2329    let mes = "고맙습니다.";
2330    println!("M =\t{}", mes);
2331    let mut message = [0_u8; 16];
2332    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2333    let mut cipher = [0_u8; 24];
2334    a_des.encrypt_array(&message, cipher.as_mut_ptr());
2335    print!("C =\t");
2336    for c in cipher.clone()
2337        { print!("{:02X} ", c); }
2338    println!();
2339    let mut txt = String::new();
2340    for c in cipher.clone()
2341        { write!(txt, "{:02X} ", c); }
2342    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2343    println!("-------------------------------");
2344}
Source

fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Encrypts the data stored in an array [U; N] object with the padding according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in Vec<V>.

§Arguments
  • message is an immutable reference to an array [U; N] object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to Vec<U> object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is an empty array [U; 0] object, only padding bytes will be encrypted, and stored in the Vec<U> object cipher.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_array_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = Vec::<u8>::new();
a_des.encrypt_array_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = Vec::<u8>::new();
taes.encrypt_array_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = Vec::<u8>::new();
tdes.encrypt_array_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 408)
392fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()
393{
394    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()");
395    use std::io::Write;
396    use std::fmt::Write as _;
397    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
398
399    // TDES case
400    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403    let mes = "In the beginning God created the heavens and the earth.";
404    println!("M =\t{}", mes);
405    let mut message = [0_u8; 55];
406    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407    let mut cipher = Vec::<u8>::new();
408    tdes.encrypt_array_into_vec(&message, &mut cipher);
409    print!("C =\t");
410    for c in cipher.clone()
411        { print!("{:02X} ", c); }
412    println!();
413    let mut txt = String::new();
414    for c in cipher.clone()
415        { write!(txt, "{:02X} ", c); }
416    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417    println!("-------------------------------");
418}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 436)
418fn bigcryptor128_encrypt_array_with_padding_iso_ecb_into_vec()
419{
420    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb_into_vec()");
421    use std::io::Write;
422    use std::fmt::Write as _;
423    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
424
425    // TAES_128 case
426    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
427                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
428                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
429    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
430    println!("IV =	{:#034X}", iv);
431    let mes = "In the beginning God created the heavens and the earth.";
432    println!("M =\t{}", mes);
433    let mut message = [0_u8; 55];
434    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435    let mut cipher = Vec::<u8>::new();
436    taes.encrypt_array_into_vec(&message, &mut cipher);
437    print!("C =\t");
438    for c in cipher.clone()
439        { print!("{:02X} ", c); }
440    println!();
441    let mut txt = String::new();
442    for c in cipher.clone()
443        { write!(txt, "{:02X} ", c); }
444    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
445    println!("-------------------------------");
446}
examples/aes_ecb_iso_examples.rs (line 1626)
1609fn aes_encrypt_array_with_padding_iso_ecb_into_vec()
1610{
1611    println!("aes_encrypt_array_with_padding_iso_ecb_into_vec()");
1612    use std::io::Write;
1613    use std::fmt::Write as _;
1614    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1615
1616    // Normal case for AES-128
1617    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1618    println!("K =\t{:#016X}", key);
1619    let mut a_aes = AES_128::new_with_key_u128(key);
1620
1621    let mes = "In the beginning God created the heavens and the earth.";
1622    println!("M =\t{}", mes);
1623    let mut message = [0_u8; 55];
1624    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1625    let mut cipher = Vec::<u8>::new();
1626    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1627    print!("C =\t");
1628    for c in cipher.clone()
1629        { print!("{:02X} ", c); }
1630    println!();
1631    let mut txt = String::new();
1632    for c in cipher.clone()
1633        { write!(txt, "{:02X} ", c); }
1634    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1635    println!();
1636
1637    // Normal case for AES-192
1638    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1639    print!("K =\t");
1640    for i in 0..24
1641        { print!("{:02X}", key[i]); }
1642    println!();
1643    let mut a_aes = AES_192::new_with_key(&key);
1644
1645    let mes = "In the beginning God created the heavens and the earth.";
1646    println!("M =\t{}", mes);
1647    let mut message = [0_u8; 55];
1648    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1649    let mut cipher = Vec::<u8>::new();
1650    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1651    print!("C =\t");
1652    for c in cipher.clone()
1653        { print!("{:02X} ", c); }
1654    println!();
1655    let mut txt = String::new();
1656    for c in cipher.clone()
1657        { write!(txt, "{:02X} ", c); }
1658    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1659    println!();
1660
1661    // Normal case for AES-256
1662    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1663    print!("K =\t");
1664    for i in 0..32
1665        { print!("{:02X}", key[i]); }
1666    println!();
1667    let mut a_aes = AES_256::new_with_key(&key);
1668
1669    let mes = "In the beginning God created the heavens and the earth.";
1670    println!("M =\t{}", mes);
1671    let mut message = [0_u8; 55];
1672    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1673    let mut cipher = Vec::<u8>::new();
1674    a_aes.encrypt_array_into_vec(&message, &mut cipher);
1675    print!("C =\t");
1676    for c in cipher.clone()
1677        { print!("{:02X} ", c); }
1678    println!();
1679    let mut txt = String::new();
1680    for c in cipher.clone()
1681        { write!(txt, "{:02X} ", c); }
1682    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1683    println!();
1684
1685    // Normal case for Rijndael-256-256
1686    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1687    print!("K =\t");
1688    for i in 0..32
1689        { print!("{:02X}", key[i]); }
1690    println!();
1691    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1692
1693    let mes = "In the beginning God created the heavens and the earth.";
1694    println!("M =\t{}", mes);
1695    let mut message = [0_u8; 55];
1696    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1697    let mut cipher = Vec::<u8>::new();
1698    a_rijndael.encrypt_array_into_vec(&message, &mut cipher);
1699    print!("C =\t");
1700    for c in cipher.clone()
1701        { print!("{:02X} ", c); }
1702    println!();
1703    let mut txt = String::new();
1704    for c in cipher.clone()
1705        { write!(txt, "{:02X} ", c); }
1706    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1707    println!();
1708
1709    // Normal case for Rijndael-512-512 for post-quantum
1710    use cryptocol::number::SharedArrays;
1711    use cryptocol::hash::SHA3_512;
1712    let mut sha3 = SHA3_512::new();
1713    sha3.absorb_str("Post-quantum");
1714    let key: [u8; 64] = sha3.get_hash_value_in_array();
1715    print!("K =\t");
1716    for i in 0..64
1717        { print!("{:02X}", key[i]); }
1718    println!();
1719    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1720    let mes = "In the beginning God created the heavens and the earth.";
1721    println!("M =\t{}", mes);
1722    let mut message = [0_u8; 55];
1723    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1724    let mut cipher = Vec::<u8>::new();
1725    a_rijndael.encrypt_array_into_vec(&message, &mut cipher);
1726    print!("C =\t");
1727    for c in cipher.clone()
1728        { print!("{:02X} ", c); }
1729    println!();
1730    let mut txt = String::new();
1731    for c in cipher.clone()
1732        { write!(txt, "{:02X} ", c); }
1733    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1734    println!("-------------------------------");
1735}
examples/des_ecb_iso_examples.rs (line 2363)
2346fn des_encrypt_array_with_padding_iso_ecb_into_vec()
2347{
2348    println!("des_encrypt_array_with_padding_iso_ecb_into_vec()");
2349    use std::io::Write;
2350    use std::fmt::Write as _;
2351    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2352
2353    // Normal case
2354    let key = 0x_1234567890ABCDEF_u64;
2355    println!("K =\t{:#016X}", key);
2356    let mut a_des = DES::new_with_key_u64(key);
2357
2358    let mes = "In the beginning God created the heavens and the earth.";
2359    println!("M =\t{}", mes);
2360    let mut message = [0_u8; 55];
2361    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2362    let mut cipher = Vec::<u8>::new();
2363    a_des.encrypt_array_into_vec(&message, &mut cipher);
2364    print!("C (16 rounds) =\t");
2365    for c in cipher.clone()
2366        { print!("{:02X} ", c); }
2367    println!();
2368    let mut txt = String::new();
2369    for c in cipher.clone()
2370        { write!(txt, "{:02X} ", c); }
2371    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2372    println!();
2373
2374    // Expanded case for 128 rounds
2375    let key = 0x_1234567890ABCDEF_u64;
2376    println!("K =\t{:#016X}", key);
2377    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2378
2379    let mes = "In the beginning God created the heavens and the earth.";
2380    println!("M =\t{}", mes);
2381    let mut message = [0_u8; 55];
2382    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2383    let mut cipher = Vec::<u8>::new();
2384    a_des.encrypt_array_into_vec(&message, &mut cipher);
2385    print!("C (128 rounds) =\t");
2386    for c in cipher.clone()
2387        { print!("{:02X} ", c); }
2388    println!();
2389    let mut txt = String::new();
2390    for c in cipher.clone()
2391        { write!(txt, "{:02X} ", c); }
2392    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2393    println!();
2394
2395    // Expanded case for 0 rounds which means that key is meaningless
2396    let key1 = 0x_1234567890ABCDEF_u64;
2397    let key2 = 0_u64;
2398    println!("K1 =\t{:#016X}", key1);
2399    println!("K2 =\t{:#016X}", key2);
2400    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2401    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2402
2403    let mes = "In the beginning God created the heavens and the earth.";
2404    println!("M =\t{}", mes);
2405    let mut message = [0_u8; 55];
2406    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2407
2408    let mut cipher1 = Vec::<u8>::new();
2409    let mut cipher2 = Vec::<u8>::new();
2410    c_des.encrypt_array_into_vec(&message, &mut cipher1);
2411    d_des.encrypt_array_into_vec(&message, &mut cipher2);
2412    print!("C (0 rounds) =\t");
2413    for c in cipher1.clone()
2414        { print!("{:02X} ", c); }
2415    println!();
2416    let mut txt = String::new();
2417    for c in cipher1.clone()
2418        { write!(txt, "{:02X} ", c); }
2419    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2420    print!("D (0 rounds) =\t");
2421    for c in cipher2.clone()
2422        { print!("{:02X} ", c); }
2423    println!();
2424    let mut txt = String::new();
2425    for c in cipher2.clone()
2426        { write!(txt, "{:02X} ", c); }
2427    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2428    println!();
2429
2430    // Normal case for the message of 0 bytes
2431    let key = 0x_1234567890ABCDEF_u64;
2432    println!("K =\t{:#016X}", key);
2433    let mut a_des = DES::new_with_key_u64(key);
2434
2435    let mes = "";
2436    println!("M =\t{}", mes);
2437    let mut message = [0_u8; 0];
2438    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2439    let mut cipher = Vec::<u8>::new();
2440    a_des.encrypt_array_into_vec(&message, &mut cipher);
2441    print!("C =\t");
2442    for c in cipher.clone()
2443        { print!("{:02X} ", c); }
2444    println!();
2445    let mut txt = String::new();
2446    for c in cipher.clone()
2447        { write!(txt, "{:02X} ", c); }
2448    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2449    println!();
2450
2451    // Normal case for the message shorter than 8 bytes
2452    let key = 0x_1234567890ABCDEF_u64;
2453    println!("K =\t{:#016X}", key);
2454    let mut a_des = DES::new_with_key_u64(key);
2455
2456    let mes = "7 bytes";
2457    println!("M =\t{}", mes);
2458    let mut message = [0_u8; 7];
2459    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460    let mut cipher = Vec::<u8>::new();
2461    a_des.encrypt_array_into_vec(&message, &mut cipher);
2462    print!("C =\t");
2463    for c in cipher.clone()
2464        { print!("{:02X} ", c); }
2465    println!();
2466    let mut txt = String::new();
2467    for c in cipher.clone()
2468        { write!(txt, "{:02X} ", c); }
2469    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2470    println!();
2471
2472    // Normal case for the message of 8 bytes
2473    let key = 0x_1234567890ABCDEF_u64;
2474    println!("K =\t{:#016X}", key);
2475    let mut a_des = DES::new_with_key_u64(key);
2476
2477    let mes = "I am OK.";
2478    println!("M =\t{}", mes);
2479    let mut message = [0_u8; 8];
2480    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2481    let mut cipher = Vec::<u8>::new();
2482    a_des.encrypt_array_into_vec(&message, &mut cipher);
2483    print!("C =\t");
2484    for c in cipher.clone()
2485        { print!("{:02X} ", c); }
2486    println!();
2487    let mut txt = String::new();
2488    for c in cipher.clone()
2489        { write!(txt, "{:02X} ", c); }
2490    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2491    println!();
2492
2493    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2494    let key = 0x_1234567890ABCDEF_u64;
2495    println!("K =\t{:#016X}", key);
2496    let mut a_des = DES::new_with_key_u64(key);
2497
2498    let mes = "PARK Youngho";
2499    println!("M =\t{}", mes);
2500    let mut message = [0_u8; 12];
2501    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2502    let mut cipher = Vec::<u8>::new();
2503    a_des.encrypt_array_into_vec(&message, &mut cipher);
2504    print!("C =\t");
2505    for c in cipher.clone()
2506        { print!("{:02X} ", c); }
2507    println!();
2508    let mut txt = String::new();
2509    for c in cipher.clone()
2510        { write!(txt, "{:02X} ", c); }
2511    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2512    println!();
2513
2514
2515    // Normal case for the message of 16 bytes
2516    let key = 0x_1234567890ABCDEF_u64;
2517    println!("K =\t{:#016X}", key);
2518    let mut a_des = DES::new_with_key_u64(key);
2519
2520    let mes = "고맙습니다.";
2521    println!("M =\t{}", mes);
2522    let mut message = [0_u8; 16];
2523    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2524    let mut cipher = Vec::<u8>::new();
2525    a_des.encrypt_array_into_vec(&message, &mut cipher);
2526    print!("C =\t");
2527    for c in cipher.clone()
2528        { print!("{:02X} ", c); }
2529    println!();
2530    let mut txt = String::new();
2531    for c in cipher.clone()
2532        { write!(txt, "{:02X} ", c); }
2533    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2534    println!("-------------------------------");
2535}
Source

fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, message: &[U; N], cipher: &mut [V; M], ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Encrypts the data stored in an array [U; N] object with the padding according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the encrypted data in array [V; M].

§Arguments
  • message is an immutable reference to an array [U; N] object, and is the place where the plaintext to be encrypted is stored.
  • cipher is a mutable reference to an array [U; N] object, and is the place where the encrypted data will be stored.
§Output
  • This method returns the size of ciphertext including padding bits in bytes.
  • The output will be at least size_of::<T>(), and cannot be other than a multiple of size_of::<T>().
  • If this method failed in encryption, this method returns zero.
§Features
  • If message is an empty array [U; 0] object, only padding bytes will be encrypted, and stored in the array [V; M] object cipher.
  • If V::size_in_bytes() * M is less than U::size_in_bytes() * N’s next multiple of size_of::<T>(), this method does not perform encryption and returns zero.
  • If V::size_in_bytes() * M is equal to U::size_in_bytes() * N’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted ciphertext, and returns the size of the ciphertext including padding bits in bytes.
  • If V::size_in_bytes() * M is greater than U::size_in_bytes() * N’s next multiple of size_of::<T>(), this method performs encryption, fills the array cipher with the encrypted ciphertext, and then fills the rest of the elements of the array cipher with zeros, and returns the size of the ciphertext including padding bits in bytes.
  • The size of the area for ciphertext should be prepared to be (size_of::<U>() * message.len() + 1).next_multiple_of(size_of::<T>()) at least. So, it is responsible for you to prepare the cipher area big enough!
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 64];
a_aes.encrypt_array_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 56];
a_des.encrypt_array_into_array(&message, &mut cipher);
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 64];
taes.encrypt_array_into_array(&message, &mut cipher);
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let mes = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", mes);
let mut message = [0_u8; 55];
message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
let mut cipher = [0_u8; 56];
tdes.encrypt_array_into_array(&message, &mut cipher);
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 436)
420fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()
421{
422    println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()");
423    use std::io::Write;
424    use std::fmt::Write as _;
425    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
426
427    // TDES case
428    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431    let mes = "In the beginning God created the heavens and the earth.";
432    println!("M =\t{}", mes);
433    let mut message = [0_u8; 55];
434    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435    let mut cipher = [0_u8; 56];
436    tdes.encrypt_array_into_array(&message, &mut cipher);
437    for c in cipher.clone()
438        { print!("{:02X} ", c); }
439    println!();
440    let mut txt = String::new();
441    for c in cipher.clone()
442        { write!(txt, "{:02X} ", c); }
443    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444    println!("-------------------------------");
445}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 466)
448fn bigcryptor128_encrypt_array_with_padding_iso_ecb_into_array()
449{
450    println!("bigcryptor128_encrypt_array_with_padding_iso_ecb_into_array()");
451    use std::io::Write;
452    use std::fmt::Write as _;
453    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
454
455    // TAES_128 case
456    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
457                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
458                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
459    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
460    println!("IV =	{:#034X}", iv);
461    let mes = "In the beginning God created the heavens and the earth.";
462    println!("M =\t{}", mes);
463    let mut message = [0_u8; 55];
464    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465    let mut cipher = [0_u8; 64];
466    taes.encrypt_array_into_array(&message, &mut cipher);
467    for c in cipher.clone()
468        { print!("{:02X} ", c); }
469    println!();
470    let mut txt = String::new();
471    for c in cipher.clone()
472        { write!(txt, "{:02X} ", c); }
473    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
474    println!("-------------------------------");
475}
examples/aes_ecb_iso_examples.rs (line 1754)
1737fn aes_encrypt_array_with_padding_iso_ecb_into_array()
1738{
1739    println!("aes_encrypt_array_with_padding_iso_ecb_into_array()");
1740    use std::io::Write;
1741    use std::fmt::Write as _;
1742    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
1743
1744    // Normal case for AES-128
1745    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
1746    println!("K =\t{:#016X}", key);
1747    let mut a_aes = AES_128::new_with_key_u128(key);
1748
1749    let mes = "In the beginning God created the heavens and the earth.";
1750    println!("M =\t{}", mes);
1751    let mut message = [0_u8; 55];
1752    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1753    let mut cipher = [0_u8; 64];
1754    a_aes.encrypt_array_into_array(&message, &mut cipher);
1755    print!("C =\t");
1756    for c in cipher.clone()
1757        { print!("{:02X} ", c); }
1758    println!();
1759    let mut txt = String::new();
1760    for c in cipher.clone()
1761        { write!(txt, "{:02X} ", c); }
1762    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
1763    println!();
1764
1765    // Normal case for AES-192
1766    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1767    print!("K =\t");
1768    for i in 0..24
1769        { print!("{:02X}", key[i]); }
1770    println!();
1771    let mut a_aes = AES_192::new_with_key(&key);
1772
1773    let mes = "In the beginning God created the heavens and the earth.";
1774    println!("M =\t{}", mes);
1775    let mut message = [0_u8; 55];
1776    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1777    let mut cipher = [0_u8; 64];
1778    a_aes.encrypt_array_into_array(&message, &mut cipher);
1779    print!("C =\t");
1780    for c in cipher.clone()
1781        { print!("{:02X} ", c); }
1782    println!();
1783    let mut txt = String::new();
1784    for c in cipher.clone()
1785        { write!(txt, "{:02X} ", c); }
1786    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
1787    println!();
1788
1789    // Normal case for AES-256
1790    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1791    print!("K =\t");
1792    for i in 0..32
1793        { print!("{:02X}", key[i]); }
1794    println!();
1795    let mut a_aes = AES_256::new_with_key(&key);
1796
1797    let mes = "In the beginning God created the heavens and the earth.";
1798    println!("M =\t{}", mes);
1799    let mut message = [0_u8; 55];
1800    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1801    let mut cipher = [0_u8; 64];
1802    a_aes.encrypt_array_into_array(&message, &mut cipher);
1803    print!("C =\t");
1804    for c in cipher.clone()
1805        { print!("{:02X} ", c); }
1806    println!();
1807    let mut txt = String::new();
1808    for c in cipher.clone()
1809        { write!(txt, "{:02X} ", c); }
1810    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
1811    println!();
1812
1813    // Normal case for Rijndael-256-256
1814    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
1815    print!("K =\t");
1816    for i in 0..32
1817        { print!("{:02X}", key[i]); }
1818    println!();
1819    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
1820
1821    let mes = "In the beginning God created the heavens and the earth.";
1822    println!("M =\t{}", mes);
1823    let mut message = [0_u8; 55];
1824    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1825    let mut cipher = [0_u8; 64];
1826    a_rijndael.encrypt_array_into_array(&message, &mut cipher);
1827    print!("C =\t");
1828    for c in cipher.clone()
1829        { print!("{:02X} ", c); }
1830    println!();
1831    let mut txt = String::new();
1832    for c in cipher.clone()
1833        { write!(txt, "{:02X} ", c); }
1834    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
1835    println!();
1836
1837    // Normal case for Rijndael-512-512 for post-quantum
1838    use cryptocol::number::SharedArrays;
1839    use cryptocol::hash::SHA3_512;
1840    let mut sha3 = SHA3_512::new();
1841    sha3.absorb_str("Post-quantum");
1842    let key: [u8; 64] = sha3.get_hash_value_in_array();
1843    print!("K =\t");
1844    for i in 0..64
1845        { print!("{:02X}", key[i]); }
1846    println!();
1847    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
1848    let mes = "In the beginning God created the heavens and the earth.";
1849    println!("M =\t{}", mes);
1850    let mut message = [0_u8; 55];
1851    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
1852    let mut cipher = [0_u8; 64];
1853    a_rijndael.encrypt_array_into_array(&message, &mut cipher);
1854    print!("C =\t");
1855    for c in cipher.clone()
1856        { print!("{:02X} ", c); }
1857    println!();
1858    let mut txt = String::new();
1859    for c in cipher.clone()
1860        { write!(txt, "{:02X} ", c); }
1861    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
1862    println!("-------------------------------");
1863}
examples/des_ecb_iso_examples.rs (line 2554)
2537fn des_encrypt_array_with_padding_iso_ecb_into_array()
2538{
2539    println!("des_encrypt_array_with_padding_iso_ecb_into_array()");
2540    use std::io::Write;
2541    use std::fmt::Write as _;
2542    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2543
2544    // Normal case
2545    let key = 0x_1234567890ABCDEF_u64;
2546    println!("K =\t{:#016X}", key);
2547    let mut a_des = DES::new_with_key_u64(key);
2548
2549    let mes = "In the beginning God created the heavens and the earth.";
2550    println!("M =\t{}", mes);
2551    let mut message = [0_u8; 55];
2552    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2553    let mut cipher = [0_u8; 56];
2554    a_des.encrypt_array_into_array(&message, &mut cipher);
2555    for c in cipher.clone()
2556        { print!("{:02X} ", c); }
2557    println!();
2558    let mut txt = String::new();
2559    for c in cipher.clone()
2560        { write!(txt, "{:02X} ", c); }
2561    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2562    println!();
2563
2564    // Expanded case for 128 rounds
2565    let key = 0x_1234567890ABCDEF_u64;
2566    println!("K =\t{:#016X}", key);
2567    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2568
2569    let mes = "In the beginning God created the heavens and the earth.";
2570    println!("M =\t{}", mes);
2571    let mut message = [0_u8; 55];
2572    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2573    let mut cipher = [0_u8; 56];
2574    a_des.encrypt_array_into_array(&message, &mut cipher);
2575    print!("C (128 rounds) =\t");
2576    for c in cipher.clone()
2577        { print!("{:02X} ", c); }
2578    println!();
2579    let mut txt = String::new();
2580    for c in cipher.clone()
2581        { write!(txt, "{:02X} ", c); }
2582    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2583    println!();
2584
2585    // Expanded case for 0 rounds which means that key is meaningless
2586    let key1 = 0x_1234567890ABCDEF_u64;
2587    let key2 = 0_u64;
2588    println!("K1 =\t{:#016X}", key1);
2589    println!("K2 =\t{:#016X}", key2);
2590    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2591    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2592
2593    let mes = "In the beginning God created the heavens and the earth.";
2594    println!("M =\t{}", mes);
2595    let mut message = [0_u8; 55];
2596    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2597    let mut cipher1 = [0_u8; 56];
2598    let mut cipher2 = [0_u8; 56];
2599    c_des.encrypt_array_into_array(&message, &mut cipher1);
2600    d_des.encrypt_array_into_array(&message, &mut cipher2);
2601    print!("C (0 rounds) =\t");
2602    for c in cipher1.clone()
2603        { print!("{:02X} ", c); }
2604    println!();
2605    let mut txt = String::new();
2606    for c in cipher1.clone()
2607        { write!(txt, "{:02X} ", c); }
2608    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2609    print!("D (0 rounds) =\t");
2610    for c in cipher2.clone()
2611        { print!("{:02X} ", c); }
2612    println!();
2613    let mut txt = String::new();
2614    for c in cipher2.clone()
2615        { write!(txt, "{:02X} ", c); }
2616    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2617    println!();
2618
2619    // Normal case for the message of 0 bytes
2620    let key = 0x_1234567890ABCDEF_u64;
2621    println!("K =\t{:#016X}", key);
2622    let mut a_des = DES::new_with_key_u64(key);
2623
2624    let mes = "";
2625    println!("M =\t{}", mes);
2626    let mut message = [0_u8; 0];
2627    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2628    let mut cipher = [0_u8; 8];
2629    a_des.encrypt_array_into_array(&message, &mut cipher);
2630    print!("C =\t");
2631    for c in cipher.clone()
2632        { print!("{:02X} ", c); }
2633    println!();
2634    let mut txt = String::new();
2635    for c in cipher.clone()
2636        { write!(txt, "{:02X} ", c); }
2637    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2638    println!();
2639
2640    // Normal case for the message shorter than 8 bytes
2641    let key = 0x_1234567890ABCDEF_u64;
2642    println!("K =\t{:#016X}", key);
2643    let mut a_des = DES::new_with_key_u64(key);
2644
2645    let mes = "7 bytes";
2646    println!("M =\t{}", mes);
2647    let mut message = [0_u8; 7];
2648    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2649    let mut cipher = [0_u8; 8];
2650    a_des.encrypt_array_into_array(&message, &mut cipher);
2651    print!("C =\t");
2652    for c in cipher.clone()
2653        { print!("{:02X} ", c); }
2654    println!();
2655    let mut txt = String::new();
2656    for c in cipher.clone()
2657        { write!(txt, "{:02X} ", c); }
2658    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2659    println!();
2660
2661    // Normal case for the message of 8 bytes
2662    let key = 0x_1234567890ABCDEF_u64;
2663    println!("K =\t{:#016X}", key);
2664    let mut a_des = DES::new_with_key_u64(key);
2665
2666    let mes = "I am OK.";
2667    println!("M =\t{}", mes);
2668    let mut message = [0_u8; 8];
2669    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2670    let mut cipher = [0_u8; 16];
2671    a_des.encrypt_array_into_array(&message, &mut cipher);
2672    print!("C =\t");
2673    for c in cipher.clone()
2674        { print!("{:02X} ", c); }
2675    println!();
2676    let mut txt = String::new();
2677    for c in cipher.clone()
2678        { write!(txt, "{:02X} ", c); }
2679    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2680    println!();
2681
2682    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2683    let key = 0x_1234567890ABCDEF_u64;
2684    println!("K =\t{:#016X}", key);
2685    let mut a_des = DES::new_with_key_u64(key);
2686
2687    let mes = "PARK Youngho";
2688    println!("M =\t{}", mes);
2689    let mut message = [0_u8; 12];
2690    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2691    let mut cipher = [0_u8; 16];
2692    a_des.encrypt_array_into_array(&message, &mut cipher);
2693    print!("C =\t");
2694    for c in cipher.clone()
2695        { print!("{:02X} ", c); }
2696    println!();
2697    let mut txt = String::new();
2698    for c in cipher.clone()
2699        { write!(txt, "{:02X} ", c); }
2700    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2701    println!();
2702
2703
2704    // Normal case for the message of 16 bytes
2705    let key = 0x_1234567890ABCDEF_u64;
2706    println!("K =\t{:#016X}", key);
2707    let mut a_des = DES::new_with_key_u64(key);
2708 
2709    let mes = "고맙습니다.";
2710    println!("M =\t{}", mes);
2711    let mut message = [0_u8; 16];
2712    message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2713    let mut cipher = [0_u8; 24];
2714    a_des.encrypt_array_into_array(&message, &mut cipher);
2715    print!("C =\t");
2716    for c in cipher.clone()
2717        { print!("{:02X} ", c); }
2718    println!();
2719    let mut txt = String::new();
2720    for c in cipher.clone()
2721        { write!(txt, "{:02X} ", c); }
2722    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2723    println!("-------------------------------");
2724}
Source

fn decrypt_into_vec<U>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
where U: SmallUInt + Copy + Clone,

Decrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in Vec<U>.

§Arguments
  • cipher is an immutable pointer to u8 which is *const u8, and is the place where the ciphertext to be decrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the ciphertext cipher in bytes.
  • message is a mutable reference to Vec<U> object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If length_in_bytes is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as decrypt_*_into_vec().
  • This method is useful to use in hybrid programming with C/C++.
  • length_in_bytes cannot be other than any multiple of size_of::<T>().
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the plaintext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = Vec::<u8>::new();
a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = Vec::<u8>::new();
a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = Vec::<u8>::new();
taes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = Vec::<u8>::new();
tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 516)
491fn bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()
492{
493    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()");
494    use std::io::Write;
495    use std::fmt::Write as _;
496    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
497
498    // TDES case
499    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502    let message = "In the beginning God created the heavens and the earth.";
503    println!("M =\t{}", message);
504    let mut cipher = Vec::<u8>::new();
505    tdes.encrypt_str_into_vec(&message, &mut cipher);
506    print!("C =\t");
507    for c in cipher.clone()
508        { print!("{:02X} ", c); }
509    println!();
510    let mut txt = String::new();
511    for c in cipher.clone()
512        { write!(txt, "{:02X} ", c); }
513    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515    let mut recovered = Vec::<u8>::new();
516    tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517    print!("Ba =\t");
518    for b in recovered.clone()
519        { print!("{:02X} ", b); }
520    println!();
521    let mut txt = String::new();
522    for c in recovered.clone()
523        { write!(txt, "{:02X} ", c); }
524    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526    let mut converted = String::new();
527    unsafe { converted.as_mut_vec() }.append(&mut recovered);
528    
529    println!("Bb =\t{}", converted);
530    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531    assert_eq!(converted, message);
532    println!("-------------------------------");
533}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 550)
523fn bigcryptor128_decrypt_with_padding_iso_ecb_into_vec()
524{
525    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_vec()");
526    use std::io::Write;
527    use std::fmt::Write as _;
528    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
529
530    // TAES_128 case
531    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
532                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
533                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
534    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
535    println!("IV =	{:#034X}", iv);
536    let message = "In the beginning God created the heavens and the earth.";
537    println!("M =\t{}", message);
538    let mut cipher = Vec::<u8>::new();
539    taes.encrypt_str_into_vec(&message, &mut cipher);
540    print!("C =\t");
541    for c in cipher.clone()
542        { print!("{:02X} ", c); }
543    println!();
544    let mut txt = String::new();
545    for c in cipher.clone()
546        { write!(txt, "{:02X} ", c); }
547    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
548
549    let mut recovered = Vec::<u8>::new();
550    taes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551    print!("Ba =\t");
552    for b in recovered.clone()
553        { print!("{:02X} ", b); }
554    println!();
555    let mut txt = String::new();
556    for c in recovered.clone()
557        { write!(txt, "{:02X} ", c); }
558    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560    let mut converted = String::new();
561    unsafe { converted.as_mut_vec() }.append(&mut recovered);
562    
563    println!("Bb =\t{}", converted);
564    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565    assert_eq!(converted, message);
566    println!("-------------------------------");
567}
examples/aes_ecb_iso_examples.rs (line 2101)
2074fn aes_decrypt_with_padding_iso_ecb_into_vec()
2075{
2076    println!("aes_decrypt_with_padding_iso_ecb_into_vec()");
2077    use std::io::Write;
2078    use std::fmt::Write as _;
2079    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2080
2081    // Normal case for AES-128
2082    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2083    println!("K =\t{:#016X}", key);
2084    let mut a_aes = AES_128::new_with_key_u128(key);
2085
2086    let message = "In the beginning God created the heavens and the earth.";
2087    println!("M =\t{}", message);
2088    let mut cipher = [0_u8; 64];
2089    a_aes.encrypt_str_into_array(&message, &mut cipher);
2090    print!("C =\t");
2091    for c in cipher.clone()
2092        { print!("{:02X} ", c); }
2093    println!();
2094    let mut txt = String::new();
2095    for c in cipher.clone()
2096        { write!(txt, "{:02X} ", c); }
2097    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2098    println!();
2099
2100    let mut recovered = Vec::<u8>::new();
2101    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2102    print!("Ba =\t");
2103    for b in recovered.clone()
2104        { print!("{:02X} ", b); }
2105    println!();
2106    let mut txt = String::new();
2107    for c in recovered.clone()
2108        { write!(txt, "{:02X} ", c); }
2109    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2110
2111    let mut converted = String::new();
2112    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2113    
2114    println!("Bb =\t{}", converted);
2115    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2116    assert_eq!(converted, message);
2117    println!();
2118
2119    // Normal case for AES-192
2120    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2121    print!("K =\t");
2122    for i in 0..24
2123        { print!("{:02X}", key[i]); }
2124    println!();
2125    let mut a_aes = AES_192::new_with_key(&key);
2126
2127    let message = "In the beginning God created the heavens and the earth.";
2128    println!("M =\t{}", message);
2129    let mut cipher = [0_u8; 64];
2130    a_aes.encrypt_str_into_array(&message, &mut cipher);
2131    print!("C =\t");
2132    for c in cipher.clone()
2133        { print!("{:02X} ", c); }
2134    println!();
2135    let mut txt = String::new();
2136    for c in cipher.clone()
2137        { write!(txt, "{:02X} ", c); }
2138    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2139    println!();
2140
2141    let mut recovered = Vec::<u8>::new();
2142    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2143    print!("Ba =\t");
2144    for b in recovered.clone()
2145        { print!("{:02X} ", b); }
2146    println!();
2147    let mut txt = String::new();
2148    for c in recovered.clone()
2149        { write!(txt, "{:02X} ", c); }
2150    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2151
2152    let mut converted = String::new();
2153    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2154    
2155    println!("Bb =\t{}", converted);
2156    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2157    assert_eq!(converted, message);
2158    println!();
2159
2160    // Normal case for AES-256
2161    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2162    print!("K =\t");
2163    for i in 0..32
2164        { print!("{:02X}", key[i]); }
2165    println!();
2166    let mut a_aes = AES_256::new_with_key(&key);
2167
2168    let message = "In the beginning God created the heavens and the earth.";
2169    println!("M =\t{}", message);
2170    let mut cipher = [0_u8; 64];
2171    a_aes.encrypt_str_into_array(&message, &mut cipher);
2172    print!("C =\t");
2173    for c in cipher.clone()
2174        { print!("{:02X} ", c); }
2175    println!();
2176    let mut txt = String::new();
2177    for c in cipher.clone()
2178        { write!(txt, "{:02X} ", c); }
2179    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2180    println!();
2181
2182    let mut recovered = Vec::<u8>::new();
2183    a_aes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2184    print!("Ba =\t");
2185    for b in recovered.clone()
2186        { print!("{:02X} ", b); }
2187    println!();
2188    let mut txt = String::new();
2189    for c in recovered.clone()
2190        { write!(txt, "{:02X} ", c); }
2191    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2192
2193    let mut converted = String::new();
2194    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2195    
2196    println!("Bb =\t{}", converted);
2197    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2198    assert_eq!(converted, message);
2199    println!();
2200
2201    // Normal case for Rijndael-256-256
2202    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2203    print!("K =\t");
2204    for i in 0..32
2205        { print!("{:02X}", key[i]); }
2206    println!();
2207    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2208
2209    let message = "In the beginning God created the heavens and the earth.";
2210    println!("M =\t{}", message);
2211    let mut cipher = [0_u8; 64];
2212    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2213    print!("C =\t");
2214    for c in cipher.clone()
2215        { print!("{:02X} ", c); }
2216    println!();
2217    let mut txt = String::new();
2218    for c in cipher.clone()
2219        { write!(txt, "{:02X} ", c); }
2220    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2221    println!();
2222
2223    let mut recovered = Vec::<u8>::new();
2224    a_rijndael.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2225    print!("Ba =\t");
2226    for b in recovered.clone()
2227        { print!("{:02X} ", b); }
2228    println!();
2229    let mut txt = String::new();
2230    for c in recovered.clone()
2231        { write!(txt, "{:02X} ", c); }
2232    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2233
2234    let mut converted = String::new();
2235    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2236    
2237    println!("Bb =\t{}", converted);
2238    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2239    assert_eq!(converted, message);
2240    println!();
2241
2242    // Normal case for Rijndael-512-512 for post-quantum
2243    use cryptocol::number::SharedArrays;
2244    use cryptocol::hash::SHA3_512;
2245    let mut sha3 = SHA3_512::new();
2246    sha3.absorb_str("Post-quantum");
2247    let key: [u8; 64] = sha3.get_hash_value_in_array();
2248    print!("K =\t");
2249    for i in 0..64
2250        { print!("{:02X}", key[i]); }
2251    println!();
2252    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2253    let message = "In the beginning God created the heavens and the earth.";
2254    println!("M =\t{}", message);
2255    let mut cipher = [0_u8; 64];
2256    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2257    print!("C =\t");
2258    for c in cipher.clone()
2259        { print!("{:02X} ", c); }
2260    println!();
2261    let mut txt = String::new();
2262    for c in cipher.clone()
2263        { write!(txt, "{:02X} ", c); }
2264    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2265    
2266    let mut recovered = Vec::<u8>::new();
2267    a_rijndael.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
2268    print!("Ba =\t");
2269    for b in recovered.clone()
2270        { print!("{:02X} ", b); }
2271    println!();
2272    let mut txt = String::new();
2273    for c in recovered.clone()
2274        { write!(txt, "{:02X} ", c); }
2275    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2276
2277    let mut converted = String::new();
2278    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2279    
2280    println!("Bb =\t{}", converted);
2281    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2282    assert_eq!(converted, message);
2283    println!("-------------------------------");
2284}
examples/des_ecb_iso_examples.rs (line 3090)
3064fn des_decrypt_with_padding_iso_ecb_into_vec()
3065{
3066    println!("des_decrypt_with_padding_iso_ecb_into_vec()");
3067    use std::io::Write;
3068    use std::fmt::Write as _;
3069    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3070
3071    // Normal case
3072    let key = 0x_1234567890ABCDEF_u64;
3073    println!("K =\t{:#016X}", key);
3074    let mut a_des = DES::new_with_key_u64(key);
3075
3076    let message = "In the beginning God created the heavens and the earth.";
3077    println!("M =\t{}", message);
3078    let mut cipher = Vec::<u8>::new();
3079    a_des.encrypt_str_into_vec(&message, &mut cipher);
3080    print!("C (16 rounds) =\t");
3081    for c in cipher.clone()
3082        { print!("{:02X} ", c); }
3083    println!();
3084    let mut txt = String::new();
3085    for c in cipher.clone()
3086        { write!(txt, "{:02X} ", c); }
3087    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3088
3089    let mut recovered = Vec::<u8>::new();
3090    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3091    print!("Ba (16 rounds) =\t");
3092    for b in recovered.clone()
3093        { print!("{:02X} ", b); }
3094    println!();
3095    let mut txt = String::new();
3096    for c in recovered.clone()
3097        { write!(txt, "{:02X} ", c); }
3098    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3099
3100    let mut converted = String::new();
3101    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3102    
3103    println!("Bb (16 rounds) =\t{}", converted);
3104    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3105    assert_eq!(converted, message);
3106    println!();
3107
3108    // Expanded case for 128 rounds
3109    let key = 0x_1234567890ABCDEF_u64;
3110    println!("K =\t{:#016X}", key);
3111    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3112
3113    let message = "In the beginning God created the heavens and the earth.";
3114    println!("M =\t{}", message);
3115    let mut cipher = Vec::<u8>::new();
3116    a_des.encrypt_str_into_vec(&message, &mut cipher);
3117    print!("C (128 rounds) =\t");
3118    for c in cipher.clone()
3119        { print!("{:02X} ", c); }
3120    println!();
3121    let mut txt = String::new();
3122    for c in cipher.clone()
3123        { write!(txt, "{:02X} ", c); }
3124    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3125
3126    let mut recovered = Vec::<u8>::new();
3127    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3128    print!("Ba (128 rounds) =\t");
3129    for b in recovered.clone()
3130        { print!("{:02X} ", b); }
3131    println!();
3132    let mut txt = String::new();
3133    for c in recovered.clone()
3134        { write!(txt, "{:02X} ", c); }
3135    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3136
3137    let mut converted = String::new();
3138    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139    
3140    println!("Bb (128 rounds) =\t{}", converted);
3141    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3142    assert_eq!(converted, message);
3143    println!();
3144
3145    // Expanded case for 0 rounds which means that key is meaningless
3146    let key1 = 0x_1234567890ABCDEF_u64;
3147    let key2 = 0_u64;
3148    println!("K =\t{:#016X}", key);
3149    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3150    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3151
3152    let message = "In the beginning God created the heavens and the earth.";
3153    println!("M =\t{}", message);
3154    let mut cipher1 = Vec::<u8>::new();
3155    let mut cipher2 = Vec::<u8>::new();
3156    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3157    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3158    print!("C (0 rounds) =\t");
3159    for c in cipher1.clone()
3160        { print!("{:02X} ", c); }
3161    println!();
3162    let mut txt = String::new();
3163    for c in cipher1.clone()
3164        { write!(txt, "{:02X} ", c); }
3165    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3166    print!("D (0 rounds) =\t");
3167    for c in cipher2.clone()
3168        { print!("{:02X} ", c); }
3169    println!();
3170    let mut txt = String::new();
3171    for c in cipher2.clone()
3172        { write!(txt, "{:02X} ", c); }
3173    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3174
3175    let mut recovered1 = Vec::<u8>::new();
3176    let mut recovered2 = Vec::<u8>::new();
3177    c_des.decrypt_into_vec(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3178    d_des.decrypt_into_vec(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3179    print!("B1a (0 rounds) =\t");
3180    for b in recovered1.clone()
3181        { print!("{:02X} ", b); }
3182    println!();
3183    let mut txt = String::new();
3184    for c in recovered1.clone()
3185        { write!(txt, "{:02X} ", c); }
3186    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3187    print!("B2a (0 rounds) =\t");
3188    for b in recovered2.clone()
3189        { print!("{:02X} ", b); }
3190    println!();
3191    let mut txt = String::new();
3192    for c in recovered2.clone()
3193        { write!(txt, "{:02X} ", c); }
3194    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3195
3196    let mut converted1 = String::new();
3197    let mut converted2 = String::new();
3198    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3199    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3200    
3201    println!("B1b (0 rounds) =\t{}", converted1);
3202    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3203    assert_eq!(converted1, message);
3204    println!("B2b (0 rounds) =\t{}", converted2);
3205    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3206    assert_eq!(converted2, message);
3207    assert_eq!(converted1, converted1);
3208    println!();
3209
3210    // Normal case for the message of 0 bytes
3211    let key = 0x_1234567890ABCDEF_u64;
3212    println!("K =\t{:#016X}", key);
3213    let mut a_des = DES::new_with_key_u64(key);
3214
3215    let message = "";
3216    println!("M =\t{}", message);
3217    let mut cipher = Vec::<u8>::new();
3218    a_des.encrypt_str_into_vec(&message, &mut cipher);
3219    print!("C =\t");
3220    for c in cipher.clone()
3221        { print!("{:02X} ", c); }
3222    println!();
3223    let mut txt = String::new();
3224    for c in cipher.clone()
3225        { write!(txt, "{:02X} ", c); }
3226    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3227
3228    let mut recovered = Vec::<u8>::new();
3229    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3230    print!("Ba =\t");
3231    for b in recovered.clone()
3232        { print!("{:02X} ", b); }
3233    println!();
3234    let mut txt = String::new();
3235    for c in recovered.clone()
3236        { write!(txt, "{:02X} ", c); }
3237    assert_eq!(txt, "");
3238
3239    let mut converted = String::new();
3240    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3241    
3242    println!("Bb =\t{}", converted);
3243    assert_eq!(converted, "");
3244    assert_eq!(converted, message);
3245    println!();
3246
3247    // Normal case for the message shorter than 8 bytes
3248    let key = 0x_1234567890ABCDEF_u64;
3249    println!("K =\t{:#016X}", key);
3250    let mut a_des = DES::new_with_key_u64(key);
3251
3252    let message = "7 bytes";
3253    println!("M =\t{}", message);
3254    let mut cipher = Vec::<u8>::new();
3255    a_des.encrypt_str_into_vec(&message, &mut cipher);
3256    print!("C =\t");
3257    for c in cipher.clone()
3258        { print!("{:02X} ", c); }
3259    println!();
3260    let mut txt = String::new();
3261    for c in cipher.clone()
3262        { write!(txt, "{:02X} ", c); }
3263    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3264    
3265    let mut recovered = Vec::<u8>::new();
3266    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3267    print!("Ba =\t");
3268    for b in recovered.clone()
3269        { print!("{:02X} ", b); }
3270    println!();
3271    let mut txt = String::new();
3272    for c in recovered.clone()
3273        { write!(txt, "{:02X} ", c); }
3274    assert_eq!(txt, "37 20 62 79 74 65 73 ");
3275
3276    let mut converted = String::new();
3277    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3278    
3279    println!("Bb =\t{}", converted);
3280    assert_eq!(converted, "7 bytes");
3281    assert_eq!(converted, message);
3282    println!();
3283
3284    // Normal case for the message of 8 bytes
3285    let key = 0x_1234567890ABCDEF_u64;
3286    println!("K =\t{:#016X}", key);
3287    let mut a_des = DES::new_with_key_u64(key);
3288
3289    let message = "I am OK.";
3290    println!("M =\t{}", message);
3291    let mut cipher = Vec::<u8>::new();
3292    a_des.encrypt_str_into_vec(&message, &mut cipher);
3293    print!("C =\t");
3294    for c in cipher.clone()
3295        { print!("{:02X} ", c); }
3296    println!();
3297    let mut txt = String::new();
3298    for c in cipher.clone()
3299        { write!(txt, "{:02X} ", c); }
3300    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3301    
3302    let mut recovered = Vec::<u8>::new();
3303    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3304    print!("Ba =\t");
3305    for b in recovered.clone()
3306        { print!("{:02X} ", b); }
3307    println!();
3308    let mut txt = String::new();
3309    for c in recovered.clone()
3310        { write!(txt, "{:02X} ", c); }
3311    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3312
3313    let mut converted = String::new();
3314    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3315    
3316    println!("Bb =\t{}", converted);
3317    assert_eq!(converted, "I am OK.");
3318    assert_eq!(converted, message);
3319    println!();
3320
3321    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3322    let key = 0x_1234567890ABCDEF_u64;
3323    println!("K =\t{:#016X}", key);
3324    let mut a_des = DES::new_with_key_u64(key);
3325
3326    let message = "PARK Youngho";
3327    println!("M =\t{}", message);
3328    let mut cipher = Vec::<u8>::new();
3329    a_des.encrypt_str_into_vec(&message, &mut cipher);
3330    print!("C =\t");
3331    for c in cipher.clone()
3332        { print!("{:02X} ", c); }
3333    println!();
3334    let mut txt = String::new();
3335    for c in cipher.clone()
3336        { write!(txt, "{:02X} ", c); }
3337    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3338
3339    let mut recovered = Vec::<u8>::new();
3340    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3341    print!("Ba =\t");
3342    for b in recovered.clone()
3343        { print!("{:02X} ", b); }
3344    println!();
3345    let mut txt = String::new();
3346    for c in recovered.clone()
3347        { write!(txt, "{:02X} ", c); }
3348    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3349
3350    let mut converted = String::new();
3351    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3352    
3353    println!("Bb =\t{}", converted);
3354    assert_eq!(converted, "PARK Youngho");
3355    assert_eq!(converted, message);
3356    println!();
3357
3358    // Normal case for the message of 16 bytes
3359    let key = 0x_1234567890ABCDEF_u64;
3360    println!("K =\t{:#016X}", key);
3361    let mut a_des = DES::new_with_key_u64(key);
3362
3363    let message = "고맙습니다.";
3364    println!("M =\t{}", message);
3365    let mut cipher = Vec::<u8>::new();
3366    a_des.encrypt_str_into_vec(&message, &mut cipher);
3367    print!("C =\t");
3368    for c in cipher.clone()
3369        { print!("{:02X} ", c); }
3370    println!();
3371    let mut txt = String::new();
3372    for c in cipher.clone()
3373        { write!(txt, "{:02X} ", c); }
3374    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3375
3376    let mut recovered = Vec::<u8>::new();
3377    a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3378    print!("Ba =\t");
3379    for b in recovered.clone()
3380        { print!("{:02X} ", b); }
3381    println!();
3382    let mut txt = String::new();
3383    for c in recovered.clone()
3384        { write!(txt, "{:02X} ", c); }
3385    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3386
3387    let mut converted = String::new();
3388    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3389    
3390    println!("Bb =\t{}", converted);
3391    assert_eq!(converted, "고맙습니다.");
3392    assert_eq!(converted, message);
3393    println!("-------------------------------");
3394}
Source

fn decrypt_into_string( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64

Decrypts the data with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in a String.

§Arguments
  • cipher is an immutable pointer to u8 which is *const u8, and is the place where the ciphertext to be decrypted is stored.
  • length_in_bytes is of u64-type, and is the length of the ciphertext cipher in bytes.
  • message is a mutable reference to a String object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If length_in_bytes is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as decrypt_*_into_string().
  • This method is useful to use in hybrid programming with C/C++.
  • length_in_bytes cannot be other than any multiple of size_of::<T>().
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
  • This method assumes that the original plaintext is a string in the format of UTF-8.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
println!();
 
let mut converted= String::new();
a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
println!("B =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = String::new();
a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
println!("B (16 rounds) =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = String::new();
taes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = String::new();
tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 604)
579fn bigcryptor64_decrypt_with_padding_iso_ecb_into_string()
580{
581    println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_string()");
582    use std::io::Write;
583    use std::fmt::Write as _;
584    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
585
586    // TDES case
587    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590    let message = "In the beginning God created the heavens and the earth.";
591    println!("M =\t{}", message);
592    let mut cipher = Vec::<u8>::new();
593    tdes.encrypt_str_into_vec(&message, &mut cipher);
594    print!("C =\t");
595    for c in cipher.clone()
596        { print!("{:02X} ", c); }
597    println!();
598    let mut txt = String::new();
599    for c in cipher.clone()
600        { write!(txt, "{:02X} ", c); }
601    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603    let mut recovered = String::new();
604    tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605    println!("B =\t{}", recovered);
606    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607    assert_eq!(recovered, message);
608    println!("-------------------------------");
609}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 642)
615fn bigcryptor128_decrypt_with_padding_iso_ecb_into_string()
616{
617    println!("bigcryptor128_decrypt_with_padding_iso_ecb_into_string()");
618    use std::io::Write;
619    use std::fmt::Write as _;
620    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
621
622    // TAES_128 case
623    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
624                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
625                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
626    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
627    println!("IV =	{:#034X}", iv);
628    let message = "In the beginning God created the heavens and the earth.";
629    println!("M =\t{}", message);
630    let mut cipher = Vec::<u8>::new();
631    taes.encrypt_str_into_vec(&message, &mut cipher);
632    print!("C =\t");
633    for c in cipher.clone()
634        { print!("{:02X} ", c); }
635    println!();
636    let mut txt = String::new();
637    for c in cipher.clone()
638        { write!(txt, "{:02X} ", c); }
639    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
640
641    let mut recovered = String::new();
642    taes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643    println!("B =\t{}", recovered);
644    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645    assert_eq!(recovered, message);
646    println!("-------------------------------");
647}
examples/aes_ecb_iso_examples.rs (line 2526)
2500fn aes_decrypt_with_padding_iso_ecb_into_string()
2501{
2502    println!("aes_decrypt_with_padding_iso_ecb_into_string()");
2503    use std::io::Write;
2504    use std::fmt::Write as _;
2505    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2506
2507    // Normal case for AES-128
2508    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2509    println!("K =\t{:#016X}", key);
2510    let mut a_aes = AES_128::new_with_key_u128(key);
2511
2512    let message = "In the beginning God created the heavens and the earth.";
2513    println!("M =\t{}", message);
2514    let mut cipher = [0_u8; 64];
2515    a_aes.encrypt_str_into_array(&message, &mut cipher);
2516    print!("C =\t");
2517    for c in cipher.clone()
2518        { print!("{:02X} ", c); }
2519    println!();
2520    let mut txt = String::new();
2521    for c in cipher.clone()
2522        { write!(txt, "{:02X} ", c); }
2523    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2524
2525    let mut converted= String::new();
2526    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2527    println!("B =\t{}", converted);
2528    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2529    assert_eq!(converted, message);
2530    println!();
2531
2532    // Normal case for AES-192
2533    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2534    print!("K =\t");
2535    for i in 0..24
2536        { print!("{:02X}", key[i]); }
2537    println!();
2538    let mut a_aes = AES_192::new_with_key(&key);
2539
2540    let message = "In the beginning God created the heavens and the earth.";
2541    println!("M =\t{}", message);
2542    let mut cipher = [0_u8; 64];
2543    a_aes.encrypt_str_into_array(&message, &mut cipher);
2544    print!("C =\t");
2545    for c in cipher.clone()
2546        { print!("{:02X} ", c); }
2547    println!();
2548    let mut txt = String::new();
2549    for c in cipher.clone()
2550        { write!(txt, "{:02X} ", c); }
2551    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2552
2553    let mut converted= String::new();
2554    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2555    println!("B =\t{}", converted);
2556    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2557    assert_eq!(converted, message);
2558    println!();
2559
2560    // Normal case for AES-256
2561    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2562    print!("K =\t");
2563    for i in 0..32
2564        { print!("{:02X}", key[i]); }
2565    println!();
2566    let mut a_aes = AES_256::new_with_key(&key);
2567
2568    let message = "In the beginning God created the heavens and the earth.";
2569    println!("M =\t{}", message);
2570    let mut cipher = [0_u8; 64];
2571    a_aes.encrypt_str_into_array(&message, &mut cipher);
2572    print!("C =\t");
2573    for c in cipher.clone()
2574        { print!("{:02X} ", c); }
2575    println!();
2576    let mut txt = String::new();
2577    for c in cipher.clone()
2578        { write!(txt, "{:02X} ", c); }
2579    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2580
2581    let mut converted= String::new();
2582    a_aes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2583    println!("B =\t{}", converted);
2584    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2585    assert_eq!(converted, message);
2586    println!();
2587
2588    // Normal case for Rijndael-256-256
2589    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2590    print!("K =\t");
2591    for i in 0..32
2592        { print!("{:02X}", key[i]); }
2593    println!();
2594    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2595
2596    let message = "In the beginning God created the heavens and the earth.";
2597    println!("M =\t{}", message);
2598    let mut cipher = [0_u8; 64];
2599    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2600    print!("C =\t");
2601    for c in cipher.clone()
2602        { print!("{:02X} ", c); }
2603    println!();
2604    let mut txt = String::new();
2605    for c in cipher.clone()
2606        { write!(txt, "{:02X} ", c); }
2607    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2608
2609    let mut converted= String::new();
2610    a_rijndael.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2611    println!("B =\t{}", converted);
2612    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2613    assert_eq!(converted, message);
2614    println!();
2615
2616    // Normal case for Rijndael-512-512 for post-quantum
2617    use cryptocol::number::SharedArrays;
2618    use cryptocol::hash::SHA3_512;
2619    let mut sha3 = SHA3_512::new();
2620    sha3.absorb_str("Post-quantum");
2621    let key: [u8; 64] = sha3.get_hash_value_in_array();
2622    print!("K =\t");
2623    for i in 0..64
2624        { print!("{:02X}", key[i]); }
2625    println!();
2626    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2627    let message = "In the beginning God created the heavens and the earth.";
2628    println!("M =\t{}", message);
2629    let mut cipher = [0_u8; 64];
2630    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
2631    print!("C =\t");
2632    for c in cipher.clone()
2633        { print!("{:02X} ", c); }
2634    println!();
2635    let mut txt = String::new();
2636    for c in cipher.clone()
2637        { write!(txt, "{:02X} ", c); }
2638    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2639    
2640    let mut converted= String::new();
2641    a_rijndael.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut converted);
2642    println!("B =\t{}", converted);
2643    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2644    assert_eq!(converted, message);
2645    println!("-------------------------------");
2646}
examples/des_ecb_iso_examples.rs (line 3760)
3734fn des_decrypt_with_padding_iso_ecb_into_string()
3735{
3736    println!("des_decrypt_with_padding_iso_ecb_into_string()");
3737    use std::io::Write;
3738    use std::fmt::Write as _;
3739    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3740
3741    // Normal case
3742    let key = 0x_1234567890ABCDEF_u64;
3743    println!("K =\t{:#016X}", key);
3744    let mut a_des = DES::new_with_key_u64(key);
3745
3746    let message = "In the beginning God created the heavens and the earth.";
3747    println!("M =\t{}", message);
3748    let mut cipher = Vec::<u8>::new();
3749    a_des.encrypt_str_into_vec(&message, &mut cipher);
3750    print!("C (16 rounds) =\t");
3751    for c in cipher.clone()
3752        { print!("{:02X} ", c); }
3753    println!();
3754    let mut txt = String::new();
3755    for c in cipher.clone()
3756        { write!(txt, "{:02X} ", c); }
3757    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3758
3759    let mut recovered = String::new();
3760    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3761    println!("B (16 rounds) =\t{}", recovered);
3762    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3763    assert_eq!(recovered, message);
3764    println!();
3765
3766    // Expanded case for 128 rounds
3767    let key = 0x_1234567890ABCDEF_u64;
3768    println!("K =\t{:#016X}", key);
3769    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3770
3771    let message = "In the beginning God created the heavens and the earth.";
3772    println!("M =\t{}", message);
3773    let mut cipher = Vec::<u8>::new();
3774    a_des.encrypt_str_into_vec(&message, &mut cipher);
3775    print!("C (128 rounds) =\t");
3776    for c in cipher.clone()
3777        { print!("{:02X} ", c); }
3778    println!();
3779    let mut txt = String::new();
3780    for c in cipher.clone()
3781        { write!(txt, "{:02X} ", c); }
3782    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3783
3784    let mut recovered = String::new();
3785    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3786    println!("B (128 rounds) =\t{}", recovered);
3787    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3788    assert_eq!(recovered, message);
3789    println!();
3790
3791    // Expanded case for 0 rounds which means that key is meaningless
3792    let key1 = 0x_1234567890ABCDEF_u64;
3793    let key2 = 0_u64;
3794    println!("K =\t{:#016X}", key);
3795    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3796    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3797
3798    let message = "In the beginning God created the heavens and the earth.";
3799    println!("M =\t{}", message);
3800    let mut cipher1 = Vec::<u8>::new();
3801    let mut cipher2 = Vec::<u8>::new();
3802    c_des.encrypt_str_into_vec(&message, &mut cipher1);
3803    d_des.encrypt_str_into_vec(&message, &mut cipher2);
3804    print!("C (0 rounds) =\t");
3805    for c in cipher1.clone()
3806        { print!("{:02X} ", c); }
3807    println!();
3808    let mut txt = String::new();
3809    for c in cipher1.clone()
3810        { write!(txt, "{:02X} ", c); }
3811    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3812    print!("D (0 rounds) =\t");
3813    for c in cipher2.clone()
3814        { print!("{:02X} ", c); }
3815    println!();
3816    let mut txt = String::new();
3817    for c in cipher2.clone()
3818        { write!(txt, "{:02X} ", c); }
3819    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3820
3821    let mut recovered1 = String::new();
3822    let mut recovered2 = String::new();
3823    c_des.decrypt_into_string(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3824    d_des.decrypt_into_string(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3825    println!("B1 (0 rounds) =\t{}", recovered1);
3826    println!("B2 (0 rounds) =\t{}", recovered2);
3827    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
3828    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
3829    assert_eq!(recovered1, message);
3830    assert_eq!(recovered2, message);
3831    assert_eq!(recovered1, recovered2);
3832    println!();
3833
3834    // Normal case for the message of 0 bytes
3835    let key = 0x_1234567890ABCDEF_u64;
3836    println!("K =\t{:#016X}", key);
3837    let mut a_des = DES::new_with_key_u64(key);
3838
3839    let message = "";
3840    println!("M =\t{}", message);
3841    let mut cipher = Vec::<u8>::new();
3842    a_des.encrypt_str_into_vec(&message, &mut cipher);
3843    print!("C =\t");
3844    for c in cipher.clone()
3845        { print!("{:02X} ", c); }
3846    println!();
3847    let mut txt = String::new();
3848    for c in cipher.clone()
3849        { write!(txt, "{:02X} ", c); }
3850    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3851
3852    let mut recovered = String::new();
3853    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3854    println!("B =\t{}", recovered);
3855    assert_eq!(recovered, "");
3856    assert_eq!(recovered, message);
3857    println!();
3858
3859    // Normal case for the message shorter than 8 bytes
3860    let key = 0x_1234567890ABCDEF_u64;
3861    println!("K =\t{:#016X}", key);
3862    let mut a_des = DES::new_with_key_u64(key);
3863
3864    let message = "7 bytes";
3865    println!("M =\t{}", message);
3866    let mut cipher = Vec::<u8>::new();
3867    a_des.encrypt_str_into_vec(&message, &mut cipher);
3868    print!("C =\t");
3869    for c in cipher.clone()
3870        { print!("{:02X} ", c); }
3871    println!();
3872    let mut txt = String::new();
3873    for c in cipher.clone()
3874        { write!(txt, "{:02X} ", c); }
3875    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3876
3877    let mut recovered = String::new();
3878    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3879    println!("B =\t{}", recovered);
3880    assert_eq!(recovered, "7 bytes");
3881    assert_eq!(recovered, message);
3882    println!();
3883
3884    // Normal case for the message of 8 bytes
3885    let key = 0x_1234567890ABCDEF_u64;
3886    println!("K =\t{:#016X}", key);
3887    let mut a_des = DES::new_with_key_u64(key);
3888
3889    let message = "I am OK.";
3890    println!("M =\t{}", message);
3891    let mut cipher = Vec::<u8>::new();
3892    a_des.encrypt_str_into_vec(&message, &mut cipher);
3893    print!("C =\t");
3894    for c in cipher.clone()
3895        { print!("{:02X} ", c); }
3896    println!();
3897    let mut txt = String::new();
3898    for c in cipher.clone()
3899        { write!(txt, "{:02X} ", c); }
3900    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3901
3902    let mut recovered = String::new();
3903    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3904    println!("B =\t{}", recovered);
3905    assert_eq!(recovered, "I am OK.");
3906    assert_eq!(recovered, message);
3907    println!();
3908
3909    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3910    let key = 0x_1234567890ABCDEF_u64;
3911    println!("K =\t{:#016X}", key);
3912    let mut a_des = DES::new_with_key_u64(key);
3913
3914    let message = "PARK Youngho";
3915    println!("M =\t{}", message);
3916    let mut cipher = Vec::<u8>::new();
3917    a_des.encrypt_str_into_vec(&message, &mut cipher);
3918    print!("C =\t");
3919    for c in cipher.clone()
3920        { print!("{:02X} ", c); }
3921    println!();
3922    let mut txt = String::new();
3923    for c in cipher.clone()
3924        { write!(txt, "{:02X} ", c); }
3925    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3926
3927    let mut recovered = String::new();
3928    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3929    println!("B =\t{}", recovered);
3930    assert_eq!(recovered, "PARK Youngho");
3931    assert_eq!(recovered, message);
3932    println!();
3933
3934    // Normal case for the message of 16 bytes
3935    let key = 0x_1234567890ABCDEF_u64;
3936    println!("K =\t{:#016X}", key);
3937    let mut a_des = DES::new_with_key_u64(key);
3938
3939    let message = "고맙습니다.";
3940    println!("M =\t{}", message);
3941    let mut cipher = Vec::<u8>::new();
3942    a_des.encrypt_str_into_vec(&message, &mut cipher);
3943    print!("C =\t");
3944    for c in cipher.clone()
3945        { print!("{:02X} ", c); }
3946    println!();
3947    let mut txt = String::new();
3948    for c in cipher.clone()
3949        { write!(txt, "{:02X} ", c); }
3950    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3951
3952    let mut recovered = String::new();
3953    a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3954    println!("B =\t{}", recovered);
3955    assert_eq!(recovered, "고맙습니다.");
3956    assert_eq!(recovered, message);
3957    println!("-------------------------------");
3958}
Source

fn decrypt_vec<U>(&mut self, cipher: &Vec<U>, message: *mut u8) -> u64
where U: SmallUInt + Copy + Clone,

Decrypts the data stored in a Vec<U> object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • cipher is an immutable reference to Vec<U> object, and is the place where the plaintext to be decrypted is stored.
  • message is a mutable pointer to u8 which is *mut u8, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * cipher.len() is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as decrypt_vec_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • size_of::<U>() * cipher.len() cannot be other than any multiple of size_of::<T>().
  • The size of the memory area which starts at message is assumed to be enough to store the plaintext. So, it is responsible for you to prepare the message area big enough!
  • The size of the area for plaintext does not have to be prepared more than size_of::<U>() * cipher.len() - 1.
  • If the size of the area for plaintext is prepared more than size_of::<U>() * cipher.len() - 1, the rest of the area will be filled with 0s.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = vec![0; 55];
a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = vec![0; 55];
a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = vec![0; 55];
taes.decrypt_vec(&cipher, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = vec![0; 55];
tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 636)
611fn bigcryptor64_decrypt_vec_with_padding_iso_ecb()
612{
613    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb()");
614    use std::io::Write;
615    use std::fmt::Write as _;
616    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
617
618    // TDES case
619    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622    let message = "In the beginning God created the heavens and the earth.";
623    println!("M =\t{}", message);
624    let mut cipher = Vec::<u8>::new();
625    tdes.encrypt_str_into_vec(&message, &mut cipher);
626    print!("C =\t");
627    for c in cipher.clone()
628        { print!("{:02X} ", c); }
629    println!();
630    let mut txt = String::new();
631    for c in cipher.clone()
632        { write!(txt, "{:02X} ", c); }
633    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635    let mut recovered = vec![0; 55];
636    tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637    print!("Ba =\t");
638    for b in recovered.clone()
639        { print!("{:02X} ", b); }
640    println!();
641    let mut txt = String::new();
642    for c in recovered.clone()
643        { write!(txt, "{:02X} ", c); }
644    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646    let mut converted = String::new();
647    unsafe { converted.as_mut_vec() }.append(&mut recovered);
648    
649    println!("Bb =\t{}", converted);
650    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651    assert_eq!(converted, message);
652    println!("-------------------------------");
653}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 676)
649fn bigcryptor128_decrypt_vec_with_padding_iso_ecb()
650{
651    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb()");
652    use std::io::Write;
653    use std::fmt::Write as _;
654    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
655
656    // TAES_128 case
657    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
658                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
659                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
660    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
661    println!("IV =	{:#034X}", iv);
662    let message = "In the beginning God created the heavens and the earth.";
663    println!("M =\t{}", message);
664    let mut cipher = Vec::<u8>::new();
665    taes.encrypt_str_into_vec(&message, &mut cipher);
666    print!("C =\t");
667    for c in cipher.clone()
668        { print!("{:02X} ", c); }
669    println!();
670    let mut txt = String::new();
671    for c in cipher.clone()
672        { write!(txt, "{:02X} ", c); }
673    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
674
675    let mut recovered = vec![0; 55];
676    taes.decrypt_vec(&cipher, recovered.as_mut_ptr());
677    print!("Ba =\t");
678    for b in recovered.clone()
679        { print!("{:02X} ", b); }
680    println!();
681    let mut txt = String::new();
682    for c in recovered.clone()
683        { write!(txt, "{:02X} ", c); }
684    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686    let mut converted = String::new();
687    unsafe { converted.as_mut_vec() }.append(&mut recovered);
688    
689    println!("Bb =\t{}", converted);
690    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691    assert_eq!(converted, message);
692    println!("-------------------------------");
693}
examples/aes_ecb_iso_examples.rs (line 2674)
2648fn aes_decrypt_vec_with_padding_iso_ecb()
2649{
2650    println!("aes_decrypt_vec_with_padding_iso_ecb()");
2651    use std::io::Write;
2652    use std::fmt::Write as _;
2653    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2654
2655    // Normal case for AES-128
2656    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2657    println!("K =\t{:#016X}", key);
2658    let mut a_aes = AES_128::new_with_key_u128(key);
2659
2660    let message = "In the beginning God created the heavens and the earth.";
2661    println!("M =\t{}", message);
2662    let mut cipher = Vec::<u8>::new();
2663    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2664    print!("C =\t");
2665    for c in cipher.clone()
2666        { print!("{:02X} ", c); }
2667    println!();
2668    let mut txt = String::new();
2669    for c in cipher.clone()
2670        { write!(txt, "{:02X} ", c); }
2671    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2672
2673    let mut recovered = vec![0; 55];
2674    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2675    print!("Ba =\t");
2676    for b in recovered.clone()
2677        { print!("{:02X} ", b); }
2678    println!();
2679    let mut txt = String::new();
2680    for c in recovered.clone()
2681        { write!(txt, "{:02X} ", c); }
2682    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2683
2684    let mut converted = String::new();
2685    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2686    
2687    println!("Bb =\t{}", converted);
2688    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2689    assert_eq!(converted, message);
2690    println!();
2691
2692    // Normal case for AES-192
2693    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2694    print!("K =\t");
2695    for i in 0..24
2696        { print!("{:02X}", key[i]); }
2697    println!();
2698    let mut a_aes = AES_192::new_with_key(&key);
2699
2700    let message = "In the beginning God created the heavens and the earth.";
2701    println!("M =\t{}", message);
2702    let mut cipher = Vec::<u8>::new();
2703    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2704    print!("C =\t");
2705    for c in cipher.clone()
2706        { print!("{:02X} ", c); }
2707    println!();
2708    let mut txt = String::new();
2709    for c in cipher.clone()
2710        { write!(txt, "{:02X} ", c); }
2711    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2712
2713    let mut recovered = vec![0; 55];
2714    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2715    print!("Ba =\t");
2716    for b in recovered.clone()
2717        { print!("{:02X} ", b); }
2718    println!();
2719    let mut txt = String::new();
2720    for c in recovered.clone()
2721        { write!(txt, "{:02X} ", c); }
2722    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2723
2724    let mut converted = String::new();
2725    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2726    
2727    println!("Bb =\t{}", converted);
2728    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2729    assert_eq!(converted, message);
2730    println!();
2731
2732    // Normal case for AES-256
2733    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2734    print!("K =\t");
2735    for i in 0..32
2736        { print!("{:02X}", key[i]); }
2737    println!();
2738    let mut a_aes = AES_256::new_with_key(&key);
2739
2740    let message = "In the beginning God created the heavens and the earth.";
2741    println!("M =\t{}", message);
2742    let mut cipher = Vec::<u8>::new();
2743    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2744    print!("C =\t");
2745    for c in cipher.clone()
2746        { print!("{:02X} ", c); }
2747    println!();
2748    let mut txt = String::new();
2749    for c in cipher.clone()
2750        { write!(txt, "{:02X} ", c); }
2751    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2752
2753    let mut recovered = vec![0; 55];
2754    a_aes.decrypt_vec(&cipher, recovered.as_mut_ptr());
2755    print!("Ba =\t");
2756    for b in recovered.clone()
2757        { print!("{:02X} ", b); }
2758    println!();
2759    let mut txt = String::new();
2760    for c in recovered.clone()
2761        { write!(txt, "{:02X} ", c); }
2762    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2763
2764    let mut converted = String::new();
2765    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2766    
2767    println!("Bb =\t{}", converted);
2768    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2769    assert_eq!(converted, message);
2770    println!();
2771
2772    // Normal case for Rijndael-256-256
2773    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2774    print!("K =\t");
2775    for i in 0..32
2776        { print!("{:02X}", key[i]); }
2777    println!();
2778    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2779
2780    let message = "In the beginning God created the heavens and the earth.";
2781    println!("M =\t{}", message);
2782    let mut cipher = Vec::<u8>::new();
2783    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2784    print!("C =\t");
2785    for c in cipher.clone()
2786        { print!("{:02X} ", c); }
2787    println!();
2788    let mut txt = String::new();
2789    for c in cipher.clone()
2790        { write!(txt, "{:02X} ", c); }
2791    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
2792
2793    let mut recovered = vec![0; 55];
2794    a_rijndael.decrypt_vec(&cipher, recovered.as_mut_ptr());
2795    print!("Ba =\t");
2796    for b in recovered.clone()
2797        { print!("{:02X} ", b); }
2798    println!();
2799    let mut txt = String::new();
2800    for c in recovered.clone()
2801        { write!(txt, "{:02X} ", c); }
2802    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2803
2804    let mut converted = String::new();
2805    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2806    
2807    println!("Bb =\t{}", converted);
2808    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2809    assert_eq!(converted, message);
2810    println!();
2811
2812    // Normal case for Rijndael-512-512 for post-quantum
2813    use cryptocol::number::SharedArrays;
2814    use cryptocol::hash::SHA3_512;
2815    let mut sha3 = SHA3_512::new();
2816    sha3.absorb_str("Post-quantum");
2817    let key: [u8; 64] = sha3.get_hash_value_in_array();
2818    print!("K =\t");
2819    for i in 0..64
2820        { print!("{:02X}", key[i]); }
2821    println!();
2822    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
2823    let message = "In the beginning God created the heavens and the earth.";
2824    println!("M =\t{}", message);
2825    let mut cipher = Vec::<u8>::new();
2826    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2827    print!("C =\t");
2828    for c in cipher.clone()
2829        { print!("{:02X} ", c); }
2830    println!();
2831    let mut txt = String::new();
2832    for c in cipher.clone()
2833        { write!(txt, "{:02X} ", c); }
2834    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
2835
2836    let mut recovered = vec![0; 55];
2837    a_rijndael.decrypt_vec(&cipher, recovered.as_mut_ptr());
2838    print!("Ba =\t");
2839    for b in recovered.clone()
2840        { print!("{:02X} ", b); }
2841    println!();
2842    let mut txt = String::new();
2843    for c in recovered.clone()
2844        { write!(txt, "{:02X} ", c); }
2845    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2846
2847    let mut converted = String::new();
2848    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2849    
2850    println!("Bb =\t{}", converted);
2851    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2852    assert_eq!(converted, message);
2853    println!("-------------------------------");
2854}
examples/des_ecb_iso_examples.rs (line 3986)
3960fn des_decrypt_vec_with_padding_iso_ecb()
3961{
3962    println!("des_decrypt_vec_with_padding_iso_ecb()");
3963    use std::io::Write;
3964    use std::fmt::Write as _;
3965    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3966
3967    // Normal case
3968    let key = 0x_1234567890ABCDEF_u64;
3969    println!("K =\t{:#016X}", key);
3970    let mut a_des = DES::new_with_key_u64(key);
3971
3972    let message = "In the beginning God created the heavens and the earth.";
3973    println!("M =\t{}", message);
3974    let mut cipher = Vec::<u8>::new();
3975    a_des.encrypt_str_into_vec(&message, &mut cipher);
3976    print!("C (16 rounds) =\t");
3977    for c in cipher.clone()
3978        { print!("{:02X} ", c); }
3979    println!();
3980    let mut txt = String::new();
3981    for c in cipher.clone()
3982        { write!(txt, "{:02X} ", c); }
3983    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3984
3985    let mut recovered = vec![0; 55];
3986    a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
3987    print!("Ba (16 rounds) =\t");
3988    for b in recovered.clone()
3989        { print!("{:02X} ", b); }
3990    println!();
3991    let mut txt = String::new();
3992    for c in recovered.clone()
3993        { write!(txt, "{:02X} ", c); }
3994    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3995
3996    let mut converted = String::new();
3997    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3998    
3999    println!("Bb (16 rounds) =\t{}", converted);
4000    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4001    assert_eq!(converted, message);
4002    println!();
4003
4004    // Expanded case for 128 rounds
4005    let key = 0x_1234567890ABCDEF_u64;
4006    println!("K =\t{:#016X}", key);
4007    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4008
4009    let message = "In the beginning God created the heavens and the earth.";
4010    println!("M =\t{}", message);
4011    let mut cipher = Vec::<u8>::new();
4012    a_des.encrypt_str_into_vec(&message, &mut cipher);
4013    print!("C (128 rounds) =\t");
4014    for c in cipher.clone()
4015        { print!("{:02X} ", c); }
4016    println!();
4017    let mut txt = String::new();
4018    for c in cipher.clone()
4019        { write!(txt, "{:02X} ", c); }
4020    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4021
4022    let mut recovered = vec![0; 55];
4023    a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4024    print!("Ba (128 rounds) =\t");
4025    for b in recovered.clone()
4026        { print!("{:02X} ", b); }
4027    println!();
4028    let mut txt = String::new();
4029    for c in recovered.clone()
4030        { write!(txt, "{:02X} ", c); }
4031    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4032
4033    let mut converted = String::new();
4034    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4035    
4036    println!("Bb (128 rounds) =\t{}", converted);
4037    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4038    assert_eq!(converted, message);
4039    println!();
4040
4041    // Expanded case for 0 rounds which means that key is meaningless
4042    let key1 = 0x_1234567890ABCDEF_u64;
4043    let key2 = 0_u64;
4044    println!("K =\t{:#016X}", key);
4045    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4046    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4047
4048    let message = "In the beginning God created the heavens and the earth.";
4049    println!("M =\t{}", message);
4050    let mut cipher1 = Vec::<u8>::new();
4051    let mut cipher2 = Vec::<u8>::new();
4052    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4053    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4054    print!("C (0 rounds) =\t");
4055    for c in cipher1.clone()
4056        { print!("{:02X} ", c); }
4057    println!();
4058    let mut txt = String::new();
4059    for c in cipher1.clone()
4060        { write!(txt, "{:02X} ", c); }
4061    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4062    print!("D (0 rounds) =\t");
4063    for c in cipher2.clone()
4064        { print!("{:02X} ", c); }
4065    println!();
4066    let mut txt = String::new();
4067    for c in cipher2.clone()
4068        { write!(txt, "{:02X} ", c); }
4069    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4070
4071    let mut recovered1 = vec![0; 55];
4072    let mut recovered2 = vec![0; 55];
4073    c_des.decrypt_vec(&cipher1, recovered1.as_mut_ptr());
4074    d_des.decrypt_vec(&cipher2, recovered2.as_mut_ptr());
4075    print!("B1a (0 rounds) =\t");
4076    for b in recovered1.clone()
4077        { print!("{:02X} ", b); }
4078    println!();
4079    let mut txt = String::new();
4080    for c in recovered1.clone()
4081        { write!(txt, "{:02X} ", c); }
4082    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4083    print!("B2a (0 rounds) =\t");
4084    for b in recovered2.clone()
4085        { print!("{:02X} ", b); }
4086    println!();
4087    let mut txt = String::new();
4088    for c in recovered2.clone()
4089        { write!(txt, "{:02X} ", c); }
4090    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4091
4092    let mut converted1 = String::new();
4093    let mut converted2 = String::new();
4094    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4095    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4096    
4097    println!("B1b (0 rounds) =\t{}", converted1);
4098    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4099    assert_eq!(converted1, message);
4100    println!("B2b (0 rounds) =\t{}", converted2);
4101    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4102    assert_eq!(converted2, message);
4103    assert_eq!(converted1, converted1);
4104    println!();
4105
4106    // Normal case for the message of 0 bytes
4107    let key = 0x_1234567890ABCDEF_u64;
4108    println!("K =\t{:#016X}", key);
4109    let mut a_des = DES::new_with_key_u64(key);
4110
4111    let message = "";
4112    println!("M =\t{}", message);
4113    let mut cipher = Vec::<u8>::new();
4114    a_des.encrypt_str_into_vec(&message, &mut cipher);
4115    print!("C =\t");
4116    for c in cipher.clone()
4117        { print!("{:02X} ", c); }
4118    println!();
4119    let mut txt = String::new();
4120    for c in cipher.clone()
4121        { write!(txt, "{:02X} ", c); }
4122    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4123
4124    let mut recovered = vec![0; 8];
4125    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4126    print!("Ba =\t");
4127    for b in recovered.clone()
4128        { print!("{:02X} ", b); }
4129    println!();
4130    let mut txt = String::new();
4131    for c in recovered.clone()
4132        { write!(txt, "{:02X} ", c); }
4133    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4134
4135    let mut converted = String::new();
4136    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4137    converted.truncate(len as usize);
4138    
4139    println!("Bb =\t{}", converted);
4140    assert_eq!(converted, "");
4141    assert_eq!(converted, message);
4142    println!();
4143
4144    // Normal case for the message shorter than 8 bytes
4145    let key = 0x_1234567890ABCDEF_u64;
4146    println!("K =\t{:#016X}", key);
4147    let mut a_des = DES::new_with_key_u64(key);
4148
4149    let message = "7 bytes";
4150    println!("M =\t{}", message);
4151    let mut cipher = Vec::<u8>::new();
4152    a_des.encrypt_str_into_vec(&message, &mut cipher);
4153    print!("C =\t");
4154    for c in cipher.clone()
4155        { print!("{:02X} ", c); }
4156    println!();
4157    let mut txt = String::new();
4158    for c in cipher.clone()
4159        { write!(txt, "{:02X} ", c); }
4160    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4161    
4162    let mut recovered = vec![0; 8];
4163    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4164    print!("Ba =\t");
4165    for b in recovered.clone()
4166        { print!("{:02X} ", b); }
4167    println!();
4168    let mut txt = String::new();
4169    for c in recovered.clone()
4170        { write!(txt, "{:02X} ", c); }
4171    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4172
4173    let mut converted = String::new();
4174    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4175    converted.truncate(len as usize);
4176
4177    println!("Bb =\t{}", converted);
4178    assert_eq!(converted, "7 bytes");
4179    assert_eq!(converted, message);
4180    println!();
4181
4182    // Normal case for the message of 8 bytes
4183    let key = 0x_1234567890ABCDEF_u64;
4184    println!("K =\t{:#016X}", key);
4185    let mut a_des = DES::new_with_key_u64(key);
4186
4187    let message = "I am OK.";
4188    println!("M =\t{}", message);
4189    let mut cipher = Vec::<u8>::new();
4190    a_des.encrypt_str_into_vec(&message, &mut cipher);
4191    print!("C =\t");
4192    for c in cipher.clone()
4193        { print!("{:02X} ", c); }
4194    println!();
4195    let mut txt = String::new();
4196    for c in cipher.clone()
4197        { write!(txt, "{:02X} ", c); }
4198    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4199    
4200    let mut recovered = vec![0; 16];
4201    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4202    print!("Ba =\t");
4203    for b in recovered.clone()
4204        { print!("{:02X} ", b); }
4205    println!();
4206    let mut txt = String::new();
4207    for c in recovered.clone()
4208        { write!(txt, "{:02X} ", c); }
4209    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4210
4211    let mut converted = String::new();
4212    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4213    converted.truncate(len as usize);
4214    
4215    println!("Bb =\t{}", converted);
4216    assert_eq!(converted, "I am OK.");
4217    assert_eq!(converted, message);
4218    println!();
4219
4220    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4221    let key = 0x_1234567890ABCDEF_u64;
4222    println!("K =\t{:#016X}", key);
4223    let mut a_des = DES::new_with_key_u64(key);
4224
4225    let message = "PARK Youngho";
4226    println!("M =\t{}", message);
4227    let mut cipher = Vec::<u8>::new();
4228    a_des.encrypt_str_into_vec(&message, &mut cipher);
4229    print!("C =\t");
4230    for c in cipher.clone()
4231        { print!("{:02X} ", c); }
4232    println!();
4233    let mut txt = String::new();
4234    for c in cipher.clone()
4235        { write!(txt, "{:02X} ", c); }
4236    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4237
4238    let mut recovered = vec![0; 16];
4239    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4240    print!("Ba =\t");
4241    for b in recovered.clone()
4242        { print!("{:02X} ", b); }
4243    println!();
4244    let mut txt = String::new();
4245    for c in recovered.clone()
4246        { write!(txt, "{:02X} ", c); }
4247    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4248
4249    let mut converted = String::new();
4250    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4251    converted.truncate(len as usize);
4252    
4253    println!("Bb =\t{}", converted);
4254    assert_eq!(converted, "PARK Youngho");
4255    assert_eq!(converted, message);
4256    println!();
4257
4258    // Normal case for the message of 16 bytes
4259    let key = 0x_1234567890ABCDEF_u64;
4260    println!("K =\t{:#016X}", key);
4261    let mut a_des = DES::new_with_key_u64(key);
4262
4263    let message = "고맙습니다.";
4264    println!("M =\t{}", message);
4265    let mut cipher = Vec::<u8>::new();
4266    a_des.encrypt_str_into_vec(&message, &mut cipher);
4267    print!("C =\t");
4268    for c in cipher.clone()
4269        { print!("{:02X} ", c); }
4270    println!();
4271    let mut txt = String::new();
4272    for c in cipher.clone()
4273        { write!(txt, "{:02X} ", c); }
4274    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4275
4276    let mut recovered = vec![0; 24];
4277    let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4278    print!("Ba =\t");
4279    for b in recovered.clone()
4280        { print!("{:02X} ", b); }
4281    println!();
4282    let mut txt = String::new();
4283    for c in recovered.clone()
4284        { write!(txt, "{:02X} ", c); }
4285    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4286
4287    let mut converted = String::new();
4288    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4289    converted.truncate(len as usize);
4290    
4291    println!("Bb =\t{}", converted);
4292    assert_eq!(converted, "고맙습니다.");
4293    assert_eq!(converted, message);
4294    println!("-------------------------------");
4295}
Source

fn decrypt_vec_into_vec<U, V>( &mut self, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Decrypts the data stored in a Vec<U> object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in Vec<V>.

§Arguments
  • cipher is an immutable reference to Vec<U> object, and is the place where the ciphertext to be decrypted is stored.
  • message is a mutable reference to Vec<U> object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * cipher.len() is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = Vec::<u8>::new();
a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = Vec::<u8>::new();
a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = Vec::<u8>::new();
taes.decrypt_vec_into_vec(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = Vec::<u8>::new();
tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 680)
655fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()
656{
657    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()");
658    use std::io::Write;
659    use std::fmt::Write as _;
660    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
661
662    // TDES case
663    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666    let message = "In the beginning God created the heavens and the earth.";
667    println!("M =\t{}", message);
668    let mut cipher = Vec::<u8>::new();
669    tdes.encrypt_str_into_vec(&message, &mut cipher);
670    print!("C =\t");
671    for c in cipher.clone()
672        { print!("{:02X} ", c); }
673    println!();
674    let mut txt = String::new();
675    for c in cipher.clone()
676        { write!(txt, "{:02X} ", c); }
677    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679    let mut recovered = Vec::<u8>::new();
680    tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681    print!("Ba =\t");
682    for b in recovered.clone()
683        { print!("{:02X} ", b); }
684    println!();
685    let mut txt = String::new();
686    for c in recovered.clone()
687        { write!(txt, "{:02X} ", c); }
688    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690    let mut converted = String::new();
691    unsafe { converted.as_mut_vec() }.append(&mut recovered);
692    
693    println!("Bb =\t{}", converted);
694    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695    assert_eq!(converted, message);
696    println!("-------------------------------");
697}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 722)
695fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_vec()
696{
697    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_vec()");
698    use std::io::Write;
699    use std::fmt::Write as _;
700    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
701
702    // TAES_128 case
703    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
704                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
705                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
706    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
707    println!("IV =	{:#034X}", iv);
708    let message = "In the beginning God created the heavens and the earth.";
709    println!("M =\t{}", message);
710    let mut cipher = Vec::<u8>::new();
711    taes.encrypt_str_into_vec(&message, &mut cipher);
712    print!("C =\t");
713    for c in cipher.clone()
714        { print!("{:02X} ", c); }
715    println!();
716    let mut txt = String::new();
717    for c in cipher.clone()
718        { write!(txt, "{:02X} ", c); }
719    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
720
721    let mut recovered = Vec::<u8>::new();
722    taes.decrypt_vec_into_vec(&cipher, &mut recovered);
723    print!("Ba =\t");
724    for b in recovered.clone()
725        { print!("{:02X} ", b); }
726    println!();
727    let mut txt = String::new();
728    for c in recovered.clone()
729        { write!(txt, "{:02X} ", c); }
730    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732    let mut converted = String::new();
733    unsafe { converted.as_mut_vec() }.append(&mut recovered);
734    
735    println!("Bb =\t{}", converted);
736    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737    assert_eq!(converted, message);
738    println!("-------------------------------");
739}
examples/aes_ecb_iso_examples.rs (line 2882)
2856fn aes_decrypt_vec_with_padding_iso_ecb_into_vec()
2857{
2858    println!("aes_decrypt_vec_with_padding_iso_ecb_into_vec()");
2859    use std::io::Write;
2860    use std::fmt::Write as _;
2861    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
2862
2863    // Normal case for AES-128
2864    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
2865    println!("K =\t{:#016X}", key);
2866    let mut a_aes = AES_128::new_with_key_u128(key);
2867
2868    let message = "In the beginning God created the heavens and the earth.";
2869    println!("M =\t{}", message);
2870    let mut cipher = Vec::<u8>::new();
2871    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2872    print!("C =\t");
2873    for c in cipher.clone()
2874        { print!("{:02X} ", c); }
2875    println!();
2876    let mut txt = String::new();
2877    for c in cipher.clone()
2878        { write!(txt, "{:02X} ", c); }
2879    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
2880
2881    let mut recovered = Vec::<u8>::new();
2882    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2883    print!("Ba =\t");
2884    for b in recovered.clone()
2885        { print!("{:02X} ", b); }
2886    println!();
2887    let mut txt = String::new();
2888    for c in recovered.clone()
2889        { write!(txt, "{:02X} ", c); }
2890    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2891
2892    let mut converted = String::new();
2893    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2894    
2895    println!("Bb =\t{}", converted);
2896    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2897    assert_eq!(converted, message);
2898    println!();
2899
2900    // Normal case for AES-192
2901    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2902    print!("K =\t");
2903    for i in 0..24
2904        { print!("{:02X}", key[i]); }
2905    println!();
2906    let mut a_aes = AES_192::new_with_key(&key);
2907
2908    let message = "In the beginning God created the heavens and the earth.";
2909    println!("M =\t{}", message);
2910    let mut cipher = Vec::<u8>::new();
2911    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2912    print!("C =\t");
2913    for c in cipher.clone()
2914        { print!("{:02X} ", c); }
2915    println!();
2916    let mut txt = String::new();
2917    for c in cipher.clone()
2918        { write!(txt, "{:02X} ", c); }
2919    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
2920
2921    let mut recovered = Vec::<u8>::new();
2922    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2923    print!("Ba =\t");
2924    for b in recovered.clone()
2925        { print!("{:02X} ", b); }
2926    println!();
2927    let mut txt = String::new();
2928    for c in recovered.clone()
2929        { write!(txt, "{:02X} ", c); }
2930    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2931
2932    let mut converted = String::new();
2933    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2934    
2935    println!("Bb =\t{}", converted);
2936    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2937    assert_eq!(converted, message);
2938    println!();
2939
2940    // Normal case for AES-256
2941    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2942    print!("K =\t");
2943    for i in 0..32
2944        { print!("{:02X}", key[i]); }
2945    println!();
2946    let mut a_aes = AES_256::new_with_key(&key);
2947
2948    let message = "In the beginning God created the heavens and the earth.";
2949    println!("M =\t{}", message);
2950    let mut cipher = Vec::<u8>::new();
2951    a_aes.encrypt_str_into_vec(&message, &mut cipher);
2952    print!("C =\t");
2953    for c in cipher.clone()
2954        { print!("{:02X} ", c); }
2955    println!();
2956    let mut txt = String::new();
2957    for c in cipher.clone()
2958        { write!(txt, "{:02X} ", c); }
2959    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
2960
2961    let mut recovered = Vec::<u8>::new();
2962    a_aes.decrypt_vec_into_vec(&cipher, &mut recovered);
2963    print!("Ba =\t");
2964    for b in recovered.clone()
2965        { print!("{:02X} ", b); }
2966    println!();
2967    let mut txt = String::new();
2968    for c in recovered.clone()
2969        { write!(txt, "{:02X} ", c); }
2970    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2971
2972    let mut converted = String::new();
2973    unsafe { converted.as_mut_vec() }.append(&mut recovered);
2974    
2975    println!("Bb =\t{}", converted);
2976    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2977    assert_eq!(converted, message);
2978    println!();
2979
2980    // Normal case for Rijndael-256-256
2981    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
2982    print!("K =\t");
2983    for i in 0..32
2984        { print!("{:02X}", key[i]); }
2985    println!();
2986    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
2987
2988    let message = "In the beginning God created the heavens and the earth.";
2989    println!("M =\t{}", message);
2990    let mut cipher = Vec::<u8>::new();
2991    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
2992    print!("C =\t");
2993    for c in cipher.clone()
2994        { print!("{:02X} ", c); }
2995    println!();
2996    let mut txt = String::new();
2997    for c in cipher.clone()
2998        { write!(txt, "{:02X} ", c); }
2999    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3000
3001    let mut recovered = Vec::<u8>::new();
3002    a_rijndael.decrypt_vec_into_vec(&cipher, &mut recovered);
3003    print!("Ba =\t");
3004    for b in recovered.clone()
3005        { print!("{:02X} ", b); }
3006    println!();
3007    let mut txt = String::new();
3008    for c in recovered.clone()
3009        { write!(txt, "{:02X} ", c); }
3010    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3011
3012    let mut converted = String::new();
3013    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3014    
3015    println!("Bb =\t{}", converted);
3016    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3017    assert_eq!(converted, message);
3018    println!();
3019
3020    // Normal case for Rijndael-512-512 for post-quantum
3021    use cryptocol::number::SharedArrays;
3022    use cryptocol::hash::SHA3_512;
3023    let mut sha3 = SHA3_512::new();
3024    sha3.absorb_str("Post-quantum");
3025    let key: [u8; 64] = sha3.get_hash_value_in_array();
3026    print!("K =\t");
3027    for i in 0..64
3028        { print!("{:02X}", key[i]); }
3029    println!();
3030    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3031
3032    let message = "In the beginning God created the heavens and the earth.";
3033    println!("M =\t{}", message);
3034    let mut cipher = Vec::<u8>::new();
3035    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3036    print!("C =\t");
3037    for c in cipher.clone()
3038        { print!("{:02X} ", c); }
3039    println!();
3040    let mut txt = String::new();
3041    for c in cipher.clone()
3042        { write!(txt, "{:02X} ", c); }
3043    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3044    
3045    let mut recovered = Vec::<u8>::new();
3046    a_rijndael.decrypt_vec_into_vec(&cipher, &mut recovered);
3047    print!("Ba =\t");
3048    for b in recovered.clone()
3049        { print!("{:02X} ", b); }
3050    println!();
3051    let mut txt = String::new();
3052    for c in recovered.clone()
3053        { write!(txt, "{:02X} ", c); }
3054    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3055
3056    let mut converted = String::new();
3057    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3058    
3059    println!("Bb =\t{}", converted);
3060    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3061    assert_eq!(converted, message);
3062    println!("-------------------------------");
3063}
examples/des_ecb_iso_examples.rs (line 4323)
4297fn des_decrypt_vec_with_padding_iso_ecb_into_vec()
4298{
4299    println!("des_decrypt_vec_with_padding_iso_ecb_into_vec()");
4300    use std::io::Write;
4301    use std::fmt::Write as _;
4302    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4303
4304    // Normal case
4305    let key = 0x_1234567890ABCDEF_u64;
4306    println!("K =\t{:#016X}", key);
4307    let mut a_des = DES::new_with_key_u64(key);
4308
4309    let message = "In the beginning God created the heavens and the earth.";
4310    println!("M =\t{}", message);
4311    let mut cipher = Vec::<u8>::new();
4312    a_des.encrypt_str_into_vec(&message, &mut cipher);
4313    print!("C (16 rounds) =\t");
4314    for c in cipher.clone()
4315        { print!("{:02X} ", c); }
4316    println!();
4317    let mut txt = String::new();
4318    for c in cipher.clone()
4319        { write!(txt, "{:02X} ", c); }
4320    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4321
4322    let mut recovered = Vec::<u8>::new();
4323    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4324    print!("Ba (16 rounds) =\t");
4325    for b in recovered.clone()
4326        { print!("{:02X} ", b); }
4327    println!();
4328    let mut txt = String::new();
4329    for c in recovered.clone()
4330        { write!(txt, "{:02X} ", c); }
4331    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4332
4333    let mut converted = String::new();
4334    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4335    
4336    println!("Bb (16 rounds) =\t{}", converted);
4337    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4338    assert_eq!(converted, message);
4339    println!();
4340
4341    // Expanded case for 128 rounds
4342    let key = 0x_1234567890ABCDEF_u64;
4343    println!("K =\t{:#016X}", key);
4344    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4345
4346    let message = "In the beginning God created the heavens and the earth.";
4347    println!("M =\t{}", message);
4348    let mut cipher = Vec::<u8>::new();
4349    a_des.encrypt_str_into_vec(&message, &mut cipher);
4350    print!("C (128 rounds) =\t");
4351    for c in cipher.clone()
4352        { print!("{:02X} ", c); }
4353    println!();
4354    let mut txt = String::new();
4355    for c in cipher.clone()
4356        { write!(txt, "{:02X} ", c); }
4357    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4358
4359    let mut recovered = Vec::<u8>::new();
4360    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4361    print!("Ba (128 rounds) =\t");
4362    for b in recovered.clone()
4363        { print!("{:02X} ", b); }
4364    println!();
4365    let mut txt = String::new();
4366    for c in recovered.clone()
4367        { write!(txt, "{:02X} ", c); }
4368    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4369
4370    let mut converted = String::new();
4371    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4372    
4373    println!("Bb (128 rounds) =\t{}", converted);
4374    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4375    assert_eq!(converted, message);
4376    println!();
4377
4378    // Expanded case for 0 rounds which means that key is meaningless
4379    let key1 = 0x_1234567890ABCDEF_u64;
4380    let key2 = 0_u64;
4381    println!("K =\t{:#016X}", key);
4382    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4383    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4384
4385    let message = "In the beginning God created the heavens and the earth.";
4386    println!("M =\t{}", message);
4387    let mut cipher1 = Vec::<u8>::new();
4388    let mut cipher2 = Vec::<u8>::new();
4389    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4390    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4391    print!("C (0 rounds) =\t");
4392    for c in cipher1.clone()
4393        { print!("{:02X} ", c); }
4394    println!();
4395    let mut txt = String::new();
4396    for c in cipher1.clone()
4397        { write!(txt, "{:02X} ", c); }
4398    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4399    print!("D (0 rounds) =\t");
4400    for c in cipher2.clone()
4401        { print!("{:02X} ", c); }
4402    println!();
4403    let mut txt = String::new();
4404    for c in cipher2.clone()
4405        { write!(txt, "{:02X} ", c); }
4406    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4407
4408    let mut recovered1 = Vec::<u8>::new();
4409    let mut recovered2 = Vec::<u8>::new();
4410    c_des.decrypt_vec_into_vec(&cipher1, &mut recovered1);
4411    d_des.decrypt_vec_into_vec(&cipher2, &mut recovered2);
4412    print!("B1a (0 rounds) =\t");
4413    for b in recovered1.clone()
4414        { print!("{:02X} ", b); }
4415    println!();
4416    let mut txt = String::new();
4417    for c in recovered1.clone()
4418        { write!(txt, "{:02X} ", c); }
4419    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4420    print!("B2a (0 rounds) =\t");
4421    for b in recovered2.clone()
4422        { print!("{:02X} ", b); }
4423    println!();
4424    let mut txt = String::new();
4425    for c in recovered2.clone()
4426        { write!(txt, "{:02X} ", c); }
4427    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4428
4429    let mut converted1 = String::new();
4430    let mut converted2 = String::new();
4431    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4432    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4433    
4434    println!("B1b (0 rounds) =\t{}", converted1);
4435    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4436    assert_eq!(converted1, message);
4437    println!("B2b (0 rounds) =\t{}", converted2);
4438    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4439    assert_eq!(converted2, message);
4440    assert_eq!(converted1, converted1);
4441    println!();
4442
4443    // Normal case for the message of 0 bytes
4444    let key = 0x_1234567890ABCDEF_u64;
4445    println!("K =\t{:#016X}", key);
4446    let mut a_des = DES::new_with_key_u64(key);
4447
4448    let message = "";
4449    println!("M =\t{}", message);
4450    let mut cipher = Vec::<u8>::new();
4451    a_des.encrypt_str_into_vec(&message, &mut cipher);
4452    print!("C =\t");
4453    for c in cipher.clone()
4454        { print!("{:02X} ", c); }
4455    println!();
4456    let mut txt = String::new();
4457    for c in cipher.clone()
4458        { write!(txt, "{:02X} ", c); }
4459    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4460
4461    let mut recovered = Vec::<u8>::new();
4462    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4463    print!("Ba =\t");
4464    for b in recovered.clone()
4465        { print!("{:02X} ", b); }
4466    println!();
4467    let mut txt = String::new();
4468    for c in recovered.clone()
4469        { write!(txt, "{:02X} ", c); }
4470    assert_eq!(txt, "");
4471
4472    let mut converted = String::new();
4473    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4474    
4475    println!("Bb =\t{}", converted);
4476    assert_eq!(converted, "");
4477    assert_eq!(converted, message);
4478    println!();
4479
4480    // Normal case for the message shorter than 8 bytes
4481    let key = 0x_1234567890ABCDEF_u64;
4482    println!("K =\t{:#016X}", key);
4483    let mut a_des = DES::new_with_key_u64(key);
4484
4485    let message = "7 bytes";
4486    println!("M =\t{}", message);
4487    let mut cipher = Vec::<u8>::new();
4488    a_des.encrypt_str_into_vec(&message, &mut cipher);
4489    print!("C =\t");
4490    for c in cipher.clone()
4491        { print!("{:02X} ", c); }
4492    println!();
4493    let mut txt = String::new();
4494    for c in cipher.clone()
4495        { write!(txt, "{:02X} ", c); }
4496    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4497    
4498    let mut recovered = Vec::<u8>::new();
4499    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4500    print!("Ba =\t");
4501    for b in recovered.clone()
4502        { print!("{:02X} ", b); }
4503    println!();
4504    let mut txt = String::new();
4505    for c in recovered.clone()
4506        { write!(txt, "{:02X} ", c); }
4507    assert_eq!(txt, "37 20 62 79 74 65 73 ");
4508
4509    let mut converted = String::new();
4510    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4511    
4512    println!("Bb =\t{}", converted);
4513    assert_eq!(converted, "7 bytes");
4514    assert_eq!(converted, message);
4515    println!();
4516
4517    // Normal case for the message of 8 bytes
4518    let key = 0x_1234567890ABCDEF_u64;
4519    println!("K =\t{:#016X}", key);
4520    let mut a_des = DES::new_with_key_u64(key);
4521
4522    let message = "I am OK.";
4523    println!("M =\t{}", message);
4524    let mut cipher = Vec::<u8>::new();
4525    a_des.encrypt_str_into_vec(&message, &mut cipher);
4526    print!("C =\t");
4527    for c in cipher.clone()
4528        { print!("{:02X} ", c); }
4529    println!();
4530    let mut txt = String::new();
4531    for c in cipher.clone()
4532        { write!(txt, "{:02X} ", c); }
4533    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4534    
4535    let mut recovered = Vec::<u8>::new();
4536    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4537    print!("Ba =\t");
4538    for b in recovered.clone()
4539        { print!("{:02X} ", b); }
4540    println!();
4541    let mut txt = String::new();
4542    for c in recovered.clone()
4543        { write!(txt, "{:02X} ", c); }
4544    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4545
4546    let mut converted = String::new();
4547    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4548    
4549    println!("Bb =\t{}", converted);
4550    assert_eq!(converted, "I am OK.");
4551    assert_eq!(converted, message);
4552    println!();
4553
4554    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4555    let key = 0x_1234567890ABCDEF_u64;
4556    println!("K =\t{:#016X}", key);
4557    let mut a_des = DES::new_with_key_u64(key);
4558
4559    let message = "PARK Youngho";
4560    println!("M =\t{}", message);
4561    let mut cipher = Vec::<u8>::new();
4562    a_des.encrypt_str_into_vec(&message, &mut cipher);
4563    print!("C =\t");
4564    for c in cipher.clone()
4565        { print!("{:02X} ", c); }
4566    println!();
4567    let mut txt = String::new();
4568    for c in cipher.clone()
4569        { write!(txt, "{:02X} ", c); }
4570    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4571
4572    let mut recovered = Vec::<u8>::new();
4573    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4574    print!("Ba =\t");
4575    for b in recovered.clone()
4576        { print!("{:02X} ", b); }
4577    println!();
4578    let mut txt = String::new();
4579    for c in recovered.clone()
4580        { write!(txt, "{:02X} ", c); }
4581    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4582
4583    let mut converted = String::new();
4584    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4585    
4586    println!("Bb =\t{}", converted);
4587    assert_eq!(converted, "PARK Youngho");
4588    assert_eq!(converted, message);
4589    println!();
4590
4591    // Normal case for the message of 16 bytes
4592    let key = 0x_1234567890ABCDEF_u64;
4593    println!("K =\t{:#016X}", key);
4594    let mut a_des = DES::new_with_key_u64(key);
4595
4596    let message = "고맙습니다.";
4597    println!("M =\t{}", message);
4598    let mut cipher = Vec::<u8>::new();
4599    a_des.encrypt_str_into_vec(&message, &mut cipher);
4600    print!("C =\t");
4601    for c in cipher.clone()
4602        { print!("{:02X} ", c); }
4603    println!();
4604    let mut txt = String::new();
4605    for c in cipher.clone()
4606        { write!(txt, "{:02X} ", c); }
4607    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4608
4609    let mut recovered = Vec::<u8>::new();
4610    a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4611    print!("Ba =\t");
4612    for b in recovered.clone()
4613        { print!("{:02X} ", b); }
4614    println!();
4615    let mut txt = String::new();
4616    for c in recovered.clone()
4617        { write!(txt, "{:02X} ", c); }
4618    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4619
4620    let mut converted = String::new();
4621    unsafe { converted.as_mut_vec() }.append(&mut recovered);
4622    
4623    println!("Bb =\t{}", converted);
4624    assert_eq!(converted, "고맙습니다.");
4625    assert_eq!(converted, message);
4626    println!("-------------------------------");
4627}
Source

fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Decrypts the data stored in a Vec<U> object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in array [V; N].

§Arguments
  • cipher is an immutable reference to Vec<U> object, and is the place where the ciphertext to be decrypted is stored.
  • message is a mutable reference to an array [U; N] object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * cipher.len() is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • If size_of::<V>() * N is less than size_of::<U>() * cipher.len() - 1, this method does not perform decryption but returns zero.
  • If size_of::<V>() * N is equal to or greater than size_of::<U>() * cipher.len() - 1, this method performs decryption, fills the array message with the decrypted data, and then fills the rest of the elements of the array message with zeros, and returns the size of the plaintext.
  • It is responsible for you to prepare the message area big enough!
  • The size of the area for plaintext does not have to be prepared more than size_of::<U>() * cipher.len() - 1.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = [0; 64];
let len = a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = [0u8; 56];
let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = [0u8; 64];
let len = taes.decrypt_vec_into_array(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = [0u8; 56];
let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 724)
699fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()
700{
701    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()");
702    use std::io::Write;
703    use std::fmt::Write as _;
704    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
705
706    // TDES case
707    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710    let message = "In the beginning God created the heavens and the earth.";
711    println!("M =\t{}", message);
712    let mut cipher = Vec::<u8>::new();
713    tdes.encrypt_str_into_vec(&message, &mut cipher);
714    print!("C =\t");
715    for c in cipher.clone()
716        { print!("{:02X} ", c); }
717    println!();
718    let mut txt = String::new();
719    for c in cipher.clone()
720        { write!(txt, "{:02X} ", c); }
721    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723    let mut recovered = [0u8; 56];
724    let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725    print!("Ba =\t");
726    for b in recovered.clone()
727        { print!("{:02X} ", b); }
728    println!();
729    let mut txt = String::new();
730    for c in recovered.clone()
731        { write!(txt, "{:02X} ", c); }
732    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734    let mut converted = String::new();
735    unsafe { converted.as_mut_vec() }.write(&recovered);
736    unsafe { converted.as_mut_vec() }.truncate(len as usize);
737    println!("Bb =\t{}", converted);
738    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739    assert_eq!(converted, message);
740    println!("-------------------------------");
741}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 768)
741fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_array()
742{
743    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_array()");
744    use std::io::Write;
745    use std::fmt::Write as _;
746    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
747
748    // TAES_128 case
749    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
750                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
751                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
752    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
753    println!("IV =	{:#034X}", iv);
754    let message = "In the beginning God created the heavens and the earth.";
755    println!("M =\t{}", message);
756    let mut cipher = Vec::<u8>::new();
757    taes.encrypt_str_into_vec(&message, &mut cipher);
758    print!("C =\t");
759    for c in cipher.clone()
760        { print!("{:02X} ", c); }
761    println!();
762    let mut txt = String::new();
763    for c in cipher.clone()
764        { write!(txt, "{:02X} ", c); }
765    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
766
767    let mut recovered = [0u8; 64];
768    let len = taes.decrypt_vec_into_array(&cipher, &mut recovered);
769    print!("Ba =\t");
770    for b in recovered.clone()
771        { print!("{:02X} ", b); }
772    println!();
773    let mut txt = String::new();
774    for c in recovered.clone()
775        { write!(txt, "{:02X} ", c); }
776    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
777
778    let mut converted = String::new();
779    unsafe { converted.as_mut_vec() }.write(&recovered);
780    unsafe { converted.as_mut_vec() }.truncate(len as usize);
781    println!("Bb =\t{}", converted);
782    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783    assert_eq!(converted, message);
784    println!("-------------------------------");
785}
examples/aes_ecb_iso_examples.rs (line 3091)
3065fn aes_decrypt_vec_with_padding_iso_ecb_into_array()
3066{
3067    println!("aes_decrypt_vec_with_padding_iso_ecb_into_array()");
3068    use std::io::Write;
3069    use std::fmt::Write as _;
3070    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3071
3072    // Normal case for AES-128
3073    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3074    println!("K =\t{:#016X}", key);
3075    let mut a_aes = AES_128::new_with_key_u128(key);
3076
3077    let message = "In the beginning God created the heavens and the earth.";
3078    println!("M =\t{}", message);
3079    let mut cipher = Vec::<u8>::new();
3080    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3081    print!("C =\t");
3082    for c in cipher.clone()
3083        { print!("{:02X} ", c); }
3084    println!();
3085    let mut txt = String::new();
3086    for c in cipher.clone()
3087        { write!(txt, "{:02X} ", c); }
3088    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3089
3090    let mut recovered = [0; 64];
3091    let len = a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3092    print!("Ba =\t");
3093    for b in recovered.clone()
3094        { print!("{:02X} ", b); }
3095    println!();
3096    let mut txt = String::new();
3097    for c in recovered.clone()
3098        { write!(txt, "{:02X} ", c); }
3099    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3100
3101    let mut converted = String::new();
3102    unsafe { converted.as_mut_vec() }.write(&recovered);
3103    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3104    println!("Bb =\t{}", converted);
3105    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3106    assert_eq!(converted, message);
3107    println!();
3108
3109    // Normal case for AES-192
3110    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3111    print!("K =\t");
3112    for i in 0..24
3113        { print!("{:02X}", key[i]); }
3114    println!();
3115    let mut a_aes = AES_192::new_with_key(&key);
3116
3117    let message = "In the beginning God created the heavens and the earth.";
3118    println!("M =\t{}", message);
3119    let mut cipher = Vec::<u8>::new();
3120    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3121    print!("C =\t");
3122    for c in cipher.clone()
3123        { print!("{:02X} ", c); }
3124    println!();
3125    let mut txt = String::new();
3126    for c in cipher.clone()
3127        { write!(txt, "{:02X} ", c); }
3128    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3129
3130    let mut recovered = [0; 64];
3131    a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3132    print!("Ba =\t");
3133    for b in recovered.clone()
3134        { print!("{:02X} ", b); }
3135    println!();
3136    let mut txt = String::new();
3137    for c in recovered.clone()
3138        { write!(txt, "{:02X} ", c); }
3139    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3140
3141    let mut converted = String::new();
3142    unsafe { converted.as_mut_vec() }.write(&recovered);
3143    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3144    println!("Bb =\t{}", converted);
3145    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3146    assert_eq!(converted, message);
3147    println!();
3148
3149    // Normal case for AES-256
3150    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3151    print!("K =\t");
3152    for i in 0..32
3153        { print!("{:02X}", key[i]); }
3154    println!();
3155    let mut a_aes = AES_256::new_with_key(&key);
3156
3157    let message = "In the beginning God created the heavens and the earth.";
3158    println!("M =\t{}", message);
3159    let mut cipher = Vec::<u8>::new();
3160    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3161    print!("C =\t");
3162    for c in cipher.clone()
3163        { print!("{:02X} ", c); }
3164    println!();
3165    let mut txt = String::new();
3166    for c in cipher.clone()
3167        { write!(txt, "{:02X} ", c); }
3168    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3169
3170    let mut recovered = [0; 64];
3171    a_aes.decrypt_vec_into_array(&cipher, &mut recovered);
3172    print!("Ba =\t");
3173    for b in recovered.clone()
3174        { print!("{:02X} ", b); }
3175    println!();
3176    let mut txt = String::new();
3177    for c in recovered.clone()
3178        { write!(txt, "{:02X} ", c); }
3179    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3180
3181    let mut converted = String::new();
3182    unsafe { converted.as_mut_vec() }.write(&recovered);
3183    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3184    println!("Bb =\t{}", converted);
3185    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3186    assert_eq!(converted, message);
3187    println!();
3188
3189    // Normal case for Rijndael-256-256
3190    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3191    print!("K =\t");
3192    for i in 0..32
3193        { print!("{:02X}", key[i]); }
3194    println!();
3195    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3196
3197    let message = "In the beginning God created the heavens and the earth.";
3198    println!("M =\t{}", message);
3199    let mut cipher = Vec::<u8>::new();
3200    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3201    print!("C =\t");
3202    for c in cipher.clone()
3203        { print!("{:02X} ", c); }
3204    println!();
3205    let mut txt = String::new();
3206    for c in cipher.clone()
3207        { write!(txt, "{:02X} ", c); }
3208    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3209
3210    let mut recovered = [0; 64];
3211    a_rijndael.decrypt_vec_into_array(&cipher, &mut recovered);
3212    print!("Ba =\t");
3213    for b in recovered.clone()
3214        { print!("{:02X} ", b); }
3215    println!();
3216    let mut txt = String::new();
3217    for c in recovered.clone()
3218        { write!(txt, "{:02X} ", c); }
3219    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3220
3221    let mut converted = String::new();
3222    unsafe { converted.as_mut_vec() }.write(&recovered);
3223    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3224    println!("Bb =\t{}", converted);
3225    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3226    assert_eq!(converted, message);
3227    println!();
3228
3229    // Normal case for Rijndael-512-512 for post-quantum
3230    use cryptocol::number::SharedArrays;
3231    use cryptocol::hash::SHA3_512;
3232    let mut sha3 = SHA3_512::new();
3233    sha3.absorb_str("Post-quantum");
3234    let key: [u8; 64] = sha3.get_hash_value_in_array();
3235    print!("K =\t");
3236    for i in 0..64
3237        { print!("{:02X}", key[i]); }
3238    println!();
3239    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3240
3241    let message = "In the beginning God created the heavens and the earth.";
3242    println!("M =\t{}", message);
3243    let mut cipher = Vec::<u8>::new();
3244    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3245    print!("C =\t");
3246    for c in cipher.clone()
3247        { print!("{:02X} ", c); }
3248    println!();
3249    let mut txt = String::new();
3250    for c in cipher.clone()
3251        { write!(txt, "{:02X} ", c); }
3252    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3253    
3254    let mut recovered = [0; 64];
3255    a_rijndael.decrypt_vec_into_array(&cipher, &mut recovered);
3256    print!("Ba =\t");
3257    for b in recovered.clone()
3258        { print!("{:02X} ", b); }
3259    println!();
3260    let mut txt = String::new();
3261    for c in recovered.clone()
3262        { write!(txt, "{:02X} ", c); }
3263    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3264
3265    let mut converted = String::new();
3266    unsafe { converted.as_mut_vec() }.write(&recovered);
3267    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3268    println!("Bb =\t{}", converted);
3269    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3270    assert_eq!(converted, message);
3271    println!("-------------------------------");
3272}
examples/des_ecb_iso_examples.rs (line 4655)
4629fn des_decrypt_vec_with_padding_iso_ecb_into_array()
4630{
4631    println!("des_decrypt_vec_with_padding_iso_ecb_into_array()");
4632    use std::io::Write;
4633    use std::fmt::Write as _;
4634    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4635
4636    // Normal case
4637    let key = 0x_1234567890ABCDEF_u64;
4638    println!("K =\t{:#016X}", key);
4639    let mut a_des = DES::new_with_key_u64(key);
4640
4641    let message = "In the beginning God created the heavens and the earth.";
4642    println!("M =\t{}", message);
4643    let mut cipher = Vec::<u8>::new();
4644    a_des.encrypt_str_into_vec(&message, &mut cipher);
4645    print!("C (16 rounds) =\t");
4646    for c in cipher.clone()
4647        { print!("{:02X} ", c); }
4648    println!();
4649    let mut txt = String::new();
4650    for c in cipher.clone()
4651        { write!(txt, "{:02X} ", c); }
4652    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4653
4654    let mut recovered = [0u8; 56];
4655    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4656    print!("Ba (16 rounds) =\t");
4657    for b in recovered.clone()
4658        { print!("{:02X} ", b); }
4659    println!();
4660    let mut txt = String::new();
4661    for c in recovered.clone()
4662        { write!(txt, "{:02X} ", c); }
4663    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4664
4665    let mut converted = String::new();
4666    unsafe { converted.as_mut_vec() }.write(&recovered);
4667    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4668    println!("Bb (16 rounds) =\t{}", converted);
4669    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4670    assert_eq!(converted, message);
4671    println!();
4672
4673    // Expanded case for 128 rounds
4674    let key = 0x_1234567890ABCDEF_u64;
4675    println!("K =\t{:#016X}", key);
4676    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4677
4678    let message = "In the beginning God created the heavens and the earth.";
4679    println!("M =\t{}", message);
4680    let mut cipher = Vec::<u8>::new();
4681    a_des.encrypt_str_into_vec(&message, &mut cipher);
4682    print!("C (128 rounds) =\t");
4683    for c in cipher.clone()
4684        { print!("{:02X} ", c); }
4685    println!();
4686    let mut txt = String::new();
4687    for c in cipher.clone()
4688        { write!(txt, "{:02X} ", c); }
4689    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4690
4691    let mut recovered = [0u8; 56];
4692    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4693    print!("Ba (16 rounds) =\t");
4694    for b in recovered.clone()
4695        { print!("{:02X} ", b); }
4696    println!();
4697    let mut txt = String::new();
4698    for c in recovered.clone()
4699        { write!(txt, "{:02X} ", c); }
4700    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4701
4702    let mut converted = String::new();
4703    unsafe { converted.as_mut_vec() }.write(&recovered);
4704    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4705    println!("Bb (16 rounds) =\t{}", converted);
4706    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4707    assert_eq!(converted, message);
4708    println!();
4709
4710    // Expanded case for 0 rounds which means that key is meaningless
4711    let key1 = 0x_1234567890ABCDEF_u64;
4712    let key2 = 0_u64;
4713    println!("K =\t{:#016X}", key);
4714    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4715    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4716
4717    let message = "In the beginning God created the heavens and the earth.";
4718    println!("M =\t{}", message);
4719    let mut cipher1 = Vec::<u8>::new();
4720    let mut cipher2 = Vec::<u8>::new();
4721    c_des.encrypt_str_into_vec(&message, &mut cipher1);
4722    d_des.encrypt_str_into_vec(&message, &mut cipher2);
4723    print!("C (0 rounds) =\t");
4724    for c in cipher1.clone()
4725        { print!("{:02X} ", c); }
4726    println!();
4727    let mut txt = String::new();
4728    for c in cipher1.clone()
4729        { write!(txt, "{:02X} ", c); }
4730    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4731    print!("D (0 rounds) =\t");
4732    for c in cipher2.clone()
4733        { print!("{:02X} ", c); }
4734    println!();
4735    let mut txt = String::new();
4736    for c in cipher2.clone()
4737        { write!(txt, "{:02X} ", c); }
4738    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4739
4740    let mut recovered1 = [0u8; 56];
4741    let mut recovered2 = [0u8; 56];
4742    let len1 = c_des.decrypt_vec_into_array(&cipher1, &mut recovered1);
4743    let len2 = d_des.decrypt_vec_into_array(&cipher2, &mut recovered2);
4744    print!("B1a (0 rounds) =\t");
4745    for b in recovered1.clone()
4746        { print!("{:02X} ", b); }
4747    println!();
4748    let mut txt = String::new();
4749    for c in recovered1.clone()
4750        { write!(txt, "{:02X} ", c); }
4751    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4752    print!("B2a (0 rounds) =\t");
4753    for b in recovered2.clone()
4754        { print!("{:02X} ", b); }
4755    println!();
4756    let mut txt = String::new();
4757    for c in recovered.clone()
4758        { write!(txt, "{:02X} ", c); }
4759    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4760
4761    let mut converted1 = String::new();
4762    let mut converted2 = String::new();
4763    unsafe { converted1.as_mut_vec() }.write(&recovered1);
4764    unsafe { converted2.as_mut_vec() }.write(&recovered2);
4765    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
4766    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
4767    println!("B1b (0 rounds) =\t{}", converted1);
4768    println!("B2b (0 rounds) =\t{}", converted2);
4769    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4770    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4771    assert_eq!(converted1, message);
4772    assert_eq!(converted2, message);
4773    assert_eq!(converted1, converted2);
4774    println!();
4775
4776    // Normal case for the message of 0 bytes
4777    let key = 0x_1234567890ABCDEF_u64;
4778    println!("K =\t{:#016X}", key);
4779    let mut a_des = DES::new_with_key_u64(key);
4780
4781    let message = "";
4782    println!("M =\t{}", message);
4783    let mut cipher = Vec::<u8>::new();
4784    a_des.encrypt_str_into_vec(&message, &mut cipher);
4785    print!("C =\t");
4786    for c in cipher.clone()
4787        { print!("{:02X} ", c); }
4788    println!();
4789    let mut txt = String::new();
4790    for c in cipher.clone()
4791        { write!(txt, "{:02X} ", c); }
4792    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4793
4794    let mut recovered = [0u8; 8];
4795    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4796
4797    print!("Ba =\t");
4798    for b in recovered.clone()
4799        { print!("{:02X} ", b); }
4800    println!();
4801    let mut txt = String::new();
4802    for c in recovered.clone()
4803        { write!(txt, "{:02X} ", c); }
4804    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4805
4806    let mut converted = String::new();
4807    unsafe { converted.as_mut_vec() }.write(&recovered);
4808    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4809    println!("Bb =\t{}", converted);
4810    assert_eq!(converted, "");
4811    assert_eq!(converted, message);
4812    println!();
4813
4814    // Normal case for the message shorter than 8 bytes
4815    let key = 0x_1234567890ABCDEF_u64;
4816    println!("K =\t{:#016X}", key);
4817    let mut a_des = DES::new_with_key_u64(key);
4818
4819    let message = "7 bytes";
4820    println!("M =\t{}", message);
4821    let mut cipher = Vec::<u8>::new();
4822    a_des.encrypt_str_into_vec(&message, &mut cipher);
4823    print!("C =\t");
4824    for c in cipher.clone()
4825        { print!("{:02X} ", c); }
4826    println!();
4827    let mut txt = String::new();
4828    for c in cipher.clone()
4829        { write!(txt, "{:02X} ", c); }
4830    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4831
4832    let mut recovered = [0u8; 8];
4833    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4834
4835    print!("Ba =\t");
4836    for b in recovered.clone()
4837        { print!("{:02X} ", b); }
4838    println!();
4839    let mut txt = String::new();
4840    for c in recovered.clone()
4841        { write!(txt, "{:02X} ", c); }
4842    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4843
4844    let mut converted = String::new();
4845    unsafe { converted.as_mut_vec() }.write(&recovered);
4846    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4847    println!("Bb =\t{}", converted);
4848    assert_eq!(converted, "7 bytes");
4849    assert_eq!(converted, message);
4850    println!();
4851
4852    // Normal case for the message of 8 bytes
4853    let key = 0x_1234567890ABCDEF_u64;
4854    println!("K =\t{:#016X}", key);
4855    let mut a_des = DES::new_with_key_u64(key);
4856
4857    let message = "I am OK.";
4858    println!("M =\t{}", message);
4859    let mut cipher = Vec::<u8>::new();
4860    a_des.encrypt_str_into_vec(&message, &mut cipher);
4861    print!("C =\t");
4862    for c in cipher.clone()
4863        { print!("{:02X} ", c); }
4864    println!();
4865    let mut txt = String::new();
4866    for c in cipher.clone()
4867        { write!(txt, "{:02X} ", c); }
4868    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4869
4870    let mut recovered = [0u8; 16];
4871    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4872
4873    print!("Ba =\t");
4874    for b in recovered.clone()
4875        { print!("{:02X} ", b); }
4876    println!();
4877    let mut txt = String::new();
4878    for c in recovered.clone()
4879        { write!(txt, "{:02X} ", c); }
4880    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4881
4882    let mut converted = String::new();
4883    unsafe { converted.as_mut_vec() }.write(&recovered);
4884    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4885    println!("Bb =\t{}", converted);
4886    assert_eq!(converted, "I am OK.");
4887    assert_eq!(converted, message);
4888    println!();
4889
4890    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4891    let key = 0x_1234567890ABCDEF_u64;
4892    println!("K =\t{:#016X}", key);
4893    let mut a_des = DES::new_with_key_u64(key);
4894
4895    let message = "PARK Youngho";
4896    println!("M =\t{}", message);
4897    let mut cipher = Vec::<u8>::new();
4898    a_des.encrypt_str_into_vec(&message, &mut cipher);
4899    print!("C =\t");
4900    for c in cipher.clone()
4901        { print!("{:02X} ", c); }
4902    println!();
4903    let mut txt = String::new();
4904    for c in cipher.clone()
4905        { write!(txt, "{:02X} ", c); }
4906    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4907
4908    let mut recovered = [0u8; 16];
4909    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4910
4911    print!("Ba =\t");
4912    for b in recovered.clone()
4913        { print!("{:02X} ", b); }
4914    println!();
4915    let mut txt = String::new();
4916    for c in recovered.clone()
4917        { write!(txt, "{:02X} ", c); }
4918    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4919
4920    let mut converted = String::new();
4921    unsafe { converted.as_mut_vec() }.write(&recovered);
4922    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4923    println!("Bb =\t{}", converted);
4924    assert_eq!(converted, "PARK Youngho");
4925    assert_eq!(converted, message);
4926    println!();
4927
4928    // Normal case for the message of 16 bytes
4929    let key = 0x_1234567890ABCDEF_u64;
4930    println!("K =\t{:#016X}", key);
4931    let mut a_des = DES::new_with_key_u64(key);
4932
4933    let message = "고맙습니다.";
4934    println!("M =\t{}", message);
4935    let mut cipher = Vec::<u8>::new();
4936    a_des.encrypt_str_into_vec(&message, &mut cipher);
4937    print!("C =\t");
4938    for c in cipher.clone()
4939        { print!("{:02X} ", c); }
4940    println!();
4941    let mut txt = String::new();
4942    for c in cipher.clone()
4943        { write!(txt, "{:02X} ", c); }
4944    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4945
4946    let mut recovered = [0u8; 24];
4947    let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4948
4949    print!("Ba =\t");
4950    for b in recovered.clone()
4951        { print!("{:02X} ", b); }
4952    println!();
4953    let mut txt = String::new();
4954    for c in recovered.clone()
4955        { write!(txt, "{:02X} ", c); }
4956    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4957
4958    let mut converted = String::new();
4959    unsafe { converted.as_mut_vec() }.write(&recovered);
4960    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4961    println!("Bb =\t{}", converted);
4962    assert_eq!(converted, "고맙습니다.");
4963    assert_eq!(converted, message);
4964    println!("-------------------------------");
4965}
Source

fn decrypt_vec_into_string<U>( &mut self, cipher: &Vec<U>, message: &mut String, ) -> u64
where U: SmallUInt + Copy + Clone,

Decrypts the data in str with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in String.

§Arguments
  • cipher is an immutable reference to Vec<U> object, and is the place where the ciphertext to be decrypted is stored.
  • message is a mutable reference to a String object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * cipher.len() is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
  • This method assumes that the original plaintext is a string in the format of UTF-8.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_aes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut converted= String::new();
a_aes.decrypt_vec_into_string(&cipher, &mut converted);
println!("B =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = String::new();
a_des.decrypt_vec_into_string(&cipher, &mut recovered);
println!("B (16 rounds) =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
taes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = String::new();
taes.decrypt_vec_into_string(&cipher, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = Vec::<u8>::new();
tdes.encrypt_str_into_vec(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = String::new();
tdes.decrypt_vec_into_string(&cipher, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 768)
743fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()
744{
745    println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()");
746    use std::io::Write;
747    use std::fmt::Write as _;
748    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
749
750    // TDES case
751    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754    let message = "In the beginning God created the heavens and the earth.";
755    println!("M =\t{}", message);
756    let mut cipher = Vec::<u8>::new();
757    tdes.encrypt_str_into_vec(&message, &mut cipher);
758    print!("C =\t");
759    for c in cipher.clone()
760        { print!("{:02X} ", c); }
761    println!();
762    let mut txt = String::new();
763    for c in cipher.clone()
764        { write!(txt, "{:02X} ", c); }
765    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767    let mut recovered = String::new();
768    tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769    println!("B =\t{}", recovered);
770    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771    assert_eq!(recovered, message);
772    println!("-------------------------------");
773}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 814)
787fn bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_string()
788{
789    println!("bigcryptor128_decrypt_vec_with_padding_iso_ecb_into_string()");
790    use std::io::Write;
791    use std::fmt::Write as _;
792    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
793
794    // TAES_128 case
795    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
796                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
797                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
798    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
799    println!("IV =	{:#034X}", iv);
800    let message = "In the beginning God created the heavens and the earth.";
801    println!("M =\t{}", message);
802    let mut cipher = Vec::<u8>::new();
803    taes.encrypt_str_into_vec(&message, &mut cipher);
804    print!("C =\t");
805    for c in cipher.clone()
806        { print!("{:02X} ", c); }
807    println!();
808    let mut txt = String::new();
809    for c in cipher.clone()
810        { write!(txt, "{:02X} ", c); }
811    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
812
813    let mut recovered = String::new();
814    taes.decrypt_vec_into_string(&cipher, &mut recovered);
815    println!("B =\t{}", recovered);
816    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817    assert_eq!(recovered, message);
818    println!("-------------------------------");
819}
examples/aes_ecb_iso_examples.rs (line 3300)
3274fn aes_decrypt_vec_with_padding_iso_ecb_into_string()
3275{
3276    println!("aes_decrypt_vec_with_padding_iso_ecb_into_string()");
3277    use std::io::Write;
3278    use std::fmt::Write as _;
3279    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3280
3281    // Normal case for AES-128
3282    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3283    println!("K =\t{:#016X}", key);
3284    let mut a_aes = AES_128::new_with_key_u128(key);
3285
3286    let message = "In the beginning God created the heavens and the earth.";
3287    println!("M =\t{}", message);
3288    let mut cipher = Vec::<u8>::new();
3289    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3290    print!("C =\t");
3291    for c in cipher.clone()
3292        { print!("{:02X} ", c); }
3293    println!();
3294    let mut txt = String::new();
3295    for c in cipher.clone()
3296        { write!(txt, "{:02X} ", c); }
3297    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3298
3299    let mut converted= String::new();
3300    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3301    println!("B =\t{}", converted);
3302    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3303    assert_eq!(converted, message);
3304    println!();
3305
3306    // Normal case for AES-192
3307    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3308    print!("K =\t");
3309    for i in 0..24
3310        { print!("{:02X}", key[i]); }
3311    println!();
3312    let mut a_aes = AES_192::new_with_key(&key);
3313
3314    let message = "In the beginning God created the heavens and the earth.";
3315    println!("M =\t{}", message);
3316    let mut cipher = Vec::<u8>::new();
3317    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3318    print!("C =\t");
3319    for c in cipher.clone()
3320        { print!("{:02X} ", c); }
3321    println!();
3322    let mut txt = String::new();
3323    for c in cipher.clone()
3324        { write!(txt, "{:02X} ", c); }
3325    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3326
3327    let mut converted= String::new();
3328    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3329    println!("B =\t{}", converted);
3330    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3331    assert_eq!(converted, message);
3332    println!();
3333
3334    // Normal case for AES-256
3335    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3336    print!("K =\t");
3337    for i in 0..32
3338        { print!("{:02X}", key[i]); }
3339    println!();
3340    let mut a_aes = AES_256::new_with_key(&key);
3341
3342    let message = "In the beginning God created the heavens and the earth.";
3343    println!("M =\t{}", message);
3344    let mut cipher = Vec::<u8>::new();
3345    a_aes.encrypt_str_into_vec(&message, &mut cipher);
3346    print!("C =\t");
3347    for c in cipher.clone()
3348        { print!("{:02X} ", c); }
3349    println!();
3350    let mut txt = String::new();
3351    for c in cipher.clone()
3352        { write!(txt, "{:02X} ", c); }
3353    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3354
3355    let mut converted= String::new();
3356    a_aes.decrypt_vec_into_string(&cipher, &mut converted);
3357    println!("B =\t{}", converted);
3358    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3359    assert_eq!(converted, message);
3360    println!();
3361
3362    // Normal case for Rijndael-256-256
3363    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3364    print!("K =\t");
3365    for i in 0..32
3366        { print!("{:02X}", key[i]); }
3367    println!();
3368    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3369
3370    let message = "In the beginning God created the heavens and the earth.";
3371    println!("M =\t{}", message);
3372    let mut cipher = Vec::<u8>::new();
3373    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3374    print!("C =\t");
3375    for c in cipher.clone()
3376        { print!("{:02X} ", c); }
3377    println!();
3378    let mut txt = String::new();
3379    for c in cipher.clone()
3380        { write!(txt, "{:02X} ", c); }
3381    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3382
3383    let mut converted= String::new();
3384    a_rijndael.decrypt_vec_into_string(&cipher, &mut converted);
3385    println!("B =\t{}", converted);
3386    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3387    assert_eq!(converted, message);
3388    println!();
3389
3390    // Normal case for Rijndael-512-512 for post-quantum
3391    use cryptocol::number::SharedArrays;
3392    use cryptocol::hash::SHA3_512;
3393    let mut sha3 = SHA3_512::new();
3394    sha3.absorb_str("Post-quantum");
3395    let key: [u8; 64] = sha3.get_hash_value_in_array();
3396    print!("K =\t");
3397    for i in 0..64
3398        { print!("{:02X}", key[i]); }
3399    println!();
3400    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3401
3402    let message = "In the beginning God created the heavens and the earth.";
3403    println!("M =\t{}", message);
3404    let mut cipher = Vec::<u8>::new();
3405    a_rijndael.encrypt_str_into_vec(&message, &mut cipher);
3406    print!("C =\t");
3407    for c in cipher.clone()
3408        { print!("{:02X} ", c); }
3409    println!();
3410    let mut txt = String::new();
3411    for c in cipher.clone()
3412        { write!(txt, "{:02X} ", c); }
3413    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3414    
3415    let mut converted= String::new();
3416    a_rijndael.decrypt_vec_into_string(&cipher, &mut converted);
3417    println!("B =\t{}", converted);
3418    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3419    assert_eq!(converted, message);
3420    println!("-------------------------------");
3421}
examples/des_ecb_iso_examples.rs (line 4993)
4967fn des_decrypt_vec_with_padding_iso_ecb_into_string()
4968{
4969    println!("des_decrypt_vec_with_padding_iso_ecb_into_string()");
4970    use std::io::Write;
4971    use std::fmt::Write as _;
4972    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4973
4974    // Normal case
4975    let key = 0x_1234567890ABCDEF_u64;
4976    println!("K =\t{:#016X}", key);
4977    let mut a_des = DES::new_with_key_u64(key);
4978
4979    let message = "In the beginning God created the heavens and the earth.";
4980    println!("M =\t{}", message);
4981    let mut cipher = Vec::<u8>::new();
4982    a_des.encrypt_str_into_vec(&message, &mut cipher);
4983    print!("C (16 rounds) =\t");
4984    for c in cipher.clone()
4985        { print!("{:02X} ", c); }
4986    println!();
4987    let mut txt = String::new();
4988    for c in cipher.clone()
4989        { write!(txt, "{:02X} ", c); }
4990    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4991
4992    let mut recovered = String::new();
4993    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
4994    println!("B (16 rounds) =\t{}", recovered);
4995    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4996    assert_eq!(recovered, message);
4997    println!();
4998
4999    // Expanded case for 128 rounds
5000    let key = 0x_1234567890ABCDEF_u64;
5001    println!("K =\t{:#016X}", key);
5002    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5003
5004    let message = "In the beginning God created the heavens and the earth.";
5005    println!("M =\t{}", message);
5006    let mut cipher = Vec::<u8>::new();
5007    a_des.encrypt_str_into_vec(&message, &mut cipher);
5008    print!("C (128 rounds) =\t");
5009    for c in cipher.clone()
5010        { print!("{:02X} ", c); }
5011    println!();
5012    let mut txt = String::new();
5013    for c in cipher.clone()
5014        { write!(txt, "{:02X} ", c); }
5015    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5016
5017    let mut recovered = String::new();
5018    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5019    println!("B (128 rounds) =\t{}", recovered);
5020    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5021    assert_eq!(recovered, message);
5022    println!();
5023
5024    // Expanded case for 0 rounds which means that key is meaningless
5025    let key1 = 0x_1234567890ABCDEF_u64;
5026    let key2 = 0_u64;
5027    println!("K =\t{:#016X}", key);
5028    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5029    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5030
5031    let message = "In the beginning God created the heavens and the earth.";
5032    println!("M =\t{}", message);
5033    let mut cipher1 = Vec::<u8>::new();
5034    let mut cipher2 = Vec::<u8>::new();
5035    c_des.encrypt_str_into_vec(&message, &mut cipher1);
5036    d_des.encrypt_str_into_vec(&message, &mut cipher2);
5037    print!("C (0 rounds) =\t");
5038    for c in cipher1.clone()
5039        { print!("{:02X} ", c); }
5040    println!();
5041    let mut txt = String::new();
5042    for c in cipher1.clone()
5043        { write!(txt, "{:02X} ", c); }
5044    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5045    print!("D (0 rounds) =\t");
5046    for c in cipher2.clone()
5047        { print!("{:02X} ", c); }
5048    println!();
5049    let mut txt = String::new();
5050    for c in cipher2.clone()
5051        { write!(txt, "{:02X} ", c); }
5052    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5053
5054    let mut recovered1 = String::new();
5055    let mut recovered2 = String::new();
5056    c_des.decrypt_vec_into_string(&cipher1, &mut recovered1);
5057    d_des.decrypt_vec_into_string(&cipher2, &mut recovered2);
5058    println!("B1 (0 rounds) =\t{}", recovered1);
5059    println!("B2 (0 rounds) =\t{}", recovered2);
5060    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5061    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5062    assert_eq!(recovered1, message);
5063    assert_eq!(recovered2, message);
5064    assert_eq!(recovered1, recovered2);
5065    println!();
5066
5067    // Normal case for the message of 0 bytes
5068    let key = 0x_1234567890ABCDEF_u64;
5069    println!("K =\t{:#016X}", key);
5070    let mut a_des = DES::new_with_key_u64(key);
5071
5072    let message = "";
5073    println!("M =\t{}", message);
5074    let mut cipher = Vec::<u8>::new();
5075    a_des.encrypt_str_into_vec(&message, &mut cipher);
5076    print!("C =\t");
5077    for c in cipher.clone()
5078        { print!("{:02X} ", c); }
5079    println!();
5080    let mut txt = String::new();
5081    for c in cipher.clone()
5082        { write!(txt, "{:02X} ", c); }
5083    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5084
5085    let mut recovered = String::new();
5086    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5087    println!("B =\t{}", recovered);
5088    assert_eq!(recovered, "");
5089    assert_eq!(recovered, message);
5090    println!();
5091
5092    // Normal case for the message shorter than 8 bytes
5093    let key = 0x_1234567890ABCDEF_u64;
5094    println!("K =\t{:#016X}", key);
5095    let mut a_des = DES::new_with_key_u64(key);
5096
5097    let message = "7 bytes";
5098    println!("M =\t{}", message);
5099    let mut cipher = Vec::<u8>::new();
5100    a_des.encrypt_str_into_vec(&message, &mut cipher);
5101    print!("C =\t");
5102    for c in cipher.clone()
5103        { print!("{:02X} ", c); }
5104    println!();
5105    let mut txt = String::new();
5106    for c in cipher.clone()
5107        { write!(txt, "{:02X} ", c); }
5108    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5109
5110    let mut recovered = String::new();
5111    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5112    println!("B =\t{}", recovered);
5113    assert_eq!(recovered, "7 bytes");
5114    assert_eq!(recovered, message);
5115    println!();
5116
5117    // Normal case for the message of 8 bytes
5118    let key = 0x_1234567890ABCDEF_u64;
5119    println!("K =\t{:#016X}", key);
5120    let mut a_des = DES::new_with_key_u64(key);
5121
5122    let message = "I am OK.";
5123    println!("M =\t{}", message);
5124    let mut cipher = Vec::<u8>::new();
5125    a_des.encrypt_str_into_vec(&message, &mut cipher);
5126    print!("C =\t");
5127    for c in cipher.clone()
5128        { print!("{:02X} ", c); }
5129    println!();
5130    let mut txt = String::new();
5131    for c in cipher.clone()
5132        { write!(txt, "{:02X} ", c); }
5133    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5134
5135    let mut recovered = String::new();
5136    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5137    println!("B =\t{}", recovered);
5138    assert_eq!(recovered, "I am OK.");
5139    assert_eq!(recovered, message);
5140    println!();
5141
5142    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5143    let key = 0x_1234567890ABCDEF_u64;
5144    println!("K =\t{:#016X}", key);
5145    let mut a_des = DES::new_with_key_u64(key);
5146
5147    let message = "PARK Youngho";
5148    println!("M =\t{}", message);
5149    let mut cipher = Vec::<u8>::new();
5150    a_des.encrypt_str_into_vec(&message, &mut cipher);
5151    print!("C =\t");
5152    for c in cipher.clone()
5153        { print!("{:02X} ", c); }
5154    println!();
5155    let mut txt = String::new();
5156    for c in cipher.clone()
5157        { write!(txt, "{:02X} ", c); }
5158    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5159
5160    let mut recovered = String::new();
5161    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5162    println!("B =\t{}", recovered);
5163    assert_eq!(recovered, "PARK Youngho");
5164    assert_eq!(recovered, message);
5165    println!();
5166
5167    // Normal case for the message of 16 bytes
5168    let key = 0x_1234567890ABCDEF_u64;
5169    println!("K =\t{:#016X}", key);
5170    let mut a_des = DES::new_with_key_u64(key);
5171
5172    let message = "고맙습니다.";
5173    println!("M =\t{}", message);
5174    let mut cipher = Vec::<u8>::new();
5175    a_des.encrypt_str_into_vec(&message, &mut cipher);
5176    print!("C =\t");
5177    for c in cipher.clone()
5178        { print!("{:02X} ", c); }
5179    println!();
5180    let mut txt = String::new();
5181    for c in cipher.clone()
5182        { write!(txt, "{:02X} ", c); }
5183    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5184
5185    let mut recovered = String::new();
5186    a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5187    println!("B =\t{}", recovered);
5188    assert_eq!(recovered, "고맙습니다.");
5189    assert_eq!(recovered, message);
5190    println!("-------------------------------");
5191}
Source

fn decrypt_array<U, const N: usize>( &mut self, cipher: &[U; N], message: *mut u8, ) -> u64
where U: SmallUInt + Copy + Clone,

Decrypts the data stored in an array [U; N] object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode.

§Arguments
  • cipher is an immutable reference to an array [U; N] object, and is the place where the plaintext to be decrypted is stored.
  • message is a mutable pointer to u8 which is *mut u8, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * N is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • You are not encouraged to use this method in pure Rust programming. Instead, use other safer methods such as decrypt_array_into_*().
  • This method is useful to use in hybrid programming with C/C++.
  • size_of::<U>() * N cannot be other than any multiple of size_of::<T>().
  • The size of the memory area which starts at message is assumed to be enough to store the plaintext. So, it is responsible for you to prepare the message area big enough!
  • The size of the area for plaintext does not have to be prepared more than size_of::<U>() * N - 1.
  • If the size of the area for plaintext is prepared more than size_of::<U>() * N - 1, the rest of the area will be filled with 0s.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
println!();
 
let mut recovered = vec![0; 55];
a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_str_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = vec![0; 55];
let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
recovered.truncate(len as usize);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = vec![0; 55];
let len = taes.decrypt_array(&cipher, recovered.as_mut_ptr());
recovered.truncate(len as usize);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
tdes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = vec![0; 55];
let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
recovered.truncate(len as usize);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 799)
775fn bigcryptor64_decrypt_array_with_padding_iso_ecb()
776{
777    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb()");
778    use std::io::Write;
779    use std::fmt::Write as _;
780    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
781
782    // TDES case
783    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
784                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
785                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
786    let message = "In the beginning God created the heavens and the earth.";
787    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
788    tdes.encrypt_str_into_array(&message, &mut cipher);
789    print!("C =\t");
790    for c in cipher.clone()
791        { print!("{:02X} ", c); }
792    println!();
793    let mut txt = String::new();
794    for c in cipher.clone()
795        { write!(txt, "{:02X} ", c); }
796    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
797
798    let mut recovered = vec![0; 55];
799    let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
800    recovered.truncate(len as usize);
801    print!("Ba =\t");
802    for b in recovered.clone()
803        { print!("{:02X} ", b); }
804    println!();
805    let mut txt = String::new();
806    for c in recovered.clone()
807        { write!(txt, "{:02X} ", c); }
808    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
809
810    let mut converted = String::new();
811    unsafe { converted.as_mut_vec() }.append(&mut recovered);
812    
813    println!("Bb =\t{}", converted);
814    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
815    assert_eq!(converted, message);
816    println!("-------------------------------");
817}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 848)
821fn bigcryptor128_decrypt_array_with_padding_iso_ecb()
822{
823    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb()");
824    use std::io::Write;
825    use std::fmt::Write as _;
826    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
827
828    // TAES_128 case
829    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
830                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
831                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
832    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
833    println!("IV =	{:#034X}", iv);
834    let message = "In the beginning God created the heavens and the earth.";
835        println!("M =\t{}", message);
836    let mut cipher = [0_u8; 64];
837    taes.encrypt_str_into_array(&message, &mut cipher);
838    print!("C =\t");
839    for c in cipher.clone()
840        { print!("{:02X} ", c); }
841    println!();
842    let mut txt = String::new();
843    for c in cipher.clone()
844        { write!(txt, "{:02X} ", c); }
845    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
846
847    let mut recovered = vec![0; 55];
848    let len = taes.decrypt_array(&cipher, recovered.as_mut_ptr());
849    recovered.truncate(len as usize);
850    print!("Ba =\t");
851    for b in recovered.clone()
852        { print!("{:02X} ", b); }
853    println!();
854    let mut txt = String::new();
855    for c in recovered.clone()
856        { write!(txt, "{:02X} ", c); }
857    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
858
859    let mut converted = String::new();
860    unsafe { converted.as_mut_vec() }.append(&mut recovered);
861    
862    println!("Bb =\t{}", converted);
863    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
864    assert_eq!(converted, message);
865    println!("-------------------------------");
866}
examples/aes_ecb_iso_examples.rs (line 3449)
3423fn aes_decrypt_array_with_padding_iso_ecb()
3424{
3425    println!("aes_decrypt_array_with_padding_iso_ecb()");
3426    use std::io::Write;
3427    use std::fmt::Write as _;
3428    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3429
3430    // Normal case for AES-128
3431    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3432    println!("K =\t{:#016X}", key);
3433    let mut a_aes = AES_128::new_with_key_u128(key);
3434
3435    let message = "In the beginning God created the heavens and the earth.";
3436    println!("M =\t{}", message);
3437    let mut cipher = [0_u8; 64];
3438    a_aes.encrypt_str_into_array(&message, &mut cipher);
3439    print!("C =\t");
3440    for c in cipher.clone()
3441        { print!("{:02X} ", c); }
3442    println!();
3443    let mut txt = String::new();
3444    for c in cipher.clone()
3445        { write!(txt, "{:02X} ", c); }
3446    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3447
3448    let mut recovered = vec![0; 55];
3449    a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
3450    print!("Ba =\t");
3451    for b in recovered.clone()
3452        { print!("{:02X} ", b); }
3453    println!();
3454    let mut txt = String::new();
3455    for c in recovered.clone()
3456        { write!(txt, "{:02X} ", c); }
3457    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3458
3459    let mut converted = String::new();
3460    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3461    
3462    println!("Bb =\t{}", converted);
3463    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3464    assert_eq!(converted, message);
3465    println!();
3466
3467    // Normal case for AES-192
3468    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3469    print!("K =\t");
3470    for i in 0..24
3471        { print!("{:02X}", key[i]); }
3472    println!();
3473    let mut a_aes = AES_192::new_with_key(&key);
3474
3475    let message = "In the beginning God created the heavens and the earth.";
3476    println!("M =\t{}", message);
3477    let mut cipher = [0_u8; 64];
3478    a_aes.encrypt_str_into_array(&message, &mut cipher);
3479    print!("C =\t");
3480    for c in cipher.clone()
3481        { print!("{:02X} ", c); }
3482    println!();
3483    let mut txt = String::new();
3484    for c in cipher.clone()
3485        { write!(txt, "{:02X} ", c); }
3486    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3487
3488    let mut recovered = vec![0; 55];
3489    a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
3490    print!("Ba =\t");
3491    for b in recovered.clone()
3492        { print!("{:02X} ", b); }
3493    println!();
3494    let mut txt = String::new();
3495    for c in recovered.clone()
3496        { write!(txt, "{:02X} ", c); }
3497    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3498
3499    let mut converted = String::new();
3500    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3501    
3502    println!("Bb =\t{}", converted);
3503    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3504    assert_eq!(converted, message);
3505    println!();
3506
3507    // Normal case for AES-256
3508    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3509    print!("K =\t");
3510    for i in 0..32
3511        { print!("{:02X}", key[i]); }
3512    println!();
3513    let mut a_aes = AES_256::new_with_key(&key);
3514
3515    let message = "In the beginning God created the heavens and the earth.";
3516    println!("M =\t{}", message);
3517    let mut cipher = [0_u8; 64];
3518    a_aes.encrypt_str_into_array(&message, &mut cipher);
3519    print!("C =\t");
3520    for c in cipher.clone()
3521        { print!("{:02X} ", c); }
3522    println!();
3523    let mut txt = String::new();
3524    for c in cipher.clone()
3525        { write!(txt, "{:02X} ", c); }
3526    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3527
3528    let mut recovered = vec![0; 55];
3529    a_aes.decrypt_array(&cipher, recovered.as_mut_ptr());
3530    print!("Ba =\t");
3531    for b in recovered.clone()
3532        { print!("{:02X} ", b); }
3533    println!();
3534    let mut txt = String::new();
3535    for c in recovered.clone()
3536        { write!(txt, "{:02X} ", c); }
3537    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3538
3539    let mut converted = String::new();
3540    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3541    
3542    println!("Bb =\t{}", converted);
3543    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3544    assert_eq!(converted, message);
3545    println!();
3546
3547    // Normal case for Rijndael-256-256
3548    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3549    print!("K =\t");
3550    for i in 0..32
3551        { print!("{:02X}", key[i]); }
3552    println!();
3553    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3554
3555    let message = "In the beginning God created the heavens and the earth.";
3556    println!("M =\t{}", message);
3557    let mut cipher = [0_u8; 64];
3558    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3559    print!("C =\t");
3560    for c in cipher.clone()
3561        { print!("{:02X} ", c); }
3562    println!();
3563    let mut txt = String::new();
3564    for c in cipher.clone()
3565        { write!(txt, "{:02X} ", c); }
3566    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3567
3568    let mut recovered = vec![0; 55];
3569    a_rijndael.decrypt_array(&cipher, recovered.as_mut_ptr());
3570    print!("Ba =\t");
3571    for b in recovered.clone()
3572        { print!("{:02X} ", b); }
3573    println!();
3574    let mut txt = String::new();
3575    for c in recovered.clone()
3576        { write!(txt, "{:02X} ", c); }
3577    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3578
3579    let mut converted = String::new();
3580    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3581    
3582    println!("Bb =\t{}", converted);
3583    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3584    assert_eq!(converted, message);
3585    println!();
3586
3587    // Normal case for Rijndael-512-512 for post-quantum
3588    use cryptocol::number::SharedArrays;
3589    use cryptocol::hash::SHA3_512;
3590    let mut sha3 = SHA3_512::new();
3591    sha3.absorb_str("Post-quantum");
3592    let key: [u8; 64] = sha3.get_hash_value_in_array();
3593    print!("K =\t");
3594    for i in 0..64
3595        { print!("{:02X}", key[i]); }
3596    println!();
3597    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3598    let message = "In the beginning God created the heavens and the earth.";
3599    println!("M =\t{}", message);
3600    let mut cipher = [0_u8; 64];
3601    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3602    print!("C =\t");
3603    for c in cipher.clone()
3604        { print!("{:02X} ", c); }
3605    println!();
3606    let mut txt = String::new();
3607    for c in cipher.clone()
3608        { write!(txt, "{:02X} ", c); }
3609    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3610    
3611    let mut recovered = vec![0; 55];
3612    a_rijndael.decrypt_array(&cipher, recovered.as_mut_ptr());
3613    print!("Ba =\t");
3614    for b in recovered.clone()
3615        { print!("{:02X} ", b); }
3616    println!();
3617    let mut txt = String::new();
3618    for c in recovered.clone()
3619        { write!(txt, "{:02X} ", c); }
3620    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3621
3622    let mut converted = String::new();
3623    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3624    
3625    println!("Bb =\t{}", converted);
3626    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3627    assert_eq!(converted, message);
3628    println!("-------------------------------");
3629}
examples/des_ecb_iso_examples.rs (line 5219)
5193fn des_decrypt_array_with_padding_iso_ecb()
5194{
5195    println!("des_decrypt_array_with_padding_iso_ecb()");
5196    use std::io::Write;
5197    use std::fmt::Write as _;
5198    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5199
5200    // Normal case
5201    let key = 0x_1234567890ABCDEF_u64;
5202    println!("K =\t{:#016X}", key);
5203    let mut a_des = DES::new_with_key_u64(key);
5204
5205    let message = "In the beginning God created the heavens and the earth.";
5206    println!("M =\t{}", message);
5207    let mut cipher = [0_u8; 56];
5208    a_des.encrypt_str_into_array(&message, &mut cipher);
5209    print!("C (16 rounds) =\t");
5210    for c in cipher.clone()
5211        { print!("{:02X} ", c); }
5212    println!();
5213    let mut txt = String::new();
5214    for c in cipher.clone()
5215        { write!(txt, "{:02X} ", c); }
5216    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5217
5218    let mut recovered = vec![0; 55];
5219    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5220    recovered.truncate(len as usize);
5221    print!("Ba (16 rounds) =\t");
5222    for b in recovered.clone()
5223        { print!("{:02X} ", b); }
5224    println!();
5225    let mut txt = String::new();
5226    for c in recovered.clone()
5227        { write!(txt, "{:02X} ", c); }
5228    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5229
5230    let mut converted = String::new();
5231    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5232    
5233    println!("Bb (16 rounds) =\t{}", converted);
5234    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5235    assert_eq!(converted, message);
5236    println!();
5237
5238    // Expanded case for 128 rounds
5239    let key = 0x_1234567890ABCDEF_u64;
5240    println!("K =\t{:#016X}", key);
5241    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5242
5243    let message = "In the beginning God created the heavens and the earth.";
5244    println!("M =\t{}", message);
5245    let mut cipher = [0_u8; 56];
5246    a_des.encrypt_str_into_array(&message, &mut cipher);
5247    print!("C (128 rounds) =\t");
5248    for c in cipher.clone()
5249        { print!("{:02X} ", c); }
5250    println!();
5251    let mut txt = String::new();
5252    for c in cipher.clone()
5253        { write!(txt, "{:02X} ", c); }
5254    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5255
5256    let mut recovered = vec![0; 55];
5257    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5258    recovered.truncate(len as usize);
5259    print!("Ba (128 rounds) =\t");
5260    for b in recovered.clone()
5261        { print!("{:02X} ", b); }
5262    println!();
5263    let mut txt = String::new();
5264    for c in recovered.clone()
5265        { write!(txt, "{:02X} ", c); }
5266    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5267
5268    let mut converted = String::new();
5269    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5270
5271    println!("Bb (128 rounds) =\t{}", converted);
5272    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5273    assert_eq!(converted, message);
5274    println!();
5275
5276    // Expanded case for 0 rounds which means that key is meaningless
5277    let key1 = 0x_1234567890ABCDEF_u64;
5278    let key2 = 0_u64;
5279    println!("K =\t{:#016X}", key);
5280    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5281    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5282
5283    let message = "In the beginning God created the heavens and the earth.";
5284    println!("M =\t{}", message);
5285    let mut cipher1 = [0_u8; 56];
5286    let mut cipher2 = [0_u8; 56];
5287    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5288    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5289    print!("C (0 rounds) =\t");
5290    for c in cipher1.clone()
5291        { print!("{:02X} ", c); }
5292    println!();
5293    let mut txt = String::new();
5294    for c in cipher1.clone()
5295        { write!(txt, "{:02X} ", c); }
5296    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5297    print!("D (0 rounds) =\t");
5298    for c in cipher2.clone()
5299        { print!("{:02X} ", c); }
5300    println!();
5301    let mut txt = String::new();
5302    for c in cipher2.clone()
5303        { write!(txt, "{:02X} ", c); }
5304    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5305
5306    let mut recovered1 = vec![0; 55];
5307    let mut recovered2 = vec![0; 55];
5308    let len1 = c_des.decrypt_array(&cipher1, recovered1.as_mut_ptr());
5309    let len2 = d_des.decrypt_array(&cipher2, recovered2.as_mut_ptr());
5310    recovered1.truncate(len1 as usize);
5311    recovered2.truncate(len2 as usize);
5312
5313    print!("B1a (0 rounds) =\t");
5314    for b in recovered1.clone()
5315        { print!("{:02X} ", b); }
5316    println!();
5317    let mut txt = String::new();
5318    for c in recovered1.clone()
5319        { write!(txt, "{:02X} ", c); }
5320    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5321    print!("B2a (0 rounds) =\t");
5322    for b in recovered2.clone()
5323        { print!("{:02X} ", b); }
5324    println!();
5325    let mut txt = String::new();
5326    for c in recovered2.clone()
5327        { write!(txt, "{:02X} ", c); }
5328    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5329
5330    let mut converted1 = String::new();
5331    let mut converted2 = String::new();
5332    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5333    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5334    
5335    println!("B1b (0 rounds) =\t{}", converted1);
5336    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5337    assert_eq!(converted1, message);
5338    println!("B2b (0 rounds) =\t{}", converted2);
5339    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5340    assert_eq!(converted2, message);
5341    assert_eq!(converted1, converted1);
5342    println!();
5343
5344    // Normal case for the message of 0 bytes
5345    let key = 0x_1234567890ABCDEF_u64;
5346    println!("K =\t{:#016X}", key);
5347    let mut a_des = DES::new_with_key_u64(key);
5348
5349    let message = "";
5350    println!("M =\t{}", message);
5351    let mut cipher = [0_u8; 8];
5352    a_des.encrypt_str_into_array(&message, &mut cipher);
5353    print!("C =\t");
5354    for c in cipher.clone()
5355        { print!("{:02X} ", c); }
5356    println!();
5357    let mut txt = String::new();
5358    for c in cipher.clone()
5359        { write!(txt, "{:02X} ", c); }
5360    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5361
5362    let mut recovered = vec![0; 8];
5363    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5364    recovered.truncate(len as usize);
5365
5366    print!("Ba =\t");
5367    for b in recovered.clone()
5368        { print!("{:02X} ", b); }
5369    println!();
5370    let mut txt = String::new();
5371    for c in recovered.clone()
5372        { write!(txt, "{:02X} ", c); }
5373    assert_eq!(txt, "");
5374
5375    let mut converted = String::new();
5376    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5377    
5378    println!("Bb =\t{}", converted);
5379    assert_eq!(converted, "");
5380    assert_eq!(converted, message);
5381    println!();
5382
5383    // Normal case for the message shorter than 8 bytes
5384    let key = 0x_1234567890ABCDEF_u64;
5385    println!("K =\t{:#016X}", key);
5386    let mut a_des = DES::new_with_key_u64(key);
5387
5388    let message = "7 bytes";
5389    println!("M =\t{}", message);
5390    let mut cipher = [0_u8; 8];
5391    a_des.encrypt_str_into_array(&message, &mut cipher);
5392    print!("C =\t");
5393    for c in cipher.clone()
5394        { print!("{:02X} ", c); }
5395    println!();
5396    let mut txt = String::new();
5397    for c in cipher.clone()
5398        { write!(txt, "{:02X} ", c); }
5399    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5400    
5401    let mut recovered = vec![0; 8];
5402    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5403    recovered.truncate(len as usize);
5404
5405    print!("Ba =\t");
5406    for b in recovered.clone()
5407        { print!("{:02X} ", b); }
5408    println!();
5409    let mut txt = String::new();
5410    for c in recovered.clone()
5411        { write!(txt, "{:02X} ", c); }
5412    assert_eq!(txt, "37 20 62 79 74 65 73 ");
5413
5414    let mut converted = String::new();
5415    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5416
5417    println!("Bb =\t{}", converted);
5418    assert_eq!(converted, "7 bytes");
5419    assert_eq!(converted, message);
5420    println!();
5421
5422    // Normal case for the message of 8 bytes
5423    let key = 0x_1234567890ABCDEF_u64;
5424    println!("K =\t{:#016X}", key);
5425    let mut a_des = DES::new_with_key_u64(key);
5426
5427    let message = "I am OK.";
5428    println!("M =\t{}", message);
5429    let mut cipher = [0_u8; 16];
5430    a_des.encrypt_str_into_array(&message, &mut cipher);
5431    print!("C =\t");
5432    for c in cipher.clone()
5433        { print!("{:02X} ", c); }
5434    println!();
5435    let mut txt = String::new();
5436    for c in cipher.clone()
5437        { write!(txt, "{:02X} ", c); }
5438    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5439    
5440    let mut recovered = vec![0; 16];
5441    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5442    recovered.truncate(len as usize);
5443
5444    print!("Ba =\t");
5445    for b in recovered.clone()
5446        { print!("{:02X} ", b); }
5447    println!();
5448    let mut txt = String::new();
5449    for c in recovered.clone()
5450        { write!(txt, "{:02X} ", c); }
5451    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5452
5453    let mut converted = String::new();
5454    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5455    
5456    println!("Bb =\t{}", converted);
5457    assert_eq!(converted, "I am OK.");
5458    assert_eq!(converted, message);
5459    println!();
5460
5461    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5462    let key = 0x_1234567890ABCDEF_u64;
5463    println!("K =\t{:#016X}", key);
5464    let mut a_des = DES::new_with_key_u64(key);
5465
5466    let message = "PARK Youngho";
5467    println!("M =\t{}", message);
5468    let mut cipher = [0_u8; 16];
5469    a_des.encrypt_str_into_array(&message, &mut cipher);
5470    print!("C =\t");
5471    for c in cipher.clone()
5472        { print!("{:02X} ", c); }
5473    println!();
5474    let mut txt = String::new();
5475    for c in cipher.clone()
5476        { write!(txt, "{:02X} ", c); }
5477    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5478
5479    let mut recovered = vec![0; 16];
5480    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5481    recovered.truncate(len as usize);
5482    print!("Ba =\t");
5483    for b in recovered.clone()
5484        { print!("{:02X} ", b); }
5485    println!();
5486    let mut txt = String::new();
5487    for c in recovered.clone()
5488        { write!(txt, "{:02X} ", c); }
5489    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5490
5491    let mut converted = String::new();
5492    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5493    
5494    println!("Bb =\t{}", converted);
5495    assert_eq!(converted, "PARK Youngho");
5496    assert_eq!(converted, message);
5497    println!();
5498
5499    // Normal case for the message of 16 bytes
5500    let key = 0x_1234567890ABCDEF_u64;
5501    println!("K =\t{:#016X}", key);
5502    let mut a_des = DES::new_with_key_u64(key);
5503
5504    let message = "고맙습니다.";
5505    println!("M =\t{}", message);
5506    let mut cipher = [0_u8; 24];
5507    a_des.encrypt_str_into_array(&message, &mut cipher);
5508    print!("C =\t");
5509    for c in cipher.clone()
5510        { print!("{:02X} ", c); }
5511    println!();
5512    let mut txt = String::new();
5513    for c in cipher.clone()
5514        { write!(txt, "{:02X} ", c); }
5515    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5516
5517    let mut recovered = vec![0; 24];
5518    let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5519    recovered.truncate(len as usize);
5520
5521    print!("Ba =\t");
5522    for b in recovered.clone()
5523        { print!("{:02X} ", b); }
5524    println!();
5525    let mut txt = String::new();
5526    for c in recovered.clone()
5527        { write!(txt, "{:02X} ", c); }
5528    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5529
5530    let mut converted = String::new();
5531    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5532    
5533    println!("Bb =\t{}", converted);
5534    assert_eq!(converted, "고맙습니다.");
5535    assert_eq!(converted, message);
5536    println!("-------------------------------");
5537}
Source

fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Decrypts the data stored in an array [U; N] object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in Vec<V>.

§Arguments
  • cipher is an immutable reference to an array [U; N] object, and is the place where the plaintext to be decrypted is stored.
  • message is a mutable reference to Vec<U> object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * N is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
println!();
 
let mut recovered = vec![0; 55];
a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_str_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = Vec::<u8>::new();
a_des.decrypt_array_into_vec(&cipher, &mut recovered);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = Vec::<u8>::new();
taes.decrypt_array_into_vec(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
tdes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = Vec::<u8>::new();
tdes.decrypt_array_into_vec(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.append(&mut recovered);
 
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 843)
819fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()
820{
821    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()");
822    use std::io::Write;
823    use std::fmt::Write as _;
824    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
825
826    // TDES case
827    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
828                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
829                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
830    let message = "In the beginning God created the heavens and the earth.";
831    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
832    tdes.encrypt_str_into_array(&message, &mut cipher);
833    print!("C =\t");
834    for c in cipher.clone()
835        { print!("{:02X} ", c); }
836    println!();
837    let mut txt = String::new();
838    for c in cipher.clone()
839        { write!(txt, "{:02X} ", c); }
840    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
841
842    let mut recovered = Vec::<u8>::new();
843    tdes.decrypt_array_into_vec(&cipher, &mut recovered);
844    print!("Ba =\t");
845    for b in recovered.clone()
846        { print!("{:02X} ", b); }
847    println!();
848    let mut txt = String::new();
849    for c in recovered.clone()
850        { write!(txt, "{:02X} ", c); }
851    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
852
853    let mut converted = String::new();
854    unsafe { converted.as_mut_vec() }.append(&mut recovered);
855    
856    println!("Bb =\t{}", converted);
857    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
858    assert_eq!(converted, message);
859    println!("-------------------------------");
860}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 895)
868fn bigcryptor128_decrypt_array_with_padding_iso_ecb_into_vec()
869{
870    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb_into_vec()");
871    use std::io::Write;
872    use std::fmt::Write as _;
873    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
874
875    // TAES_128 case
876    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
877                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
878                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
879    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
880    println!("IV =	{:#034X}", iv);
881    let message = "In the beginning God created the heavens and the earth.";
882    println!("M =\t{}", message);
883    let mut cipher = [0_u8; 64];
884    taes.encrypt_str_into_array(&message, &mut cipher);
885    print!("C =\t");
886    for c in cipher.clone()
887        { print!("{:02X} ", c); }
888    println!();
889    let mut txt = String::new();
890    for c in cipher.clone()
891        { write!(txt, "{:02X} ", c); }
892    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
893
894    let mut recovered = Vec::<u8>::new();
895    taes.decrypt_array_into_vec(&cipher, &mut recovered);
896    print!("Ba =\t");
897    for b in recovered.clone()
898        { print!("{:02X} ", b); }
899    println!();
900    let mut txt = String::new();
901    for c in recovered.clone()
902        { write!(txt, "{:02X} ", c); }
903    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
904
905    let mut converted = String::new();
906    unsafe { converted.as_mut_vec() }.append(&mut recovered);
907    
908    println!("Bb =\t{}", converted);
909    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
910    assert_eq!(converted, message);
911    println!("-------------------------------");
912}
examples/aes_ecb_iso_examples.rs (line 3657)
3631fn aes_decrypt_array_with_padding_iso_ecb_into_vec()
3632{
3633    println!("aes_decrypt_array_with_padding_iso_ecb_into_vec()");
3634    use std::io::Write;
3635    use std::fmt::Write as _;
3636    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3637
3638    // Normal case for AES-128
3639    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3640    println!("K =\t{:#016X}", key);
3641    let mut a_aes = AES_128::new_with_key_u128(key);
3642
3643    let message = "In the beginning God created the heavens and the earth.";
3644    println!("M =\t{}", message);
3645    let mut cipher = [0_u8; 64];
3646    a_aes.encrypt_str_into_array(&message, &mut cipher);
3647    print!("C =\t");
3648    for c in cipher.clone()
3649        { print!("{:02X} ", c); }
3650    println!();
3651    let mut txt = String::new();
3652    for c in cipher.clone()
3653        { write!(txt, "{:02X} ", c); }
3654    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3655
3656    let mut recovered = vec![0; 55];
3657    a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
3658    print!("Ba =\t");
3659    for b in recovered.clone()
3660        { print!("{:02X} ", b); }
3661    println!();
3662    let mut txt = String::new();
3663    for c in recovered.clone()
3664        { write!(txt, "{:02X} ", c); }
3665    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3666
3667    let mut converted = String::new();
3668    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3669    
3670    println!("Bb =\t{}", converted);
3671    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3672    assert_eq!(converted, message);
3673    println!();
3674
3675    // Normal case for AES-192
3676    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3677    print!("K =\t");
3678    for i in 0..24
3679        { print!("{:02X}", key[i]); }
3680    println!();
3681    let mut a_aes = AES_192::new_with_key(&key);
3682
3683    let message = "In the beginning God created the heavens and the earth.";
3684    println!("M =\t{}", message);
3685    let mut cipher = [0_u8; 64];
3686    a_aes.encrypt_str_into_array(&message, &mut cipher);
3687    print!("C =\t");
3688    for c in cipher.clone()
3689        { print!("{:02X} ", c); }
3690    println!();
3691    let mut txt = String::new();
3692    for c in cipher.clone()
3693        { write!(txt, "{:02X} ", c); }
3694    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3695
3696    let mut recovered = vec![0; 55];
3697    a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
3698    print!("Ba =\t");
3699    for b in recovered.clone()
3700        { print!("{:02X} ", b); }
3701    println!();
3702    let mut txt = String::new();
3703    for c in recovered.clone()
3704        { write!(txt, "{:02X} ", c); }
3705    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3706
3707    let mut converted = String::new();
3708    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3709    
3710    println!("Bb =\t{}", converted);
3711    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3712    assert_eq!(converted, message);
3713    println!();
3714
3715    // Normal case for AES-256
3716    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3717    print!("K =\t");
3718    for i in 0..32
3719        { print!("{:02X}", key[i]); }
3720    println!();
3721    let mut a_aes = AES_256::new_with_key(&key);
3722
3723    let message = "In the beginning God created the heavens and the earth.";
3724    println!("M =\t{}", message);
3725    let mut cipher = [0_u8; 64];
3726    a_aes.encrypt_str_into_array(&message, &mut cipher);
3727    print!("C =\t");
3728    for c in cipher.clone()
3729        { print!("{:02X} ", c); }
3730    println!();
3731    let mut txt = String::new();
3732    for c in cipher.clone()
3733        { write!(txt, "{:02X} ", c); }
3734    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3735
3736    let mut recovered = vec![0; 55];
3737    a_aes.decrypt_array_into_vec(&cipher, &mut recovered);
3738    print!("Ba =\t");
3739    for b in recovered.clone()
3740        { print!("{:02X} ", b); }
3741    println!();
3742    let mut txt = String::new();
3743    for c in recovered.clone()
3744        { write!(txt, "{:02X} ", c); }
3745    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3746
3747    let mut converted = String::new();
3748    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3749    
3750    println!("Bb =\t{}", converted);
3751    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3752    assert_eq!(converted, message);
3753    println!();
3754
3755    // Normal case for Rijndael-256-256
3756    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3757    print!("K =\t");
3758    for i in 0..32
3759        { print!("{:02X}", key[i]); }
3760    println!();
3761    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3762
3763    let message = "In the beginning God created the heavens and the earth.";
3764    println!("M =\t{}", message);
3765    let mut cipher = [0_u8; 64];
3766    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3767    print!("C =\t");
3768    for c in cipher.clone()
3769        { print!("{:02X} ", c); }
3770    println!();
3771    let mut txt = String::new();
3772    for c in cipher.clone()
3773        { write!(txt, "{:02X} ", c); }
3774    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3775
3776    let mut recovered = vec![0; 55];
3777    a_rijndael.decrypt_array_into_vec(&cipher, &mut recovered);
3778    print!("Ba =\t");
3779    for b in recovered.clone()
3780        { print!("{:02X} ", b); }
3781    println!();
3782    let mut txt = String::new();
3783    for c in recovered.clone()
3784        { write!(txt, "{:02X} ", c); }
3785    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3786
3787    let mut converted = String::new();
3788    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3789    
3790    println!("Bb =\t{}", converted);
3791    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3792    assert_eq!(converted, message);
3793    println!();
3794
3795    // Normal case for Rijndael-512-512 for post-quantum
3796    use cryptocol::number::SharedArrays;
3797    use cryptocol::hash::SHA3_512;
3798    let mut sha3 = SHA3_512::new();
3799    sha3.absorb_str("Post-quantum");
3800    let key: [u8; 64] = sha3.get_hash_value_in_array();
3801    print!("K =\t");
3802    for i in 0..64
3803        { print!("{:02X}", key[i]); }
3804    println!();
3805    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
3806    let message = "In the beginning God created the heavens and the earth.";
3807    println!("M =\t{}", message);
3808    let mut cipher = [0_u8; 64];
3809    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3810    print!("C =\t");
3811    for c in cipher.clone()
3812        { print!("{:02X} ", c); }
3813    println!();
3814    let mut txt = String::new();
3815    for c in cipher.clone()
3816        { write!(txt, "{:02X} ", c); }
3817    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
3818
3819    let mut recovered = vec![0; 55];
3820    a_rijndael.decrypt_array_into_vec(&cipher, &mut recovered);
3821    print!("Ba =\t");
3822    for b in recovered.clone()
3823        { print!("{:02X} ", b); }
3824    println!();
3825    let mut txt = String::new();
3826    for c in recovered.clone()
3827        { write!(txt, "{:02X} ", c); }
3828    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3829
3830    let mut converted = String::new();
3831    unsafe { converted.as_mut_vec() }.append(&mut recovered);
3832    
3833    println!("Bb =\t{}", converted);
3834    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3835    assert_eq!(converted, message);
3836    println!("-------------------------------");
3837}
examples/des_ecb_iso_examples.rs (line 5565)
5539fn des_decrypt_array_with_padding_iso_ecb_into_vec()
5540{
5541    println!("des_decrypt_array_with_padding_iso_ecb_into_vec()");
5542    use std::io::Write;
5543    use std::fmt::Write as _;
5544    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5545
5546    // Normal case
5547    let key = 0x_1234567890ABCDEF_u64;
5548    println!("K =\t{:#016X}", key);
5549    let mut a_des = DES::new_with_key_u64(key);
5550
5551    let message = "In the beginning God created the heavens and the earth.";
5552    println!("M =\t{}", message);
5553    let mut cipher = [0_u8; 56];
5554    a_des.encrypt_str_into_array(&message, &mut cipher);
5555    print!("C (16 rounds) =\t");
5556    for c in cipher.clone()
5557        { print!("{:02X} ", c); }
5558    println!();
5559    let mut txt = String::new();
5560    for c in cipher.clone()
5561        { write!(txt, "{:02X} ", c); }
5562    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5563
5564    let mut recovered = Vec::<u8>::new();
5565    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5566    print!("Ba (16 rounds) =\t");
5567    for b in recovered.clone()
5568        { print!("{:02X} ", b); }
5569    println!();
5570    let mut txt = String::new();
5571    for c in recovered.clone()
5572        { write!(txt, "{:02X} ", c); }
5573    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5574
5575    let mut converted = String::new();
5576    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5577    
5578    println!("Bb (16 rounds) =\t{}", converted);
5579    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5580    assert_eq!(converted, message);
5581    println!();
5582
5583    // Expanded case for 128 rounds
5584    let key = 0x_1234567890ABCDEF_u64;
5585    println!("K =\t{:#016X}", key);
5586    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5587
5588    let message = "In the beginning God created the heavens and the earth.";
5589    println!("M =\t{}", message);
5590    let mut cipher = [0_u8; 56];
5591    a_des.encrypt_str_into_array(&message, &mut cipher);
5592    print!("C (128 rounds) =\t");
5593    for c in cipher.clone()
5594        { print!("{:02X} ", c); }
5595    println!();
5596    let mut txt = String::new();
5597    for c in cipher.clone()
5598        { write!(txt, "{:02X} ", c); }
5599    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5600
5601    let mut recovered = Vec::<u8>::new();
5602    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5603    print!("Ba (128 rounds) =\t");
5604    for b in recovered.clone()
5605        { print!("{:02X} ", b); }
5606    println!();
5607    let mut txt = String::new();
5608    for c in recovered.clone()
5609        { write!(txt, "{:02X} ", c); }
5610    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5611
5612    let mut converted = String::new();
5613    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5614    
5615    println!("Bb (128 rounds) =\t{}", converted);
5616    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5617    assert_eq!(converted, message);
5618    println!();
5619
5620    // Expanded case for 0 rounds which means that key is meaningless
5621    let key1 = 0x_1234567890ABCDEF_u64;
5622    let key2 = 0_u64;
5623    println!("K =\t{:#016X}", key);
5624    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5625    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5626
5627    let message = "In the beginning God created the heavens and the earth.";
5628    println!("M =\t{}", message);
5629    let mut cipher1 = [0_u8; 56];
5630    let mut cipher2 = [0_u8; 56];
5631    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5632    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5633    print!("C (0 rounds) =\t");
5634    for c in cipher1.clone()
5635        { print!("{:02X} ", c); }
5636    println!();
5637    let mut txt = String::new();
5638    for c in cipher1.clone()
5639        { write!(txt, "{:02X} ", c); }
5640    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5641    print!("D (0 rounds) =\t");
5642    for c in cipher2.clone()
5643        { print!("{:02X} ", c); }
5644    println!();
5645    let mut txt = String::new();
5646    for c in cipher2.clone()
5647        { write!(txt, "{:02X} ", c); }
5648    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5649
5650    let mut recovered1 = Vec::<u8>::new();
5651    let mut recovered2 = Vec::<u8>::new();
5652    c_des.decrypt_array_into_vec(&cipher1, &mut recovered1);
5653    d_des.decrypt_array_into_vec(&cipher2, &mut recovered2);
5654    print!("B1a (0 rounds) =\t");
5655    for b in recovered1.clone()
5656        { print!("{:02X} ", b); }
5657    println!();
5658    let mut txt = String::new();
5659    for c in recovered1.clone()
5660        { write!(txt, "{:02X} ", c); }
5661    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5662    print!("B2a (0 rounds) =\t");
5663    for b in recovered2.clone()
5664        { print!("{:02X} ", b); }
5665    println!();
5666    let mut txt = String::new();
5667    for c in recovered2.clone()
5668        { write!(txt, "{:02X} ", c); }
5669    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5670
5671    let mut converted1 = String::new();
5672    let mut converted2 = String::new();
5673    unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5674    unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5675    
5676    println!("B1b (0 rounds) =\t{}", converted1);
5677    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5678    assert_eq!(converted1, message);
5679    println!("B2b (0 rounds) =\t{}", converted2);
5680    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5681    assert_eq!(converted2, message);
5682    assert_eq!(converted1, converted1);
5683    println!();
5684
5685    // Normal case for the message of 0 bytes
5686    let key = 0x_1234567890ABCDEF_u64;
5687    println!("K =\t{:#016X}", key);
5688    let mut a_des = DES::new_with_key_u64(key);
5689
5690    let message = "";
5691    println!("M =\t{}", message);
5692    let mut cipher = [0_u8; 8];
5693    a_des.encrypt_str_into_array(&message, &mut cipher);
5694    print!("C =\t");
5695    for c in cipher.clone()
5696        { print!("{:02X} ", c); }
5697    println!();
5698    let mut txt = String::new();
5699    for c in cipher.clone()
5700        { write!(txt, "{:02X} ", c); }
5701    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5702
5703    let mut recovered = Vec::<u8>::new();
5704    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5705    print!("Ba =\t");
5706    for b in recovered.clone()
5707        { print!("{:02X} ", b); }
5708    println!();
5709    let mut txt = String::new();
5710    for c in recovered.clone()
5711        { write!(txt, "{:02X} ", c); }
5712    assert_eq!(txt, "");
5713
5714    let mut converted = String::new();
5715    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5716    
5717    println!("Bb =\t{}", converted);
5718    assert_eq!(converted, "");
5719    assert_eq!(converted, message);
5720    println!();
5721
5722    // Normal case for the message shorter than 8 bytes
5723    let key = 0x_1234567890ABCDEF_u64;
5724    println!("K =\t{:#016X}", key);
5725    let mut a_des = DES::new_with_key_u64(key);
5726
5727    let message = "7 bytes";
5728    println!("M =\t{}", message);
5729    let mut cipher = [0_u8; 8];
5730    a_des.encrypt_str_into_array(&message, &mut cipher);
5731    print!("C =\t");
5732    for c in cipher.clone()
5733        { print!("{:02X} ", c); }
5734    println!();
5735    let mut txt = String::new();
5736    for c in cipher.clone()
5737        { write!(txt, "{:02X} ", c); }
5738    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5739    
5740    let mut recovered = Vec::<u8>::new();
5741    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5742    print!("Ba =\t");
5743    for b in recovered.clone()
5744        { print!("{:02X} ", b); }
5745    println!();
5746    let mut txt = String::new();
5747    for c in recovered.clone()
5748        { write!(txt, "{:02X} ", c); }
5749    assert_eq!(txt, "37 20 62 79 74 65 73 ");
5750
5751    let mut converted = String::new();
5752    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5753    
5754    println!("Bb =\t{}", converted);
5755    assert_eq!(converted, "7 bytes");
5756    assert_eq!(converted, message);
5757    println!();
5758
5759    // Normal case for the message of 8 bytes
5760    let key = 0x_1234567890ABCDEF_u64;
5761    println!("K =\t{:#016X}", key);
5762    let mut a_des = DES::new_with_key_u64(key);
5763
5764    let message = "I am OK.";
5765    println!("M =\t{}", message);
5766    let mut cipher = [0_u8; 16];
5767    a_des.encrypt_str_into_array(&message, &mut cipher);
5768    print!("C =\t");
5769    for c in cipher.clone()
5770        { print!("{:02X} ", c); }
5771    println!();
5772    let mut txt = String::new();
5773    for c in cipher.clone()
5774        { write!(txt, "{:02X} ", c); }
5775    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5776    
5777    let mut recovered = Vec::<u8>::new();
5778    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5779    print!("Ba =\t");
5780    for b in recovered.clone()
5781        { print!("{:02X} ", b); }
5782    println!();
5783    let mut txt = String::new();
5784    for c in recovered.clone()
5785        { write!(txt, "{:02X} ", c); }
5786    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5787
5788    let mut converted = String::new();
5789    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5790    
5791    println!("Bb =\t{}", converted);
5792    assert_eq!(converted, "I am OK.");
5793    assert_eq!(converted, message);
5794    println!();
5795
5796    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5797    let key = 0x_1234567890ABCDEF_u64;
5798    println!("K =\t{:#016X}", key);
5799    let mut a_des = DES::new_with_key_u64(key);
5800
5801    let message = "PARK Youngho";
5802    println!("M =\t{}", message);
5803    let mut cipher = [0_u8; 16];
5804    a_des.encrypt_str_into_array(&message, &mut cipher);
5805    print!("C =\t");
5806    for c in cipher.clone()
5807        { print!("{:02X} ", c); }
5808    println!();
5809    let mut txt = String::new();
5810    for c in cipher.clone()
5811        { write!(txt, "{:02X} ", c); }
5812    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5813
5814    let mut recovered = Vec::<u8>::new();
5815    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5816    print!("Ba =\t");
5817    for b in recovered.clone()
5818        { print!("{:02X} ", b); }
5819    println!();
5820    let mut txt = String::new();
5821    for c in recovered.clone()
5822        { write!(txt, "{:02X} ", c); }
5823    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5824
5825    let mut converted = String::new();
5826    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5827    
5828    println!("Bb =\t{}", converted);
5829    assert_eq!(converted, "PARK Youngho");
5830    assert_eq!(converted, message);
5831    println!();
5832
5833    // Normal case for the message of 16 bytes
5834    let key = 0x_1234567890ABCDEF_u64;
5835    println!("K =\t{:#016X}", key);
5836    let mut a_des = DES::new_with_key_u64(key);
5837
5838    let message = "고맙습니다.";
5839    println!("M =\t{}", message);
5840    let mut cipher = [0_u8; 24];
5841    a_des.encrypt_str_into_array(&message, &mut cipher);
5842    print!("C =\t");
5843    for c in cipher.clone()
5844        { print!("{:02X} ", c); }
5845    println!();
5846    let mut txt = String::new();
5847    for c in cipher.clone()
5848        { write!(txt, "{:02X} ", c); }
5849    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5850
5851    let mut recovered = Vec::<u8>::new();
5852    a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5853    print!("Ba =\t");
5854    for b in recovered.clone()
5855        { print!("{:02X} ", b); }
5856    println!();
5857    let mut txt = String::new();
5858    for c in recovered.clone()
5859        { write!(txt, "{:02X} ", c); }
5860    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5861
5862    let mut converted = String::new();
5863    unsafe { converted.as_mut_vec() }.append(&mut recovered);
5864    
5865    println!("Bb =\t{}", converted);
5866    assert_eq!(converted, "고맙습니다.");
5867    assert_eq!(converted, message);
5868    println!("-------------------------------");
5869}
Source

fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, cipher: &[U; N], message: &mut [V; M], ) -> u64
where U: SmallUInt + Copy + Clone, V: SmallUInt + Copy + Clone,

Decrypts the data stored in an array [U; N] object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in array [V; M].

§Arguments
  • cipher is an immutable reference to an array [U; N] object, and is the place where the plaintext to be decrypted is stored.
  • message is a mutable reference to an array [U; N] object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * N is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • If size_of::<V>() * M is less than size_of::<U>() * N - 1, this method does not perform decryption but returns zero.
  • If size_of::<V>() * M is equal to or greater than size_of::<U>() * N - 1, this method performs decryption, fills the array message with the decrypted data, and then fills the rest of the elements of the array message with zeros, and returns the size of the plaintext.
  • It is responsible for you to prepare the message area big enough!
  • The size of the area for plaintext does not have to be prepared more than size_of::<U>() * N - 1.
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut recovered = [0; 64];
let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_str_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = [0u8; 56];
let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
print!("Ba (16 rounds) =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb (16 rounds) =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = [0u8; 64];
let len = taes.decrypt_array_into_array(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
tdes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = [0u8; 56];
let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
print!("Ba =\t");
for b in recovered.clone()
    { print!("{:02X} ", b); }
println!();
let mut txt = String::new();
for c in recovered.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
 
let mut converted = String::new();
unsafe { converted.as_mut_vec() }.write(&recovered);
unsafe { converted.as_mut_vec() }.truncate(len as usize);
println!("Bb =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 886)
862fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()
863{
864    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()");
865    use std::io::Write;
866    use std::fmt::Write as _;
867    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
868
869    // TDES case
870    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
871                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
872                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
873    let message = "In the beginning God created the heavens and the earth.";
874    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
875    tdes.encrypt_str_into_array(&message, &mut cipher);
876    print!("C =\t");
877    for c in cipher.clone()
878        { print!("{:02X} ", c); }
879    println!();
880    let mut txt = String::new();
881    for c in cipher.clone()
882        { write!(txt, "{:02X} ", c); }
883    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
884
885    let mut recovered = [0u8; 56];
886    let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
887    print!("Ba =\t");
888    for b in recovered.clone()
889        { print!("{:02X} ", b); }
890    println!();
891    let mut txt = String::new();
892    for c in recovered.clone()
893        { write!(txt, "{:02X} ", c); }
894    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
895
896    let mut converted = String::new();
897    unsafe { converted.as_mut_vec() }.write(&recovered);
898    unsafe { converted.as_mut_vec() }.truncate(len as usize);
899    println!("Bb =\t{}", converted);
900    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
901    assert_eq!(converted, message);
902    println!("-------------------------------");
903}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 941)
914fn bigcryptor128_decrypt_array_with_padding_iso_ecb_into_array()
915{
916    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb_into_array()");
917    use std::io::Write;
918    use std::fmt::Write as _;
919    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
920
921    // TAES_128 case
922    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
923                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
924                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
925    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
926    println!("IV =	{:#034X}", iv);
927    let message = "In the beginning God created the heavens and the earth.";
928        println!("M =\t{}", message);
929    let mut cipher = [0_u8; 64];
930    taes.encrypt_str_into_array(&message, &mut cipher);
931    print!("C =\t");
932    for c in cipher.clone()
933        { print!("{:02X} ", c); }
934    println!();
935    let mut txt = String::new();
936    for c in cipher.clone()
937        { write!(txt, "{:02X} ", c); }
938    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
939
940    let mut recovered = [0u8; 64];
941    let len = taes.decrypt_array_into_array(&cipher, &mut recovered);
942    print!("Ba =\t");
943    for b in recovered.clone()
944        { print!("{:02X} ", b); }
945    println!();
946    let mut txt = String::new();
947    for c in recovered.clone()
948        { write!(txt, "{:02X} ", c); }
949    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
950
951    let mut converted = String::new();
952    unsafe { converted.as_mut_vec() }.write(&recovered);
953    unsafe { converted.as_mut_vec() }.truncate(len as usize);
954    println!("Bb =\t{}", converted);
955    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
956    assert_eq!(converted, message);
957    println!("-------------------------------");
958}
examples/aes_ecb_iso_examples.rs (line 3865)
3839fn aes_decrypt_array_with_padding_iso_ecb_into_array()
3840{
3841    println!("aes_decrypt_array_with_padding_iso_ecb_into_array()");
3842    use std::io::Write;
3843    use std::fmt::Write as _;
3844    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
3845
3846    // Normal case for AES-128
3847    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
3848    println!("K =\t{:#016X}", key);
3849    let mut a_aes = AES_128::new_with_key_u128(key);
3850
3851    let message = "In the beginning God created the heavens and the earth.";
3852    println!("M =\t{}", message);
3853    let mut cipher = [0_u8; 64];
3854    a_aes.encrypt_str_into_array(&message, &mut cipher);
3855    print!("C =\t");
3856    for c in cipher.clone()
3857        { print!("{:02X} ", c); }
3858    println!();
3859    let mut txt = String::new();
3860    for c in cipher.clone()
3861        { write!(txt, "{:02X} ", c); }
3862    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
3863
3864    let mut recovered = [0; 64];
3865    let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
3866    print!("Ba =\t");
3867    for b in recovered.clone()
3868        { print!("{:02X} ", b); }
3869    println!();
3870    let mut txt = String::new();
3871    for c in recovered.clone()
3872        { write!(txt, "{:02X} ", c); }
3873    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3874
3875    let mut converted = String::new();
3876    unsafe { converted.as_mut_vec() }.write(&recovered);
3877    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3878    println!("Bb =\t{}", converted);
3879    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3880    assert_eq!(converted, message);
3881    println!();
3882
3883    // Normal case for AES-192
3884    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3885    print!("K =\t");
3886    for i in 0..24
3887        { print!("{:02X}", key[i]); }
3888    println!();
3889    let mut a_aes = AES_192::new_with_key(&key);
3890
3891    let message = "In the beginning God created the heavens and the earth.";
3892    println!("M =\t{}", message);
3893    let mut cipher = [0_u8; 64];
3894    a_aes.encrypt_str_into_array(&message, &mut cipher);
3895    print!("C =\t");
3896    for c in cipher.clone()
3897        { print!("{:02X} ", c); }
3898    println!();
3899    let mut txt = String::new();
3900    for c in cipher.clone()
3901        { write!(txt, "{:02X} ", c); }
3902    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
3903
3904    let mut recovered = [0; 64];
3905    let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
3906    print!("Ba =\t");
3907    for b in recovered.clone()
3908        { print!("{:02X} ", b); }
3909    println!();
3910    let mut txt = String::new();
3911    for c in recovered.clone()
3912        { write!(txt, "{:02X} ", c); }
3913    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3914
3915    let mut converted = String::new();
3916    unsafe { converted.as_mut_vec() }.write(&recovered);
3917    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3918    println!("Bb =\t{}", converted);
3919    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3920    assert_eq!(converted, message);
3921    println!();
3922
3923    // Normal case for AES-256
3924    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3925    print!("K =\t");
3926    for i in 0..32
3927        { print!("{:02X}", key[i]); }
3928    println!();
3929    let mut a_aes = AES_256::new_with_key(&key);
3930
3931    let message = "In the beginning God created the heavens and the earth.";
3932    println!("M =\t{}", message);
3933    let mut cipher = [0_u8; 64];
3934    a_aes.encrypt_str_into_array(&message, &mut cipher);
3935    print!("C =\t");
3936    for c in cipher.clone()
3937        { print!("{:02X} ", c); }
3938    println!();
3939    let mut txt = String::new();
3940    for c in cipher.clone()
3941        { write!(txt, "{:02X} ", c); }
3942    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
3943
3944    let mut recovered = [0; 64];
3945    let len = a_aes.decrypt_array_into_array(&cipher, &mut recovered);
3946    print!("Ba =\t");
3947    for b in recovered.clone()
3948        { print!("{:02X} ", b); }
3949    println!();
3950    let mut txt = String::new();
3951    for c in recovered.clone()
3952        { write!(txt, "{:02X} ", c); }
3953    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3954
3955    let mut converted = String::new();
3956    unsafe { converted.as_mut_vec() }.write(&recovered);
3957    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3958    println!("Bb =\t{}", converted);
3959    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3960    assert_eq!(converted, message);
3961    println!();
3962
3963    // Normal case for Rijndael-256-256
3964    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
3965    print!("K =\t");
3966    for i in 0..32
3967        { print!("{:02X}", key[i]); }
3968    println!();
3969    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
3970
3971    let message = "In the beginning God created the heavens and the earth.";
3972    println!("M =\t{}", message);
3973    let mut cipher = [0_u8; 64];
3974    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
3975    print!("C =\t");
3976    for c in cipher.clone()
3977        { print!("{:02X} ", c); }
3978    println!();
3979    let mut txt = String::new();
3980    for c in cipher.clone()
3981        { write!(txt, "{:02X} ", c); }
3982    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
3983
3984    let mut recovered = [0; 64];
3985    let len = a_rijndael.decrypt_array_into_array(&cipher, &mut recovered);
3986    print!("Ba =\t");
3987    for b in recovered.clone()
3988        { print!("{:02X} ", b); }
3989    println!();
3990    let mut txt = String::new();
3991    for c in recovered.clone()
3992        { write!(txt, "{:02X} ", c); }
3993    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
3994
3995    let mut converted = String::new();
3996    unsafe { converted.as_mut_vec() }.write(&recovered);
3997    unsafe { converted.as_mut_vec() }.truncate(len as usize);
3998    println!("Bb =\t{}", converted);
3999    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4000    assert_eq!(converted, message);
4001    println!();
4002
4003    // Normal case for Rijndael-512-512 for post-quantum
4004    use cryptocol::number::SharedArrays;
4005    use cryptocol::hash::SHA3_512;
4006    let mut sha3 = SHA3_512::new();
4007    sha3.absorb_str("Post-quantum");
4008    let key: [u8; 64] = sha3.get_hash_value_in_array();
4009    print!("K =\t");
4010    for i in 0..64
4011        { print!("{:02X}", key[i]); }
4012    println!();
4013    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
4014    let message = "In the beginning God created the heavens and the earth.";
4015    println!("M =\t{}", message);
4016    let mut cipher = [0_u8; 64];
4017    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
4018    print!("C =\t");
4019    for c in cipher.clone()
4020        { print!("{:02X} ", c); }
4021    println!();
4022    let mut txt = String::new();
4023    for c in cipher.clone()
4024        { write!(txt, "{:02X} ", c); }
4025    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
4026
4027    let mut recovered = [0; 64];
4028    let len = a_rijndael.decrypt_array_into_array(&cipher, &mut recovered);
4029    print!("Ba =\t");
4030    for b in recovered.clone()
4031        { print!("{:02X} ", b); }
4032    println!();
4033    let mut txt = String::new();
4034    for c in recovered.clone()
4035        { write!(txt, "{:02X} ", c); }
4036    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 00 00 00 00 00 00 00 00 ");
4037
4038    let mut converted = String::new();
4039    unsafe { converted.as_mut_vec() }.write(&recovered);
4040    unsafe { converted.as_mut_vec() }.truncate(len as usize);
4041    println!("Bb =\t{}", converted);
4042    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4043    assert_eq!(converted, message);
4044    println!("-------------------------------");
4045}
examples/des_ecb_iso_examples.rs (line 5897)
5871fn des_decrypt_array_with_padding_iso_ecb_into_array()
5872{
5873    println!("des_decrypt_array_with_padding_iso_ecb_into_array()");
5874    use std::io::Write;
5875    use std::fmt::Write as _;
5876    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5877
5878    // Normal case
5879    let key = 0x_1234567890ABCDEF_u64;
5880    println!("K =\t{:#016X}", key);
5881    let mut a_des = DES::new_with_key_u64(key);
5882
5883    let message = "In the beginning God created the heavens and the earth.";
5884    println!("M =\t{}", message);
5885    let mut cipher = [0_u8; 56];
5886    a_des.encrypt_str_into_array(&message, &mut cipher);
5887    print!("C (16 rounds) =\t");
5888    for c in cipher.clone()
5889        { print!("{:02X} ", c); }
5890    println!();
5891    let mut txt = String::new();
5892    for c in cipher.clone()
5893        { write!(txt, "{:02X} ", c); }
5894    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5895
5896    let mut recovered = [0u8; 56];
5897    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5898    print!("Ba (16 rounds) =\t");
5899    for b in recovered.clone()
5900        { print!("{:02X} ", b); }
5901    println!();
5902    let mut txt = String::new();
5903    for c in recovered.clone()
5904        { write!(txt, "{:02X} ", c); }
5905    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5906
5907    let mut converted = String::new();
5908    unsafe { converted.as_mut_vec() }.write(&recovered);
5909    unsafe { converted.as_mut_vec() }.truncate(len as usize);
5910    println!("Bb (16 rounds) =\t{}", converted);
5911    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5912    assert_eq!(converted, message);
5913    println!();
5914
5915    // Expanded case for 128 rounds
5916    let key = 0x_1234567890ABCDEF_u64;
5917    println!("K =\t{:#016X}", key);
5918    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5919
5920    let message = "In the beginning God created the heavens and the earth.";
5921    println!("M =\t{}", message);
5922    let mut cipher = [0_u8; 56];
5923    a_des.encrypt_str_into_array(&message, &mut cipher);
5924    print!("C (128 rounds) =\t");
5925    for c in cipher.clone()
5926        { print!("{:02X} ", c); }
5927    println!();
5928    let mut txt = String::new();
5929    for c in cipher.clone()
5930        { write!(txt, "{:02X} ", c); }
5931    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5932
5933    let mut recovered = [0u8; 56];
5934    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5935    print!("Ba (16 rounds) =\t");
5936    for b in recovered.clone()
5937        { print!("{:02X} ", b); }
5938    println!();
5939    let mut txt = String::new();
5940    for c in recovered.clone()
5941        { write!(txt, "{:02X} ", c); }
5942    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5943
5944    let mut converted = String::new();
5945    unsafe { converted.as_mut_vec() }.write(&recovered);
5946    unsafe { converted.as_mut_vec() }.truncate(len as usize);
5947    println!("Bb (16 rounds) =\t{}", converted);
5948    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5949    assert_eq!(converted, message);
5950    println!();
5951
5952    // Expanded case for 0 rounds which means that key is meaningless
5953    let key1 = 0x_1234567890ABCDEF_u64;
5954    let key2 = 0_u64;
5955    println!("K =\t{:#016X}", key);
5956    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5957    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5958
5959    let message = "In the beginning God created the heavens and the earth.";
5960    println!("M =\t{}", message);
5961    let mut cipher1 = [0_u8; 56];
5962    let mut cipher2 = [0_u8; 56];
5963    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5964    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5965    print!("C (0 rounds) =\t");
5966    for c in cipher1.clone()
5967        { print!("{:02X} ", c); }
5968    println!();
5969    let mut txt = String::new();
5970    for c in cipher1.clone()
5971        { write!(txt, "{:02X} ", c); }
5972    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5973    print!("D (0 rounds) =\t");
5974    for c in cipher2.clone()
5975        { print!("{:02X} ", c); }
5976    println!();
5977    let mut txt = String::new();
5978    for c in cipher2.clone()
5979        { write!(txt, "{:02X} ", c); }
5980    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5981
5982    let mut recovered1 = [0u8; 56];
5983    let mut recovered2 = [0u8; 56];
5984    let len1 = c_des.decrypt_array_into_array(&cipher1, &mut recovered1);
5985    let len2 = d_des.decrypt_array_into_array(&cipher2, &mut recovered2);
5986    print!("B1a (0 rounds) =\t");
5987    for b in recovered1.clone()
5988        { print!("{:02X} ", b); }
5989    println!();
5990    let mut txt = String::new();
5991    for c in recovered1.clone()
5992        { write!(txt, "{:02X} ", c); }
5993    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5994    print!("B2a (0 rounds) =\t");
5995    for b in recovered2.clone()
5996        { print!("{:02X} ", b); }
5997    println!();
5998    let mut txt = String::new();
5999    for c in recovered.clone()
6000        { write!(txt, "{:02X} ", c); }
6001    assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6002
6003    let mut converted1 = String::new();
6004    let mut converted2 = String::new();
6005    unsafe { converted1.as_mut_vec() }.write(&recovered1);
6006    unsafe { converted2.as_mut_vec() }.write(&recovered2);
6007    unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6008    unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6009    println!("B1b (0 rounds) =\t{}", converted1);
6010    println!("B2b (0 rounds) =\t{}", converted2);
6011    assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6012    assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6013    assert_eq!(converted1, message);
6014    assert_eq!(converted2, message);
6015    assert_eq!(converted1, converted2);
6016    println!();
6017
6018    // Normal case for the message of 0 bytes
6019    let key = 0x_1234567890ABCDEF_u64;
6020    println!("K =\t{:#016X}", key);
6021    let mut a_des = DES::new_with_key_u64(key);
6022
6023    let message = "";
6024    println!("M =\t{}", message);
6025    let mut cipher = [0_u8; 8];
6026    a_des.encrypt_str_into_array(&message, &mut cipher);
6027    print!("C =\t");
6028    for c in cipher.clone()
6029        { print!("{:02X} ", c); }
6030    println!();
6031    let mut txt = String::new();
6032    for c in cipher.clone()
6033        { write!(txt, "{:02X} ", c); }
6034    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
6035
6036    let mut recovered = [0u8; 8];
6037    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6038
6039    print!("Ba =\t");
6040    for b in recovered.clone()
6041        { print!("{:02X} ", b); }
6042    println!();
6043    let mut txt = String::new();
6044    for c in recovered.clone()
6045        { write!(txt, "{:02X} ", c); }
6046    assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6047
6048    let mut converted = String::new();
6049    unsafe { converted.as_mut_vec() }.write(&recovered);
6050    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6051    println!("Bb =\t{}", converted);
6052    assert_eq!(converted, "");
6053    assert_eq!(converted, message);
6054    println!();
6055
6056    // Normal case for the message shorter than 8 bytes
6057    let key = 0x_1234567890ABCDEF_u64;
6058    println!("K =\t{:#016X}", key);
6059    let mut a_des = DES::new_with_key_u64(key);
6060
6061    let message = "7 bytes";
6062    println!("M =\t{}", message);
6063    let mut cipher = [0_u8; 8];
6064    a_des.encrypt_str_into_array(&message, &mut cipher);
6065    print!("C =\t");
6066    for c in cipher.clone()
6067        { print!("{:02X} ", c); }
6068    println!();
6069    let mut txt = String::new();
6070    for c in cipher.clone()
6071        { write!(txt, "{:02X} ", c); }
6072    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
6073
6074    let mut recovered = [0u8; 8];
6075    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6076
6077    print!("Ba =\t");
6078    for b in recovered.clone()
6079        { print!("{:02X} ", b); }
6080    println!();
6081    let mut txt = String::new();
6082    for c in recovered.clone()
6083        { write!(txt, "{:02X} ", c); }
6084    assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6085
6086    let mut converted = String::new();
6087    unsafe { converted.as_mut_vec() }.write(&recovered);
6088    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6089    println!("Bb =\t{}", converted);
6090    assert_eq!(converted, "7 bytes");
6091    assert_eq!(converted, message);
6092    println!();
6093
6094    // Normal case for the message of 8 bytes
6095    let key = 0x_1234567890ABCDEF_u64;
6096    println!("K =\t{:#016X}", key);
6097    let mut a_des = DES::new_with_key_u64(key);
6098
6099    let message = "I am OK.";
6100    println!("M =\t{}", message);
6101    let mut cipher = [0_u8; 16];
6102    a_des.encrypt_str_into_array(&message, &mut cipher);
6103    print!("C =\t");
6104    for c in cipher.clone()
6105        { print!("{:02X} ", c); }
6106    println!();
6107    let mut txt = String::new();
6108    for c in cipher.clone()
6109        { write!(txt, "{:02X} ", c); }
6110    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
6111
6112    let mut recovered = [0u8; 16];
6113    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6114
6115    print!("Ba =\t");
6116    for b in recovered.clone()
6117        { print!("{:02X} ", b); }
6118    println!();
6119    let mut txt = String::new();
6120    for c in recovered.clone()
6121        { write!(txt, "{:02X} ", c); }
6122    assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6123
6124    let mut converted = String::new();
6125    unsafe { converted.as_mut_vec() }.write(&recovered);
6126    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6127    println!("Bb =\t{}", converted);
6128    assert_eq!(converted, "I am OK.");
6129    assert_eq!(converted, message);
6130    println!();
6131
6132    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6133    let key = 0x_1234567890ABCDEF_u64;
6134    println!("K =\t{:#016X}", key);
6135    let mut a_des = DES::new_with_key_u64(key);
6136
6137    let message = "PARK Youngho";
6138    println!("M =\t{}", message);
6139    let mut cipher = [0_u8; 16];
6140    a_des.encrypt_str_into_array(&message, &mut cipher);
6141    print!("C =\t");
6142    for c in cipher.clone()
6143        { print!("{:02X} ", c); }
6144    println!();
6145    let mut txt = String::new();
6146    for c in cipher.clone()
6147        { write!(txt, "{:02X} ", c); }
6148    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
6149
6150    let mut recovered = [0u8; 16];
6151    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6152
6153    print!("Ba =\t");
6154    for b in recovered.clone()
6155        { print!("{:02X} ", b); }
6156    println!();
6157    let mut txt = String::new();
6158    for c in recovered.clone()
6159        { write!(txt, "{:02X} ", c); }
6160    assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6161
6162    let mut converted = String::new();
6163    unsafe { converted.as_mut_vec() }.write(&recovered);
6164    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6165    println!("Bb =\t{}", converted);
6166    assert_eq!(converted, "PARK Youngho");
6167    assert_eq!(converted, message);
6168    println!();
6169
6170    // Normal case for the message of 16 bytes
6171    let key = 0x_1234567890ABCDEF_u64;
6172    println!("K =\t{:#016X}", key);
6173    let mut a_des = DES::new_with_key_u64(key);
6174
6175    let message = "고맙습니다.";
6176    println!("M =\t{}", message);
6177    let mut cipher = [0_u8; 24];
6178    a_des.encrypt_str_into_array(&message, &mut cipher);
6179    print!("C =\t");
6180    for c in cipher.clone()
6181        { print!("{:02X} ", c); }
6182    println!();
6183    let mut txt = String::new();
6184    for c in cipher.clone()
6185        { write!(txt, "{:02X} ", c); }
6186    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
6187
6188    let mut recovered = [0u8; 24];
6189    let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6190
6191    print!("Ba =\t");
6192    for b in recovered.clone()
6193        { print!("{:02X} ", b); }
6194    println!();
6195    let mut txt = String::new();
6196    for c in recovered.clone()
6197        { write!(txt, "{:02X} ", c); }
6198    assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6199
6200    let mut converted = String::new();
6201    unsafe { converted.as_mut_vec() }.write(&recovered);
6202    unsafe { converted.as_mut_vec() }.truncate(len as usize);
6203    println!("Bb =\t{}", converted);
6204    assert_eq!(converted, "고맙습니다.");
6205    assert_eq!(converted, message);
6206    println!("-------------------------------");
6207}
Source

fn decrypt_array_into_string<U, const N: usize>( &mut self, cipher: &[U; N], message: &mut String, ) -> u64
where U: SmallUInt + Copy + Clone,

Decrypts the data stored in an array [U; N] object with the padding defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the decrypted data in String.

§Arguments
  • cipher is an immutable reference to an array [U; N] object, and is the place where the plaintext to be decrypted is stored.
  • message is a mutable reference to a String object, and is the place where the decrypted data will be stored.
§Output
  • This method returns the size of plaintext in bytes.
  • If this method failed in decryption, it always returns zero.
  • Even if this method succeeded in decryption, it returns zero when the original plaintext is zero-length empty data. Then, you will have to check whether or not it failed by using the method is_successful() or is_failed().
  • If size_of::<U>() * N is greater than size_of::<T>() (which means that the original plaintext is surely not empty data) and it returns zero, you can interpret it that this method surely failed in decryption.
§Features
  • The padding bits are composed of the byte 0b_1000_0000 that indicates the delimiter one bit 1 followed by seven bits 0s and all padding bits 0s according to ISO 7816-4.
  • For more information about the padding bits according to ISO 7816-4, Read here.
  • You don’t have to worry about whether or not the size of the memory area where the ciphertext will be stored is enough.
  • This method assumes that the original plaintext is a string in the format of UTF-8.
§For Rijndael or AES, and its variants
§Example 1 for AES-128
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ AES_128, ECB_ISO };
 
let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
println!("K =\t{:#016X}", key);
let mut a_aes = AES_128::new_with_key_u128(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
a_aes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
 
let mut converted= String::new();
a_aes.decrypt_array_into_string(&cipher, &mut converted);
println!("B =\t{}", converted);
assert_eq!(converted, "In the beginning God created the heavens and the earth.");
assert_eq!(converted, message);
§For more examples,

click here

§For DES and its variants
§Example 1 for Normal case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_ISO };
 
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#016X}", key);
let mut a_des = DES::new_with_key_u64(key);
 
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 56];
a_des.encrypt_str_into_array(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
 
let mut recovered = String::new();
a_des.decrypt_array_into_string(&cipher, &mut recovered);
println!("B (16 rounds) =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

§For BigCryptor128
§Example 1 for TAES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
 
let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
                + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
                + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let mut cipher = [0_u8; 64];
taes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
 
let mut recovered = String::new();
taes.decrypt_array_into_string(&cipher, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

§For BigCryptor64
§Example 1 for TDES case
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
 
let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
                + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
                + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
tdes.encrypt_str_into_array(&message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
    { print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
    { write!(txt, "{:02X} ", c); }
assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
 
let mut recovered = String::new();
tdes.decrypt_array_into_string(&cipher, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
§For more examples,

click here

Examples found in repository?
examples/bigcryptor64_ecb_iso_examples.rs (line 929)
905fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()
906{
907    println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()");
908    use std::io::Write;
909    use std::fmt::Write as _;
910    use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
911
912    // TDES case
913    let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
914                    + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
915                    + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
916    let message = "In the beginning God created the heavens and the earth.";
917    println!("M =\t{}", message);    let mut cipher = [0_u8; 56];
918    tdes.encrypt_str_into_array(&message, &mut cipher);
919    print!("C =\t");
920    for c in cipher.clone()
921        { print!("{:02X} ", c); }
922    println!();
923    let mut txt = String::new();
924    for c in cipher.clone()
925        { write!(txt, "{:02X} ", c); }
926    assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
927
928    let mut recovered = String::new();
929    tdes.decrypt_array_into_string(&cipher, &mut recovered);
930    println!("B =\t{}", recovered);
931    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
932    assert_eq!(recovered, message);
933    println!("-------------------------------");
934}
More examples
Hide additional examples
examples/bigcryptor128_ecb_iso_examples.rs (line 987)
960fn bigcryptor128_decrypt_array_with_padding_iso_ecb_into_string()
961{
962    println!("bigcryptor128_decrypt_array_with_padding_iso_ecb_into_string()");
963    use std::io::Write;
964    use std::fmt::Write as _;
965    use cryptocol::symmetric::{ BigCryptor128, AES_128, ECB_ISO };
966
967    // TAES_128 case
968    let mut taes = AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128)
969                    + AES_128::decryptor_with_key_u128(0x_FEDCBA09876543211234567890ABCDEF_u128)
970                    + AES_128::encryptor_with_key_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
971    let iv = 0x_FEDCBA09876543211234567890ABCDEF_u128;
972    println!("IV =	{:#034X}", iv);
973    let message = "In the beginning God created the heavens and the earth.";
974    println!("M =\t{}", message);
975    let mut cipher = [0_u8; 64];
976    taes.encrypt_str_into_array(&message, &mut cipher);
977    print!("C =\t");
978    for c in cipher.clone()
979        { print!("{:02X} ", c); }
980    println!();
981    let mut txt = String::new();
982    for c in cipher.clone()
983        { write!(txt, "{:02X} ", c); }
984    assert_eq!(txt, "5A 29 46 8D EE CE 8C C2 03 FE 08 AE 41 30 82 7A 03 BF 55 05 02 AE C0 4A 70 12 31 0E F6 8F 86 28 2B F9 0C 3F F4 84 D9 C9 3A 6B 68 4D E2 A3 DC F7 6A 69 FF 82 0D 05 27 DE 71 08 68 BD 1A BC E9 EE ");
985
986    let mut recovered = String::new();
987    taes.decrypt_array_into_string(&cipher, &mut recovered);
988    println!("B =\t{}", recovered);
989    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
990    assert_eq!(recovered, message);
991    println!("-------------------------------");
992}
examples/aes_ecb_iso_examples.rs (line 4073)
4047fn aes_decrypt_array_with_padding_iso_ecb_into_string()
4048{
4049    println!("aes_decrypt_array_with_padding_iso_ecb_into_string()");
4050    use std::io::Write;
4051    use std::fmt::Write as _;
4052    use cryptocol::symmetric::{ AES_128, AES_192, AES_256, Rijndael_256_256, Rijndael_512_512, ECB_ISO };
4053
4054    // Normal case for AES-128
4055    let key = 0x_1234567890ABCDEF1234567890ABCDEF_u128;
4056    println!("K =\t{:#016X}", key);
4057    let mut a_aes = AES_128::new_with_key_u128(key);
4058
4059    let message = "In the beginning God created the heavens and the earth.";
4060    println!("M =\t{}", message);
4061    let mut cipher = [0_u8; 64];
4062    a_aes.encrypt_str_into_array(&message, &mut cipher);
4063    print!("C =\t");
4064    for c in cipher.clone()
4065        { print!("{:02X} ", c); }
4066    println!();
4067    let mut txt = String::new();
4068    for c in cipher.clone()
4069        { write!(txt, "{:02X} ", c); }
4070    assert_eq!(txt, "E8 96 2E 8D BA 45 C6 D9 45 06 DC 98 D9 2F 1F 86 B8 05 A9 B8 D2 B2 1E 82 DA 51 DA B1 F9 81 B7 B3 95 C5 46 72 A8 D9 D8 B0 9E 62 AB 4F F8 36 31 54 3F C4 ED AB CE EE B1 9A FF 05 29 FF 65 BD 25 93 ");
4071
4072    let mut converted= String::new();
4073    a_aes.decrypt_array_into_string(&cipher, &mut converted);
4074    println!("B =\t{}", converted);
4075    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4076    assert_eq!(converted, message);
4077    println!();
4078
4079    // Normal case for AES-192
4080    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
4081    print!("K =\t");
4082    for i in 0..24
4083        { print!("{:02X}", key[i]); }
4084    println!();
4085    let mut a_aes = AES_192::new_with_key(&key);
4086
4087    let message = "In the beginning God created the heavens and the earth.";
4088    println!("M =\t{}", message);
4089    let mut cipher = [0_u8; 64];
4090    a_aes.encrypt_str_into_array(&message, &mut cipher);
4091    print!("C =\t");
4092    for c in cipher.clone()
4093        { print!("{:02X} ", c); }
4094    println!();
4095    let mut txt = String::new();
4096    for c in cipher.clone()
4097        { write!(txt, "{:02X} ", c); }
4098    assert_eq!(txt, "F2 8F C2 CA 9D 3A AC 96 69 7B 52 0D 5F CB 10 4B 31 26 61 63 CE A4 EB 2B EE 9F C3 4C A1 40 F4 FF 0F 70 8E 7C 6F 42 BC 93 4F CF DA 45 BB F6 6F 6B 70 E3 6D 5B F7 85 2D BD FB 3B BE E3 6E A3 56 25 ");
4099
4100    let mut converted= String::new();
4101    a_aes.decrypt_array_into_string(&cipher, &mut converted);
4102    println!("B =\t{}", converted);
4103    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4104    assert_eq!(converted, message);
4105    println!();
4106
4107    // Normal case for AES-256
4108    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
4109    print!("K =\t");
4110    for i in 0..32
4111        { print!("{:02X}", key[i]); }
4112    println!();
4113    let mut a_aes = AES_256::new_with_key(&key);
4114
4115    let message = "In the beginning God created the heavens and the earth.";
4116    println!("M =\t{}", message);
4117    let mut cipher = [0_u8; 64];
4118    a_aes.encrypt_str_into_array(&message, &mut cipher);
4119    print!("C =\t");
4120    for c in cipher.clone()
4121        { print!("{:02X} ", c); }
4122    println!();
4123    let mut txt = String::new();
4124    for c in cipher.clone()
4125        { write!(txt, "{:02X} ", c); }
4126    assert_eq!(txt, "09 74 04 A7 68 1F 4D 00 ED CA 85 39 90 0E A1 AC E1 AC 90 60 D8 C9 BC AB ED 8D 66 89 3F 85 2B 86 3E CE 84 00 57 F2 B9 14 43 FB DD D9 19 70 46 25 BE 7B 8D 4A 52 E8 03 1D 63 0D 5E F1 82 3A 28 A3 ");
4127
4128    let mut converted= String::new();
4129    a_aes.decrypt_array_into_string(&cipher, &mut converted);
4130    println!("B =\t{}", converted);
4131    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4132    assert_eq!(converted, message);
4133    println!();
4134
4135    // Normal case for Rijndael-256-256
4136    let key = [0x12_u8, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
4137    print!("K =\t");
4138    for i in 0..32
4139        { print!("{:02X}", key[i]); }
4140    println!();
4141    let mut a_rijndael = Rijndael_256_256::new_with_key(&key);
4142
4143    let message = "In the beginning God created the heavens and the earth.";
4144    println!("M =\t{}", message);
4145    let mut cipher = [0_u8; 64];
4146    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
4147    print!("C =\t");
4148    for c in cipher.clone()
4149        { print!("{:02X} ", c); }
4150    println!();
4151    let mut txt = String::new();
4152    for c in cipher.clone()
4153        { write!(txt, "{:02X} ", c); }
4154    assert_eq!(txt, "9A 05 BF D4 01 B1 D9 A1 31 C5 13 A9 D1 50 83 C6 E4 F7 B9 40 E2 29 59 E2 42 96 3A DC 22 65 88 F7 53 E1 83 F5 55 E5 86 3E 21 C8 DF DE C8 9C 06 C5 41 DE 7C 88 FE E8 F3 A0 64 8B 52 DA 99 D9 BF F6 ");
4155
4156    let mut converted= String::new();
4157    a_rijndael.decrypt_array_into_string(&cipher, &mut converted);
4158    println!("B =\t{}", converted);
4159    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4160    assert_eq!(converted, message);
4161    println!();
4162
4163    // Normal case for Rijndael-512-512 for post-quantum
4164    use cryptocol::number::SharedArrays;
4165    use cryptocol::hash::SHA3_512;
4166    let mut sha3 = SHA3_512::new();
4167    sha3.absorb_str("Post-quantum");
4168    let key: [u8; 64] = sha3.get_hash_value_in_array();
4169    print!("K =\t");
4170    for i in 0..64
4171        { print!("{:02X}", key[i]); }
4172    println!();
4173    let mut a_rijndael = Rijndael_512_512::new_with_key(&key);
4174    let message = "In the beginning God created the heavens and the earth.";
4175    println!("M =\t{}", message);
4176    let mut cipher = [0_u8; 64];
4177    a_rijndael.encrypt_str_into_array(&message, &mut cipher);
4178    print!("C =\t");
4179    for c in cipher.clone()
4180        { print!("{:02X} ", c); }
4181    println!();
4182    let mut txt = String::new();
4183    for c in cipher.clone()
4184        { write!(txt, "{:02X} ", c); }
4185    assert_eq!(txt, "F8 B7 BD C0 65 7B DC D8 7F 90 FC 2E 6B A6 D9 8C A7 0A D5 CF 9A 2D A4 99 4C 86 1F 67 56 88 2C E7 06 6C F2 95 FE 9E AF BF 9F 73 88 70 C7 A5 84 3F 82 27 76 C8 B7 CC 3B 44 07 CD AD F5 72 8E 73 72 ");
4186
4187    let mut converted= String::new();
4188    a_rijndael.decrypt_array_into_string(&cipher, &mut converted);
4189    println!("B =\t{}", converted);
4190    assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4191    assert_eq!(converted, message);
4192    println!("-------------------------------");
4193}
examples/des_ecb_iso_examples.rs (line 6235)
6209fn des_decrypt_array_with_padding_iso_ecb_into_string()
6210{
6211    println!("des_decrypt_array_with_padding_iso_ecb_into_string()");
6212    use std::io::Write;
6213    use std::fmt::Write as _;
6214    use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
6215
6216    // Normal case
6217    let key = 0x_1234567890ABCDEF_u64;
6218    println!("K =\t{:#016X}", key);
6219    let mut a_des = DES::new_with_key_u64(key);
6220
6221    let message = "In the beginning God created the heavens and the earth.";
6222    println!("M =\t{}", message);
6223    let mut cipher = [0_u8; 56];
6224    a_des.encrypt_str_into_array(&message, &mut cipher);
6225    print!("C (16 rounds) =\t");
6226    for c in cipher.clone()
6227        { print!("{:02X} ", c); }
6228    println!();
6229    let mut txt = String::new();
6230    for c in cipher.clone()
6231        { write!(txt, "{:02X} ", c); }
6232    assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
6233
6234    let mut recovered = String::new();
6235    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6236    println!("B (16 rounds) =\t{}", recovered);
6237    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6238    assert_eq!(recovered, message);
6239    println!();
6240
6241    // Expanded case for 128 rounds
6242    let key = 0x_1234567890ABCDEF_u64;
6243    println!("K =\t{:#016X}", key);
6244    let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6245
6246    let message = "In the beginning God created the heavens and the earth.";
6247    println!("M =\t{}", message);
6248    let mut cipher = [0_u8; 56];
6249    a_des.encrypt_str_into_array(&message, &mut cipher);
6250    print!("C (128 rounds) =\t");
6251    for c in cipher.clone()
6252        { print!("{:02X} ", c); }
6253    println!();
6254    let mut txt = String::new();
6255    for c in cipher.clone()
6256        { write!(txt, "{:02X} ", c); }
6257    assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
6258
6259    let mut recovered = String::new();
6260    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6261    println!("B (128 rounds) =\t{}", recovered);
6262    assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6263    assert_eq!(recovered, message);
6264    println!();
6265
6266    // Expanded case for 0 rounds which means that key is meaningless
6267    let key1 = 0x_1234567890ABCDEF_u64;
6268    let key2 = 0_u64;
6269    println!("K =\t{:#016X}", key);
6270    let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6271    let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6272
6273    let message = "In the beginning God created the heavens and the earth.";
6274    println!("M =\t{}", message);
6275    let mut cipher1 = [0_u8; 56];
6276    let mut cipher2 = [0_u8; 56];
6277    c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
6278    d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
6279    print!("C (0 rounds) =\t");
6280    for c in cipher1.clone()
6281        { print!("{:02X} ", c); }
6282    println!();
6283    let mut txt = String::new();
6284    for c in cipher1.clone()
6285        { write!(txt, "{:02X} ", c); }
6286    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
6287    print!("D (0 rounds) =\t");
6288    for c in cipher2.clone()
6289        { print!("{:02X} ", c); }
6290    println!();
6291    let mut txt = String::new();
6292    for c in cipher2.clone()
6293        { write!(txt, "{:02X} ", c); }
6294    assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
6295
6296    let mut recovered1 = String::new();
6297    let mut recovered2 = String::new();
6298    c_des.decrypt_array_into_string(&cipher1, &mut recovered1);
6299    d_des.decrypt_array_into_string(&cipher2, &mut recovered2);
6300    println!("B1 (0 rounds) =\t{}", recovered1);
6301    println!("B2 (0 rounds) =\t{}", recovered2);
6302    assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6303    assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6304    assert_eq!(recovered1, message);
6305    assert_eq!(recovered2, message);
6306    assert_eq!(recovered1, recovered2);
6307    println!();
6308
6309    // Normal case for the message of 0 bytes
6310    let key = 0x_1234567890ABCDEF_u64;
6311    println!("K =\t{:#016X}", key);
6312    let mut a_des = DES::new_with_key_u64(key);
6313
6314    let message = "";
6315    println!("M =\t{}", message);
6316    let mut cipher = [0_u8; 8];
6317    a_des.encrypt_str_into_array(&message, &mut cipher);
6318    print!("C =\t");
6319    for c in cipher.clone()
6320        { print!("{:02X} ", c); }
6321    println!();
6322    let mut txt = String::new();
6323    for c in cipher.clone()
6324        { write!(txt, "{:02X} ", c); }
6325    assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
6326
6327    let mut recovered = String::new();
6328    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6329    println!("B =\t{}", recovered);
6330    assert_eq!(recovered, "");
6331    assert_eq!(recovered, message);
6332    println!();
6333
6334    // Normal case for the message shorter than 8 bytes
6335    let key = 0x_1234567890ABCDEF_u64;
6336    println!("K =\t{:#016X}", key);
6337    let mut a_des = DES::new_with_key_u64(key);
6338
6339    let message = "7 bytes";
6340    println!("M =\t{}", message);
6341    let mut cipher = [0_u8; 8];
6342    a_des.encrypt_str_into_array(&message, &mut cipher);
6343    print!("C =\t");
6344    for c in cipher.clone()
6345        { print!("{:02X} ", c); }
6346    println!();
6347    let mut txt = String::new();
6348    for c in cipher.clone()
6349        { write!(txt, "{:02X} ", c); }
6350    assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
6351
6352    let mut recovered = String::new();
6353    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6354    println!("B =\t{}", recovered);
6355    assert_eq!(recovered, "7 bytes");
6356    assert_eq!(recovered, message);
6357    println!();
6358
6359    // Normal case for the message of 8 bytes
6360    let key = 0x_1234567890ABCDEF_u64;
6361    println!("K =\t{:#016X}", key);
6362    let mut a_des = DES::new_with_key_u64(key);
6363
6364    let message = "I am OK.";
6365    println!("M =\t{}", message);
6366    let mut cipher = [0_u8; 16];
6367    a_des.encrypt_str_into_array(&message, &mut cipher);
6368    print!("C =\t");
6369    for c in cipher.clone()
6370        { print!("{:02X} ", c); }
6371    println!();
6372    let mut txt = String::new();
6373    for c in cipher.clone()
6374        { write!(txt, "{:02X} ", c); }
6375    assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
6376
6377    let mut recovered = String::new();
6378    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6379    println!("B =\t{}", recovered);
6380    assert_eq!(recovered, "I am OK.");
6381    assert_eq!(recovered, message);
6382    println!();
6383
6384    // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6385    let key = 0x_1234567890ABCDEF_u64;
6386    println!("K =\t{:#016X}", key);
6387    let mut a_des = DES::new_with_key_u64(key);
6388
6389    let message = "PARK Youngho";
6390    println!("M =\t{}", message);
6391    let mut cipher = [0_u8; 16];
6392    a_des.encrypt_str_into_array(&message, &mut cipher);
6393    print!("C =\t");
6394    for c in cipher.clone()
6395        { print!("{:02X} ", c); }
6396    println!();
6397    let mut txt = String::new();
6398    for c in cipher.clone()
6399        { write!(txt, "{:02X} ", c); }
6400    assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
6401
6402    let mut recovered = String::new();
6403    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6404    println!("B =\t{}", recovered);
6405    assert_eq!(recovered, "PARK Youngho");
6406    assert_eq!(recovered, message);
6407    println!();
6408
6409    // Normal case for the message of 16 bytes
6410    let key = 0x_1234567890ABCDEF_u64;
6411    println!("K =\t{:#016X}", key);
6412    let mut a_des = DES::new_with_key_u64(key);
6413
6414    let message = "고맙습니다.";
6415    println!("M =\t{}", message);
6416    let mut cipher = [0_u8; 24];
6417    a_des.encrypt_str_into_array(&message, &mut cipher);
6418    print!("C =\t");
6419    for c in cipher.clone()
6420        { print!("{:02X} ", c); }
6421    println!();
6422    let mut txt = String::new();
6423    for c in cipher.clone()
6424        { write!(txt, "{:02X} ", c); }
6425    assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
6426
6427    let mut recovered = String::new();
6428    a_des.decrypt_array_into_string(&cipher, &mut recovered);
6429    println!("B =\t{}", recovered);
6430    assert_eq!(recovered, "고맙습니다.");
6431    assert_eq!(recovered, message);
6432    println!("-------------------------------");
6433}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ECB_ISO<u64> for BigCryptor64

Source§

impl ECB_ISO<u128> for BigCryptor128

Source§

impl<const ROUND: usize, const NB: usize, const NK: usize, const IRREDUCIBLE: u8, const AFFINE_MUL: u64, const AFFINE_ADD: u8, const SR0: usize, const SR1: usize, const SR2: usize, const SR3: usize, const MC00: u8, const MC01: u8, const MC02: u8, const MC03: u8, const MC10: u8, const MC11: u8, const MC12: u8, const MC13: u8, const MC20: u8, const MC21: u8, const MC22: u8, const MC23: u8, const MC30: u8, const MC31: u8, const MC32: u8, const MC33: u8, const RC0: u32, const RC1: u32, const RC2: u32, const RC3: u32, const RC4: u32, const RC5: u32, const RC6: u32, const RC7: u32, const RC8: u32, const RC9: u32, const ROT: u32> ECB_ISO<[u32; NB]> for Rijndael_Generic<ROUND, NB, NK, IRREDUCIBLE, AFFINE_MUL, AFFINE_ADD, SR0, SR1, SR2, SR3, MC00, MC01, MC02, MC03, MC10, MC11, MC12, MC13, MC20, MC21, MC22, MC23, MC30, MC31, MC32, MC33, RC0, RC1, RC2, RC3, RC4, RC5, RC6, RC7, RC8, RC9, ROT>

Source§

impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> ECB_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>