Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit dcd4db2

Browse files
committed
Modified generator and added proper testing
1 parent 508980a commit dcd4db2

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Elgamal-Encryption/example.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _generate_key():
4444
# Assigning the largest 1024-bit safe prime as p
4545
p = (1 << 1024) - 1093337
4646
x = randint(2, p-2)
47-
g = 23
47+
g = 7
4848
q = p - 1
4949
h = pow(g, x, p)
5050
pubkey = PublicKey(h, p, g, q)
@@ -126,14 +126,15 @@ def _decrypt(ciphertext, privkey):
126126
m = (c2*inverse(s, p)) % p
127127
return m
128128

129-
def test():
129+
if __name__ == "__main__":
130+
from os import urandom
130131
pubkey, privkey = _generate_key()
131-
print "h: ", pubkey.h
132-
print "p: ", pubkey.p
133-
print "g: ", pubkey.g
134-
print "q: ", pubkey.q
135-
print "x: ", privkey.x
136-
print "\n"
137-
ct = _encrypt("test string", pubkey)
138-
print long_to_bytes(_decrypt(ct, privkey))
139-
test()
132+
for i in range(100):
133+
message = chr(1) + urandom(16)
134+
ct = _encrypt(message, pubkey)
135+
try:
136+
assert long_to_bytes(_decrypt(ct, privkey)) == message
137+
except:
138+
print "[-] Something's wrong! Check the implementation!"
139+
import sys
140+
sys.exit()

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ Help CTF players and individuals interested in the field of Cryptography provide
8787

8888
| S.No. | Topic | Explanation | Impl./Exploit | Challenge# |
8989
|-------|:---------------------------:|:-----------------------------------------------------------------------------------------------:|:------------:|:----------:|
90-
| 1 | [DLP](https://github.com/ashutosh1206/Crypton/tree/master/Discrete-Logarithm-Problem)- cyclic groups, discrete logarithm problem, Baby-Step-Giant-Step algorithm| <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/blob/master/Discrete-Logarithm-Problem/README.md)</li></ul> | <ul><li>- [ ] </li></ul>| <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/tree/master/Discrete-Logarithm-Problem/Challenges) </li></ul> |
91-
| 2 | [Elliptic Curve DLP](https://github.com/ashutosh1206/Crypton/tree/master/Discrete-Logarithm-Problem/Elliptic-Curve-DLP)- defining identity element, inverse of a point, cyclic groups over points on an EC, Hasse's theorem, ECDLP | <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/blob/master/Discrete-Logarithm-Problem/Elliptic-Curve-DLP/README.md)</li></ul> | <ul><li>- [ ] </li></ul>| <ul><li>- [ ] </li></ul> |
90+
| 1 | [DLP](https://github.com/ashutosh1206/Crypton/tree/master/Discrete-Logarithm-Problem)- Cyclic Groups, Discrete Logarithm Problem| <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/blob/master/Discrete-Logarithm-Problem/README.md)</li></ul> | <ul><li>- [ ] </li></ul>| <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/tree/master/Discrete-Logarithm-Problem/Challenges) </li></ul> |
91+
| 2 | []()
92+
| 3 | [Elliptic Curve DLP](https://github.com/ashutosh1206/Crypton/tree/master/Discrete-Logarithm-Problem/Elliptic-Curve-DLP)- defining identity element, inverse of a point, cyclic groups over points on an EC, Hasse's theorem, ECDLP | <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/blob/master/Discrete-Logarithm-Problem/Elliptic-Curve-DLP/README.md)</li></ul> | <ul><li>- [ ] </li></ul>| <ul><li>- [ ] </li></ul> |
9293

9394

9495

@@ -117,7 +118,7 @@ Help CTF players and individuals interested in the field of Cryptography provide
117118

118119
| S.No. | Topic | Explanation | Impl./Exploit | Challenge# |
119120
|-------|:---------------------------:|:-----------------------------------------------------------------------------------------------:|:------------:|:----------:|
120-
| 1 | [Elliptic Curve Internals](https://github.com/ashutosh1206/Crypton/tree/master/Elliptic-Curves)- defining Elliptic Curves, point addition, point doubling and scalar multiplication | <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/blob/master/Elliptic-Curves/README.md)</li></ul> | <ul><li>- [x] [\[python impl.\]](https://github.com/ashutosh1206/Crypton/blob/master/Elliptic-Curves/ellipticcurve.py), [\[sage impl.\]](https://github.com/ashutosh1206/Crypton/blob/master/Elliptic-Curves/ellipticcurve.sage)</li></ul> | <ul><li>- [ ] </li></ul> |
121+
| 1 | [Elliptic Curve Internals](https://github.com/ashutosh1206/Crypton/tree/master/Elliptic-Curves)- defining Elliptic Curves, point addition, point doubling and scalar multiplication | <ul><li>- [x] [\[link\]](https://github.com/ashutosh1206/Crypton/blob/master/Elliptic-Curves/README.md)</li></ul> | <ul><li>- [x] [\[python\]](https://github.com/ashutosh1206/Crypton/blob/master/Elliptic-Curves/ellipticcurve.py), [\[sage\]](https://github.com/ashutosh1206/Crypton/blob/master/Elliptic-Curves/ellipticcurve.sage)</li></ul> | <ul><li>- [ ] </li></ul> |
121122

122123

123124

0 commit comments

Comments
 (0)