Fixed bugs:

- Key save did not save all values.
	- Index out of range of tempKey when only
	  it is only public part.

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-04-18 03:15:08 +03:00
parent ff3df34597
commit 1924c14df0
Signed by: Hesham
GPG Key ID: 74876157D199B09E

6
rsa.py
View File

@ -177,8 +177,8 @@ def readKeyFile(keyName):
key = tuple()
with open(keysFolder+keyName, "r") as keyFile:
tempkey = keyFile.readlines()
if len(tempkey) == 2: #means it only public part (n, e)
key = (int(tempkey[N].strip(), 16), int(tempkey[E].strip(), 16), 0, 0, 0, 0, tempkey[ID])
if len(tempkey) == 3: #means it only public part (n, e, id)
key = (int(tempkey[N].strip(), 16), int(tempkey[E].strip(), 16), 0, 0, 0, 0, tempkey[2])
else: #Make this a loop from 0 to 5
key = (int(tempkey[N].strip(), 16),
int(tempkey[E].strip(), 16),
@ -194,7 +194,7 @@ def saveKeyFile(key, fileName):
if not os.path.isdir(keysFolder):
os.makedirs(keysFolder)
with open(keysFolder+fileName, "w") as keyFile:
for entry in range(0, 5):
for entry in range(0, 6):
keyFile.write(hex(key[entry])+"\n")
keyFile.write(key[ID]+"\n")