forked from SnakeDoctor/FGInt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECElGamalSample.pp
More file actions
55 lines (50 loc) · 1.27 KB
/
ECElGamalSample.pp
File metadata and controls
55 lines (50 loc) · 1.27 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
Program ECElGamalSample;
{$H+}
Uses
crt, FGInt, ECGFp, ECElGamal;
Var
a, b, p, k, x, n, h : TFGInt;
S, T : String;
g, y : TECPoint;
ok : boolean;
Begin
// First we generate a prime, this will determine our underlying prime field
writeln('Setting up parameters....');
Base256StringToFGInt('gxTHtzzzzznnn', p);
ok := true;
While ok Do
Begin
FindPrimeGoodCurveAndPoint(p, a, b, h, n, 50, g);
IsECSuperSingular(p, a, b, ok);
If ok Then
Begin
FGIntDestroy(a);
FGIntDestroy(b);
FGIntDestroy(h);
FGIntDestroy(n);
ECPointDestroy(g);
End;
End;
// x is a private parameter
Base2StringToFGInt('10101001011000011101', x);
// k is a random parameter
Base256StringToFGInt('AEfz32QSD', k);
// y is another public parameter, y = x * g
ECPointkmultiple(g, p, a, x, y);
S := 'peek-a-boo, I c u';
writeln('Encrypting: ', S);
// Now everything is set for encryption and decryption
ECElGamalEncrypt(S, p, a, b, k, g, y, true, T);
S := '';
writeln('Decrypting... ');
ECElGamalDecrypt(T, p, a, b, x, S);
writeln('Result: ', S);
FGIntDestroy(k);
FGIntDestroy(x);
FGIntDestroy(a);
FGIntDestroy(b);
FGIntDestroy(h);
FGIntDestroy(n);
ECPointDestroy(g);
readln
End.