1#![allow(missing_docs)]
10#![allow(unused_must_use)]
11#![allow(dead_code)]
12#![allow(unused_imports)]
13#![allow(non_snake_case)]
14
15
16pub fn main()
17{
18 bigcryptor64_quick_start_main();
19 bigcryptor64_basic_operation_main();
20 tdes_quick_start_main();
21 ddes_quick_start_main();
22}
23
24fn bigcryptor64_quick_start_main()
25{
26 bigcryptor64_import_modules();
27 bigcryptor64_instantiation_with_keys_u64();
28 bigcryptor64_instantiation_with_keys();
29 bigcryptor64_set_keys_u64_later();
30 bigcryptor64_set_keys_later();
31 bigcryptor64_cbc_pkcs7();
32}
33
34fn bigcryptor64_import_modules()
35{
36 println!("bigcryptor64_import_modules()");
37
38 use cryptocol::symmetric::BigCryptor64;
39
40 println!("-------------------------------");
41}
42
43fn bigcryptor64_instantiation_with_keys_u64()
44{
45 println!("bigcryptor64_instantiation_with_keys_u64()");
46 use cryptocol::symmetric::{ BigCryptor64, DES };
47 let mut _tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
48 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
49 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
50 println!("-------------------------------");
51}
52
53fn bigcryptor64_instantiation_with_keys()
54{
55 println!("bigcryptor64_instantiation_with_keys()");
56 use cryptocol::symmetric::{ BigCryptor64, DES };
57 let mut _tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
58 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
59 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
60 println!("-------------------------------");
61}
62
63fn bigcryptor64_set_keys_u64_later()
64{
65 println!("bigcryptor64_instantiation_with_keys_u64()");
66 use cryptocol::symmetric::{ BigCryptor64, DES };
67 let mut tdes = BigCryptor64::new();
68 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
69 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
70 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
71 tdes.push_small_cryptor(des1);
72 tdes.push_small_cryptor(des2);
73 tdes.push_small_cryptor(des3);
74 println!("-------------------------------");
75}
76
77fn bigcryptor64_set_keys_later()
78{
79 println!("bigcryptor64_instantiation_with_keys()");
80 use cryptocol::symmetric::{ BigCryptor64, DES };
81 let mut tdes = BigCryptor64::new();
82 let des1 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
83 let des2 = DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]);
84 let des3 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
85 tdes.push_small_cryptor(des1);
86 tdes.push_small_cryptor(des2);
87 tdes.push_small_cryptor(des3);
88 println!("-------------------------------");
89}
90
91fn bigcryptor64_cbc_pkcs7()
92{
93 println!("bigcryptor64_cbc_pkcs7()");
94 use std::fmt::Write as _;
95 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
96 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
97 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
98 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
99
100 let iv = 0x_FEDCBA0987654321_u64;
101 println!("IV = {:#018X}", iv);
102 let message = "In the beginning God created the heavens and the earth.";
103 println!("M =\t{}", message);
104 let mut cipher = Vec::<u8>::new();
105 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
106 print!("C =\t");
107 for c in cipher.clone()
108 { print!("{:02X} ", c); }
109 println!();
110 let mut txt = String::new();
111 for c in cipher.clone()
112 { write!(txt, "{:02X} ", c); }
113 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
114
115 let mut recovered = String::new();
116 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
117 println!("B =\t{}", recovered);
118 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
119 assert_eq!(recovered, message);
120 println!("-------------------------------");
121}
122
123fn bigcryptor64_basic_operation_main()
124{
125 bigcryptor64_new();
126 bigcryptor64_new_with_small_cryptor_array();
127 bigcryptor64_new_with_small_cryptor_vec();
128 bigcryptor64_push_small_cryptor();
129 bigcryptor64_push_small_cryptor_array();
130 bigcryptor64_push_small_cryptor_vec();
131 bigcryptor64_turn_inverse();
132 bigcryptor64_turn_encryptor();
133 bigcryptor64_turn_decryptor();
134 bigcryptor64_encrypt_u64();
135 bigcryptor64_decrypt_u64();
136 bigcryptor64_encrypt_array_u64();
137 bigcryptor64_decrypt_array_u64();
138 bigcryptor64_is_successful();
139 bigcryptor64_is_failed();
140}
141
142fn bigcryptor64_new()
143{
144 println!("bigcryptor64_new()");
145 use cryptocol::symmetric::{ BigCryptor64, DES };
146
147 let mut tdes = BigCryptor64::new();
149 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
150 tdes.push_small_cryptor(DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]));
151 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
152
153 let mut _tdes = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
155 + DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
156 + DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
157 println!("-------------------------------");
158}
159
160fn bigcryptor64_new_with_small_cryptor_array()
161{
162 println!("bigcryptor64_new_with_small_cryptor_array()");
163 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
164
165 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
167 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
168 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
169 let mut _tdes = BigCryptor64::new_with_small_cryptor_array(cryptors);
170 println!("-------------------------------");
171}
172
173fn bigcryptor64_new_with_small_cryptor_vec()
174{
175 println!("bigcryptor64_new_with_small_cryptor_vec()");
176 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
177
178 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
180 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
181 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
182 let mut _tdes = BigCryptor64::new_with_small_cryptor_vec(cryptors);
183 println!("-------------------------------");
184}
185
186fn bigcryptor64_push_small_cryptor()
187{
188 println!("bigcryptor64_new_with_small_cryptor_vec()");
189 use cryptocol::symmetric::{ BigCryptor64, DES };
190
191 let mut tdes = BigCryptor64::new();
193 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
195 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
196 tdes.push_small_cryptor(des1);
197 tdes.push_small_cryptor(des2);
198 tdes.push_small_cryptor(des3);
199 println!("-------------------------------");
200}
201
202fn bigcryptor64_push_small_cryptor_array()
203{
204 println!("bigcryptor64_push_small_cryptor_array()");
205 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
206
207 let mut tdes = BigCryptor64::new();
209 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
210 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
211 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
212 tdes.push_small_cryptor_array(cryptors);
213 println!("-------------------------------");
214}
215
216fn bigcryptor64_push_small_cryptor_vec()
217{
218 println!("bigcryptor64_push_small_cryptor_vec()");
219 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
220
221 let mut tdes = BigCryptor64::new();
223 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
224 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
225 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
226 tdes.push_small_cryptor_vec(cryptors);
227 println!("-------------------------------");
228}
229
230fn bigcryptor64_turn_inverse()
231{
232 println!("bigcryptor64_turn_inverse");
233 use cryptocol::symmetric::{ BigCryptor64, DES, Rijndael_64_64, SmallCryptor };
234 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
235 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
236 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
237 let des = DES::new_with_key([0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
238 let rijndael = Rijndael_64_64::new_with_key(&[0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE]);
239 tdes.turn_inverse();
240 let mut bigcryptor = des + rijndael + tdes;
241
242 let plaintext = 0x_1234567890ABCDEF_u64;
243 println!("Plaintext:\t\t{:#018X}", plaintext);
244 let ciphertext = bigcryptor.encrypt_u64(plaintext);
245 println!("Ciphertext:\t\t{:#018X}", ciphertext);
246 assert_eq!(ciphertext, 0x_0036D446DF6D218F_u64);
247
248 let recovered_text = bigcryptor.decrypt_u64(ciphertext);
249 println!("Recovered text:\t{:#018X}", recovered_text);
250 assert_eq!(recovered_text, 0x1234567890ABCDEF_u64);
251 assert_eq!(recovered_text, plaintext);
252 println!("-------------------------------");
253}
254
255fn bigcryptor64_turn_encryptor()
256{
257 println!("bigcryptor64_turn_encryptor");
258 use cryptocol::symmetric::{ BigCryptor64, DES, Rijndael_64_64, SmallCryptor };
259 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
260 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
261 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
262 let des = DES::new_with_key([0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
263 let rijndael = Rijndael_64_64::new_with_key(&[0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE]);
264 tdes.turn_encryptor();
265 let mut bigcryptor = des + rijndael + tdes;
266
267 let plaintext = 0x_1234567890ABCDEF_u64;
268 println!("Plaintext:\t\t{:#018X}", plaintext);
269 let ciphertext = bigcryptor.encrypt_u64(plaintext);
270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
271 assert_eq!(ciphertext, 0x_911ED9892E52BC7C_u64);
272
273 let recovered_text = bigcryptor.decrypt_u64(ciphertext);
274 println!("Recovered text:\t{:#018X}", recovered_text);
275 assert_eq!(recovered_text, 0x1234567890ABCDEF_u64);
276 assert_eq!(recovered_text, plaintext);
277 println!("-------------------------------");
278}
279
280fn bigcryptor64_turn_decryptor()
281{
282 println!("bigcryptor64_turn_decryptor");
283 use cryptocol::symmetric::{ BigCryptor64, DES, Rijndael_64_64, SmallCryptor };
284 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
285 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
286 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
287 let des = DES::new_with_key([0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
288 let rijndael = Rijndael_64_64::new_with_key(&[0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE]);
289 tdes.turn_decryptor();
290 let mut bigcryptor = des + rijndael + tdes;
291
292 let plaintext = 0x_1234567890ABCDEF_u64;
293 println!("Plaintext:\t\t{:#018X}", plaintext);
294 let ciphertext = bigcryptor.encrypt_u64(plaintext);
295 println!("Ciphertext:\t\t{:#018X}", ciphertext);
296 assert_eq!(ciphertext, 0x_0036D446DF6D218F_u64);
297
298 let recovered_text = bigcryptor.decrypt_u64(ciphertext);
299 println!("Recovered text:\t{:#018X}", recovered_text);
300 assert_eq!(recovered_text, 0x1234567890ABCDEF_u64);
301 assert_eq!(recovered_text, plaintext);
302 println!("-------------------------------");
303}
304
305fn bigcryptor64_encrypt_u64()
306{
307 println!("bigcryptor64_encrypt_u64()");
308 use cryptocol::symmetric::{ BigCryptor64, DES };
309
310 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
312 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
313 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
314 let message = 0x1234567890ABCDEF_u64;
315 println!("M = {:#018X}", message);
316 let cipher = tdes.encrypt_u64(message);
317 println!("C = {:#018X}", cipher);
318 assert_eq!(cipher, 0x_CA61814E7AE964BA_u64);
319 println!("-------------------------------");
320}
321
322fn bigcryptor64_decrypt_u64()
323{
324 println!("bigcryptor64_decrypt_u64()");
325 use cryptocol::symmetric::{ BigCryptor64, DES };
326
327 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
329 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
330 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
331 let message = 0x1234567890ABCDEF_u64;
332 println!("M = {:#018X}", message);
333 let cipher = tdes.encrypt_u64(message);
334 println!("C = {:#018X}", cipher);
335 assert_eq!(cipher, 0x_CA61814E7AE964BA_u64);
336
337 let recovered = tdes.decrypt_u64(cipher);
338 println!("B = {:#018X}", recovered);
339 assert_eq!(recovered, 0x1234567890ABCDEF_u64);
340 assert_eq!(recovered, message);
341 println!("-------------------------------");
342}
343
344fn bigcryptor64_encrypt_array_u64()
345{
346 println!("bigcryptor64_encrypt_array_u64()");
347 use cryptocol::symmetric::{ BigCryptor64, DES };
348
349 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
351 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
352 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
353 let message = [0x1234567890ABCDEF_u64, 0x1122334455667788, 0x9900AABBCCDDEEFF];
354 print!("M = ");
355 for msg in message.clone()
356 { print!("{:#018X} ", msg); }
357 println!();
358
359 let mut cipher = [0_u64; 3];
360 tdes.encrypt_array_u64(&message, &mut cipher);
361 print!("C = ");
362 for c in cipher.clone()
363 { print!("{:#018X} ", c); }
364 println!();
365 assert_eq!(cipher[0], 0x_CA61814E7AE964BA_u64);
366 assert_eq!(cipher[1], 0x_073450DF82262B1B_u64);
367 assert_eq!(cipher[2], 0x_51712805A458A102_u64);
368 println!("-------------------------------");
369}
370
371fn bigcryptor64_decrypt_array_u64()
372{
373 println!("bigcryptor64_decrypt_array_u64()");
374 use cryptocol::symmetric::{ BigCryptor64, DES };
375
376 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
378 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
379 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
380 let message = [0x1234567890ABCDEF_u64, 0x1122334455667788, 0x9900AABBCCDDEEFF];
381 print!("M = ");
382 for msg in message.clone()
383 { print!("{:#018X} ", msg); }
384 println!();
385
386 let mut cipher = [0_u64; 3];
387 tdes.encrypt_array_u64(&message, &mut cipher);
388 print!("C = ");
389 for c in cipher.clone()
390 { print!("{:#018X} ", c); }
391 println!();
392 assert_eq!(cipher[0], 0x_CA61814E7AE964BA_u64);
393 assert_eq!(cipher[1], 0x_073450DF82262B1B_u64);
394 assert_eq!(cipher[2], 0x_51712805A458A102_u64);
395
396 let mut recovered = [0_u64; 3];
397 tdes.decrypt_array_u64(&cipher, &mut recovered);
398 print!("B = ");
399 for r in recovered.clone()
400 { print!("{:#018X} ", r); }
401 println!();
402 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
403 assert_eq!(recovered[1], 0x_1122334455667788_u64);
404 assert_eq!(recovered[2], 0x_9900AABBCCDDEEFF_u64);
405 assert_eq!(recovered[0], message[0]);
406 assert_eq!(recovered[1], message[1]);
407 assert_eq!(recovered[2], message[2]);
408 println!("-------------------------------");
409}
410
411fn bigcryptor64_is_successful()
412{
413 println!("bigcryptor64_is_successful");
414 use std::io::Write;
415 use std::fmt::Write as _;
416 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
417
418 let iv = 0x_FEDCBA0987654321_u64;
420 println!("IV = {}", iv);
421 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
422 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
423 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
424
425 let message = "";
426 println!("M =\t{}", message);
427 let mut cipher = [0_u8; 8];
428 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
429 println!("The length of ciphertext = {}", len);
430 assert_eq!(len, 8);
431 let success = tdes.is_successful();
432 assert_eq!(success, true);
433 print!("C =\t");
434 for c in cipher.clone()
435 { print!("{:02X} ", c); }
436 println!();
437 let mut txt = String::new();
438 for c in cipher.clone()
439 { write!(txt, "{:02X} ", c); }
440 assert_eq!(txt, "17 C8 15 48 EE 85 42 43 ");
441 println!();
442
443 let iv = 0x_FEDCBA0987654321_u64;
445 println!("IV = {}", iv);
446 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
447 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
448 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
449
450 let cipher = [0x17_u8, 0xC8, 0x15, 0x48, 0xEE, 0x85, 0x42, 0x43];
451 print!("C =\t");
452 for c in cipher.clone()
453 { print!("{:02X} ", c); }
454 println!();
455 let mut recovered = [0u8; 8];
456 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
457 println!("The length of plaintext = {}", len);
458 assert_eq!(len, 0);
459 let success = tdes.is_successful();
460 assert_eq!(success, true);
461 print!("Ba =\t");
462 for b in recovered.clone()
463 { print!("{:02X} ", b); }
464 println!();
465 let mut txt = String::new();
466 for c in recovered.clone()
467 { write!(txt, "{:02X} ", c); }
468 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
469
470 let mut converted = String::new();
471 unsafe { converted.as_mut_vec() }.write(&recovered);
472 unsafe { converted.as_mut_vec() }.truncate(len as usize);
473 println!("Bb =\t{}", converted);
474 assert_eq!(converted, "");
475 assert_eq!(converted, message);
476 println!();
477
478
479 let iv = 0x_FEDCBA0987654321_u64;
481 println!("IV = {}", iv);
482 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
483 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
484 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
485
486 let message = "";
487 println!("M =\t{}", message);
488 let mut cipher = [0_u8; 4];
489 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
490 println!("The length of ciphertext = {}", len);
491 assert_eq!(len, 0);
492 let success = tdes.is_successful();
493 assert_eq!(success, false);
494 let mut txt = String::new();
495 for c in cipher.clone()
496 { write!(txt, "{:02X} ", c); }
497 assert_eq!(txt, "00 00 00 00 ");
498 println!();
499
500 let iv = 0x_FEDCBA0987654321_u64;
502 println!("IV = {}", iv);
503 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
504 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
505 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
506
507 let cipher = [0x17_u8, 0xC8, 0x15, 0x48];
508 print!("C =\t");
509 for c in cipher.clone()
510 { print!("{:02X} ", c); }
511 println!();
512 let mut recovered = [0u8; 8];
513 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
514 println!("The length of plaintext = {}", len);
515 assert_eq!(len, 0);
516 let success = tdes.is_successful();
517 assert_eq!(success, false);
518 println!("-------------------------------");
519}
520
521fn bigcryptor64_is_failed()
522{
523 println!("bigcryptor64_is_failed");
524 use std::io::Write;
525 use std::fmt::Write as _;
526 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
527
528 let iv = 0x_FEDCBA0987654321_u64;
530 println!("IV = {}", iv);
531 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
532 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
533 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
534
535 let message = "";
536 println!("M =\t{}", message);
537 let mut cipher = [0_u8; 8];
538 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
539 println!("The length of ciphertext = {}", len);
540 assert_eq!(len, 8);
541 let failure = tdes.is_failed();
542 assert_eq!(failure, false);
543 print!("C =\t");
544 for c in cipher.clone()
545 { print!("{:02X} ", c); }
546 println!();
547 let mut txt = String::new();
548 for c in cipher.clone()
549 { write!(txt, "{:02X} ", c); }
550 assert_eq!(txt, "17 C8 15 48 EE 85 42 43 ");
551 println!();
552
553 let iv = 0x_FEDCBA0987654321_u64;
555 println!("IV = {}", iv);
556 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
557 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
558 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
559
560 let cipher = [0x17_u8, 0xC8, 0x15, 0x48, 0xEE, 0x85, 0x42, 0x43];
561 print!("C =\t");
562 for c in cipher.clone()
563 { print!("{:02X} ", c); }
564 println!();
565 let mut recovered = [0u8; 8];
566 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
567 println!("The length of plaintext = {}", len);
568 assert_eq!(len, 0);
569 let failure = tdes.is_failed();
570 assert_eq!(failure, false);
571 print!("Ba =\t");
572 for b in recovered.clone()
573 { print!("{:02X} ", b); }
574 println!();
575 let mut txt = String::new();
576 for c in recovered.clone()
577 { write!(txt, "{:02X} ", c); }
578 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
579
580 let mut converted = String::new();
581 unsafe { converted.as_mut_vec() }.write(&recovered);
582 unsafe { converted.as_mut_vec() }.truncate(len as usize);
583 println!("Bb =\t{}", converted);
584 assert_eq!(converted, "");
585 assert_eq!(converted, message);
586 println!();
587
588
589 let iv = 0x_FEDCBA0987654321_u64;
591 println!("IV = {}", iv);
592 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
593 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
594 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
595
596 let message = "";
597 println!("M =\t{}", message);
598 let mut cipher = [0_u8; 4];
599 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
600 println!("The length of ciphertext = {}", len);
601 assert_eq!(len, 0);
602 let failure = tdes.is_failed();
603 assert_eq!(failure, true);
604 let mut txt = String::new();
605 for c in cipher.clone()
606 { write!(txt, "{:02X} ", c); }
607 assert_eq!(txt, "00 00 00 00 ");
608 println!();
609
610 let iv = 0x_FEDCBA0987654321_u64;
612 println!("IV = {}", iv);
613 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
614 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
615 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
616
617 let cipher = [0x17_u8, 0xC8, 0x15, 0x48];
618 print!("C =\t");
619 for c in cipher.clone()
620 { print!("{:02X} ", c); }
621 println!();
622
623 let mut recovered = [0u8; 8];
624 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
625 println!("The length of plaintext = {}", len);
626 assert_eq!(len, 0);
627 let failure = tdes.is_failed();
628 assert_eq!(failure, true);
629 println!("-------------------------------");
630}
631
632fn tdes_quick_start_main()
633{
634 tdes_new_with_2_keys_u64();
635 tdes_new_with_3_keys_u64();
636 tdes_new_with_2_keys();
637 tdes_new_with_3_keys();
638 tdes_new_with_keys_u128();
639}
640
641fn tdes_new_with_2_keys_u64()
642{
643 println!("tdes_new_with_2_keys_u64()");
644 use std::io::Write;
645 use std::fmt::Write as _;
646 use cryptocol::symmetric::{ TDES, CBC_PKCS7 };
647
648 let mut tdes = TDES::new_with_2_keys_u64(0x_1234567890ABCDEF_u64, 0x_FEDCBA0987654321_u64);
649 let iv = 0x_FEDCBA0987654321_u64;
650 println!("IV = {:#018X}", iv);
651 let message = "In the beginning God created the heavens and the earth.";
652 println!("M =\t{}", message);
653 let mut cipher = Vec::<u8>::new();
654 tdes.encrypt_str_into_vec(iv, &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, "01 A5 7E BC ED 83 28 FB 7A 06 61 60 7D 8B BA AF 5C A7 76 0B FE 94 1C C4 C2 BC DD 15 98 A9 98 6C 85 18 92 6B 00 72 FB 72 DB 9D 46 BD B1 3C 56 C0 DC 0E 37 04 69 4F 62 68 ");
663
664 let mut recovered = String::new();
665 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
666 println!("B =\t{}", recovered);
667 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
668 assert_eq!(recovered, message);
669 println!("-------------------------------");
670}
671
672fn tdes_new_with_3_keys_u64()
673{
674 println!("tdes_new_with_3_keys_u64()");
675 use std::io::Write;
676 use std::fmt::Write as _;
677 use cryptocol::symmetric::{ TDES, CBC_PKCS7 };
678
679 let mut tdes = TDES::new_with_3_keys_u64(0x_1234567890ABCDEF_u64, 0x_1122334455667788_u64, 0x_9900AABBCCDDEEFF_u64);
680 let iv = 0x_FEDCBA0987654321_u64;
681 println!("IV = {:#018X}", iv);
682 let message = "In the beginning God created the heavens and the earth.";
683 println!("M =\t{}", message);
684 let mut cipher = Vec::<u8>::new();
685 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
686 print!("C =\t");
687 for c in cipher.clone()
688 { print!("{:02X} ", c); }
689 println!();
690 let mut txt = String::new();
691 for c in cipher.clone()
692 { write!(txt, "{:02X} ", c); }
693 assert_eq!(txt, "B4 6C 2D 9A F5 67 60 45 A0 2B 68 E8 76 8E BD EF 7E 2D 7A 49 9A DE 43 0D 4C 3C 50 1E B6 8B 0A E8 A4 88 6E E7 FF 99 B9 2D 83 67 C9 3C 4A 2D C7 BA 40 F3 19 88 05 F2 2C D9 ");
694
695 let mut recovered = String::new();
696 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
697 println!("B =\t{}", recovered);
698 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
699 assert_eq!(recovered, message);
700 println!("-------------------------------");
701}
702
703fn tdes_new_with_2_keys()
704{
705 println!("tdes_new_with_2_keys()");
706 use std::io::Write;
707 use std::fmt::Write as _;
708 use cryptocol::symmetric::{ TDES, CBC_PKCS7 };
709
710 let key1 = [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
711 let key2 = [0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21];
712 let mut tdes = TDES::new_with_2_keys(key1, key2);
713 let iv = 0x_FEDCBA0987654321_u64;
714 println!("IV = {:#018X}", iv);
715 let message = "In the beginning God created the heavens and the earth.";
716 println!("M =\t{}", message);
717 let mut cipher = Vec::<u8>::new();
718 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
719 print!("C =\t");
720 for c in cipher.clone()
721 { print!("{:02X} ", c); }
722 println!();
723 let mut txt = String::new();
724 for c in cipher.clone()
725 { write!(txt, "{:02X} ", c); }
726 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
727
728 let mut recovered = String::new();
729 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
730 println!("B =\t{}", recovered);
731 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
732 assert_eq!(recovered, message);
733 println!("-------------------------------");
734}
735
736fn tdes_new_with_3_keys()
737{
738 println!("tdes_new_with_3_keys()");
739 use std::io::Write;
740 use std::fmt::Write as _;
741 use cryptocol::symmetric::{ TDES, CBC_PKCS7 };
742
743 let key1 = [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
744 let key2 = [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88];
745 let key3 = [0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF];
746 let mut tdes = TDES::new_with_3_keys(key1, key2, key3);
747 let iv = 0x_FEDCBA0987654321_u64;
748 println!("IV = {:#018X}", iv);
749 let message = "In the beginning God created the heavens and the earth.";
750 println!("M =\t{}", message);
751 let mut cipher = Vec::<u8>::new();
752 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
753 print!("C =\t");
754 for c in cipher.clone()
755 { print!("{:02X} ", c); }
756 println!();
757 let mut txt = String::new();
758 for c in cipher.clone()
759 { write!(txt, "{:02X} ", c); }
760 assert_eq!(txt, "93 8E 74 E3 51 84 23 B5 36 76 B6 82 D1 8B 7A A3 1F 87 D2 48 9A 75 BF 59 0D 93 6D 8D A7 86 4A CC 0F D8 0D E0 CD 0D F9 A8 B9 38 36 0C E7 24 73 3F 5F 4D 61 AB 92 D6 34 14 ");
761
762 let mut recovered = String::new();
763 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
764 println!("B =\t{}", recovered);
765 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
766 assert_eq!(recovered, message);
767 println!("-------------------------------");
768}
769
770fn tdes_new_with_keys_u128()
771{
772 println!("tdes_new_with_keys_u128()");
773 use std::io::Write;
774 use std::fmt::Write as _;
775 use cryptocol::symmetric::{ TDES, CBC_PKCS7 };
776
777 let mut tdes = TDES::new_with_keys_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
778 let iv = 0x_FEDCBA0987654321_u64;
779 println!("IV = {:#018X}", iv);
780 let message = "In the beginning God created the heavens and the earth.";
781 println!("M =\t{}", message);
782 let mut cipher = Vec::<u8>::new();
783 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
784 print!("C =\t");
785 for c in cipher.clone()
786 { print!("{:02X} ", c); }
787 println!();
788 let mut txt = String::new();
789 for c in cipher.clone()
790 { write!(txt, "{:02X} ", c); }
791 assert_eq!(txt, "17 AE B5 A8 D2 77 21 0C 73 52 2F EB 5B 7C 9B 82 47 71 D2 7A F0 A9 F0 EA EC 0A D5 61 CB 63 86 33 8C 1F F2 F1 16 62 A0 55 22 9E 12 7A 91 88 D1 37 7B CB 43 32 19 0D AA B0 ");
792
793 let mut recovered = String::new();
794 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
795 println!("B =\t{}", recovered);
796 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
797 assert_eq!(recovered, message);
798 println!("-------------------------------");
799}
800
801fn ddes_quick_start_main()
802{
803 ddes_new_with_2_keys_u64();
804 ddes_new_with_2_keys();
805 ddes_new_with_keys_u128();
806}
807
808fn ddes_new_with_2_keys_u64()
809{
810 println!("ddes_new_with_2_keys_u64()");
811 use std::io::Write;
812 use std::fmt::Write as _;
813 use cryptocol::symmetric::{ DDES, CBC_PKCS7 };
814
815 let mut ddes = DDES::new_with_2_keys_u64(0x_1234567890ABCDEF_u64, 0x_FEDCBA0987654321_u64);
816 let iv = 0x_FEDCBA0987654321_u64;
817 println!("IV = {:#018X}", iv);
818 let message = "In the beginning God created the heavens and the earth.";
819 println!("M =\t{}", message);
820 let mut cipher = Vec::<u8>::new();
821 ddes.encrypt_str_into_vec(iv, &message, &mut cipher);
822 print!("C =\t");
823 for c in cipher.clone()
824 { print!("{:02X} ", c); }
825 println!();
826 let mut txt = String::new();
827 for c in cipher.clone()
828 { write!(txt, "{:02X} ", c); }
829 assert_eq!(txt, "B0 56 0C 03 A4 38 1F 70 C1 21 99 C6 23 06 05 30 DA 57 5F CD 17 FB 11 BF E1 05 92 B3 FD A8 70 15 24 3F A1 29 B9 D1 F6 7A 1D 58 86 BE 40 41 26 15 4A DA D3 EB 4E 84 85 60 ");
830
831 let mut recovered = String::new();
832 ddes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
833 println!("B =\t{}", recovered);
834 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
835 assert_eq!(recovered, message);
836 println!("-------------------------------");
837}
838
839fn ddes_new_with_2_keys()
840{
841 println!("ddes_new_with_2_keys()");
842 use std::io::Write;
843 use std::fmt::Write as _;
844 use cryptocol::symmetric::{ DDES, CBC_PKCS7 };
845
846 let key1 = [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF];
847 let key2 = [0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21];
848 let mut ddes = DDES::new_with_2_keys(key1, key2);
849 let iv = 0x_FEDCBA0987654321_u64;
850 println!("IV = {:#018X}", iv);
851 let message = "In the beginning God created the heavens and the earth.";
852 println!("M =\t{}", message);
853 let mut cipher = Vec::<u8>::new();
854 ddes.encrypt_str_into_vec(iv, &message, &mut cipher);
855 print!("C =\t");
856 for c in cipher.clone()
857 { print!("{:02X} ", c); }
858 println!();
859 let mut txt = String::new();
860 for c in cipher.clone()
861 { write!(txt, "{:02X} ", c); }
862 assert_eq!(txt, "26 FB A9 70 99 13 83 84 63 A7 17 79 DD C6 1D D0 3D 37 12 07 B3 79 FE 5F E7 E2 6A 06 FF EC 43 26 CB 38 D6 A0 74 05 C0 E8 18 86 3F AF EA 54 AC 12 64 B7 20 C5 7F 36 02 2F ");
863
864 let mut recovered = String::new();
865 ddes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
866 println!("B =\t{}", recovered);
867 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
868 assert_eq!(recovered, message);
869 println!("-------------------------------");
870}
871
872fn ddes_new_with_keys_u128()
873{
874 println!("ddes_new_with_keys_u128()");
875 use std::io::Write;
876 use std::fmt::Write as _;
877 use cryptocol::symmetric::{ DDES, CBC_PKCS7 };
878
879 let mut tdes = DDES::new_with_keys_u128(0x_1234567890ABCDEFFEDCBA0987654321_u128);
880 let iv = 0x_FEDCBA0987654321_u64;
881 println!("IV = {:#018X}", iv);
882 let message = "In the beginning God created the heavens and the earth.";
883 println!("M =\t{}", message);
884 let mut cipher = Vec::<u8>::new();
885 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
886 print!("C =\t");
887 for c in cipher.clone()
888 { print!("{:02X} ", c); }
889 println!();
890 let mut txt = String::new();
891 for c in cipher.clone()
892 { write!(txt, "{:02X} ", c); }
893 assert_eq!(txt, "8E C3 47 07 38 6E 5F E1 BA 9C AF C1 41 B5 22 E3 55 22 DE 83 60 21 41 86 5D 94 06 1A 6C 54 32 F8 58 BE 43 23 FC 80 99 5B 1C 9D 4B 5D 1B E7 8B 9F 91 9D 83 1B C7 3D C0 55 ");
894
895 let mut recovered = String::new();
896 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
897 println!("B =\t{}", recovered);
898 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
899 assert_eq!(recovered, message);
900 println!("-------------------------------");
901}