-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrypto_test.ml
More file actions
62 lines (49 loc) · 1.67 KB
/
Copy pathcrypto_test.ml
File metadata and controls
62 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(* Scott Dickson
* 12/2/2017
* Test file for the cryptography section
*)
open OUnit2
open Crypto
(* Aliases used by crypto.ml *)
let zero = Big_int.zero_big_int
let bMod = Big_int.mod_big_int
let eq = Big_int.eq_big_int
let add = Big_int.add_big_int
let add_i = Big_int.add_int_big_int
let sub = Big_int.sub_big_int
let mult = Big_int.mult_big_int
let mult_i = Big_int.mult_int_big_int
let div = Big_int.div_big_int
let half b = div b (Big_int.big_int_of_int 2)
let decr b = add b (Big_int.big_int_of_int (-1))
let even b = eq (bMod b (Big_int.big_int_of_int 2)) zero
let of_int = Big_int.big_int_of_int
let to_int = Big_int.int_of_big_int
(*End functions *)
let test () =
let (pu,pr) = Crypto.generate_public_private () in
let l1 = encrypt_and_chunk "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" pu in
"After encryption: "^l1 |> print_endline;
print_string "Length is: "; print_int (String.length l1);
let l2 = decrypt_chunked l1 pu pr in
"After Decryption: "^l2 |> print_endline;
print_string "Length is: "; print_int (String.length l2)
(*
let rec test_string_to_key n =
if n = 10 then print_endline "NICE" else
let (pu,pr) = Crypto.generate_public_private () in
let str1 =Crypto.string_from_key pu in
let str2 = Crypto.key_from_string str1 in
if (eq str2 pu) then test_string_to_key (n+1) else print_endline "CRAP"
let test_mods () =
let (pu,pr) = Crypto.generate_public_private () in
let a = of_int (190*190) in
let b = of_int 191 in
let m = pu in
let val1 = mod_exp a b m in
let val2 = modinv b (mult (decr pr) pr) in
print_string "Value is: ";
print_string (Big_int.string_of_big_int (mod_exp val1 val2 m));
print_endline ""
*)
let _ = test ()