-
Notifications
You must be signed in to change notification settings - Fork 0
/
unblind.py
55 lines (32 loc) · 1.06 KB
/
unblind.py
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
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from random import SystemRandom
import sys
print("Start")
def readFromFile(filename):
file = open(filename, 'r')
data = file.readlines()
file.close()
return ''.join(data).replace(">","").replace("<","")
pub= RSA.importKey(readFromFile('key.pub'))
r = (long) (readFromFile('r'))
msg_blinded_signature = long(sys.argv[1])
print pub.exportKey()
print "r:" , r
print "blinded signature: " , msg_blinded_signature
#SA computes
# msg_blinded_signature = ''.join(str(bytearray.fromhex(msg_blinded_signature)))
# user computes
msg_signature = pub.unblind(msg_blinded_signature, r)
print "Signature for original ballot:"
print msg_signature
msg = raw_input("What was the original ballot? ")
print "got: " + msg
# Someone verifies
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.hexdigest()
if (pub.verify(msgDigest, (msg_signature,))):
print "Signature is good. Submit signature and original ballot to the counter"
else:
print "The signature is invalid. Something went wrong"