2020-04-19 14:45:51 +02:00
|
|
|
#!/usr/bin/python3
|
2020-04-17 03:43:03 +02:00
|
|
|
|
2020-12-12 00:26:02 +01:00
|
|
|
# Copyright (C) 2019, 2020 Hesham T. Banafa
|
|
|
|
|
2020-04-18 01:21:53 +02:00
|
|
|
s = 'test message hello awdawd'
|
2020-04-17 03:43:03 +02:00
|
|
|
print(s)
|
|
|
|
s_number = int.from_bytes(s.encode('utf-8'),'little')
|
|
|
|
print(s_number)
|
|
|
|
|
|
|
|
ss = str(s_number.to_bytes(s_number.bit_length(),'little').decode('utf-8')).strip()
|
|
|
|
print(ss)
|
|
|
|
|
|
|
|
msg_list = list()
|
|
|
|
|
|
|
|
for word in s.split():
|
|
|
|
msg_list.append(word)
|
|
|
|
print(msg_list)
|
|
|
|
|
|
|
|
import rsa as en
|
|
|
|
|
2020-04-18 01:21:53 +02:00
|
|
|
key = en.generateKeys("temp")
|
2020-04-17 03:43:03 +02:00
|
|
|
enc_list = list()
|
|
|
|
pub_key = (key[0],key[1])
|
|
|
|
for word in msg_list:
|
|
|
|
enc_list.append(en.encrypt(word,pub_key))
|
|
|
|
print(enc_list)
|
|
|
|
|
|
|
|
unenc_list = list()
|
|
|
|
|
|
|
|
for enc_word in enc_list:
|
2020-04-17 20:38:50 +02:00
|
|
|
unenc_list.append(str(en.decrypt(enc_word,key[2],key[0])).strip(('\x00')))
|
|
|
|
print(unenc_list)
|
|
|
|
|
|
|
|
sig = "hesham"
|
|
|
|
n = key[en.N]
|
|
|
|
e = key[en.D] #encrypt with private key
|
|
|
|
d = key[en.E]
|
|
|
|
sig_enc = en.encrypt(sig,(n,e))
|
|
|
|
print(sig_enc)
|
|
|
|
sig_un = en.decrypt(sig_enc,d,n)
|
2020-04-18 01:21:53 +02:00
|
|
|
print(sig_un)
|
2020-04-19 14:45:51 +02:00
|
|
|
print(key)
|
2020-04-20 19:16:49 +02:00
|
|
|
|
|
|
|
import OAEP
|
|
|
|
|
|
|
|
key = en.generateKeys("encode-test", 2048)
|
|
|
|
x = int(en.encrypt("test message", (key[en.N], key[en.E])))
|
|
|
|
print(x)
|
|
|
|
encoded_msg = OAEP.i2osp(x, key[en.N].bit_length())
|
|
|
|
print(encoded_msg)
|
|
|
|
|
|
|
|
decoded = OAEP.os2ip(encoded_msg)
|
|
|
|
print(decoded)
|