arnaucube
arnaucube/cryptofunPublic Self-hosted repository
cryptofun/elgamal/README.md
elgamal/README.mdRaw
 1## ECC ElGamal
 2- https://en.wikipedia.org/wiki/ElGamal_encryption
 3
 4- [x] ECC ElGamal key generation
 5- [x] ECC ElGamal Encrypton
 6- [x] ECC ElGamal Decryption
 7
 8
 9#### Usage
10- NewEG, Encryption, Decryption
11```go
12// define new elliptic curve
13ec := ecc.NewEC(big.NewInt(int64(1)), big.NewInt(int64(18)), big.NewInt(int64(19)))
14
15// define new point
16g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
17
18// define new ElGamal crypto system with the elliptic curve and the point
19eg, err := NewEG(ec, g)
20if err!=nil {
21	fmt.Println(err)
22}
23
24// define privK&pubK over the elliptic curve
25privK := big.NewInt(int64(5))
26pubK, err := eg.PubK(privK)
27if err!=nil {
28	fmt.Println(err)
29}
30
31// define point to encrypt
32m := ecc.Point{big.NewInt(int64(11)), big.NewInt(int64(12))}
33
34// encrypt
35c, err := eg.Encrypt(m, pubK, big.NewInt(int64(15)))
36if err!=nil {
37	fmt.Println(err)
38}
39
40// decrypt
41d, err := eg.Decrypt(c, privK)
42if err!=nil {
43	fmt.Println(err)
44}
45
46// check that decryption is correct
47if !m.Equal(d) {
48	fmt.Println("decrypted not equal to original")
49}
50```