-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.fs
51 lines (45 loc) · 1.4 KB
/
Program.fs
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
// Learn more about F# at http://fsharp.org
open System
open Paillier
open Org.BouncyCastle
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
let pub, priv =
match genkeypair 1024 with
| None -> emtpyPubkey, emptyPrivateKey
| Some(a, b) -> a, b
let m1 = Math.BigInteger.ValueOf 77234725L
let m2 = Math.BigInteger.ValueOf 32234L
let a =
match encrypt pub (m1) with
| None -> Math.BigInteger.Zero
| Some(b) -> b
printfn "%A" a
let b =
match encrypt pub (m2) with
| None -> Math.BigInteger.Zero
| Some(b) -> b
printfn "%A" ( b)
let sum = add pub (a, b)
printfn "%A" (sum)
let sumC = addConstant pub (a, one)
let decSum =
match decrypt priv sum with
| None -> Math.BigInteger.Zero
| Some(b) -> b
printfn "%A" (decSum)
let decSumC =
match decrypt priv sumC with
| None -> Math.BigInteger.Zero
| Some(b) -> b
printfn "%A + %A = %A" (m1) one decSumC
printfn "decrypted equal to their sum : %A"
(decSum = m1.Add m2)
let mulC = mul pub (a,Math.BigInteger.Two)
let decMulC =
match decrypt priv mulC with
| None -> Math.BigInteger.Zero
| Some(b) -> b
printfn "%A + %A = %A" (m1) Math.BigInteger.Two decMulC
0 // return an integer exit code