WIP: read/write text files #2

Closed
Hesham wants to merge 6 commits from file-sys into master

14
rsa.py
View File

@ -25,6 +25,8 @@ P=3
Q=4
PHI=5
ID=6
FILE_HEADER = "---------- START OF RSA ENCRYPTED MESSAGE ----------"
FILE_FOOTER = "---------- END OF RSA ENCRYPTED MESSAGE ----------"
def main():
print("hesham-rsa version ", VERSION)
@ -58,8 +60,10 @@ def main():
for word in msg_list:
msg_encrypted = msg_encrypted + " " + hex(encrypt(word, key_public))
#msg_encrypted = encrypt(msg, key_public)
sighned_msg = sign(msg_encrypted, signing_key)
print("Encrypted msg: \n", msg_encrypted)
print("Signed: \n", sign(msg_encrypted, signing_key)) ## Adds an encrypted sig at the end of message.
print("Signed: \n", sighned_msg) ## Adds an encrypted sig at the end of message.
saveToFile(sighned_msg, "encrypted-msg.txt")
else:
print("Not enough arguments")
print("rsa encrypt <message> <key> <signer>")
@ -284,6 +288,14 @@ def exportKey(keyFileName):
saveKeyFile(public_key, key[ID]+"-public")
print("Saved public form of key {} in keys folder".format(key[ID]))
def saveToFile(msg, file):
msg = str(msg)
with open(file,"w") as msg_file:
msg_file.writelines(FILE_HEADER + "\n")
msg_file.writelines(msg + "\n")
msg_file.writelines(FILE_FOOTER + "\n")
def crackKey(keyName):
print("in crack")
key = readKeyFile(keyName)