-
Notifications
You must be signed in to change notification settings - Fork 0
/
signRSA.py
48 lines (25 loc) · 900 Bytes
/
signRSA.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
import fileOp
import fdh
import modInverse
import initRSAsignature
import coprime
global public_key, private_key, n
class signer:
def __init__(self,fname):
global public_key, private_key, n
public_key = fileOp.read_list("FpublicKey")[1]
n, private_key = fileOp.read_list("FprivateKey") #FIX: Reconstruct using Shamir and rest
self.set_message(fname)
self.sign()
def set_message(self,fname):
inp = fname
inp = fileOp.read_binary_file(inp)
inp = fdh.fdh(inp,(len(bin(n))-2))
fileOp.write_list("Fsignature",[inp])
def sign(self):
signature = fileOp.read_list_noint("Fsignature")[0]
signature = int(signature[1:-1],16)
ciphertext = pow(signature, private_key, n)
fileOp.write_list("Fciphertext",[ciphertext])
if __name__ == "__main__":
s = signer("pico.jpg")