Compare commits

...

6 Commits

Author SHA1 Message Date
0cbbc77976
Merge branch 'master' into file-sys 2020-08-28 19:28:25 +03:00
96e8f753ff
prepare merge 2020-08-28 19:27:56 +03:00
7bfe4c3c89
Ignore new ecnrypted msg files.
Signed-off-by: HeshamTB <hishaminv@gmail.com>
2020-07-24 10:49:45 +03:00
d7a8ec02ea
Rename rsa.py to hrsa:
hashbang in hrsa file will invoke python3 on linux
2020-07-06 02:18:03 +03:00
960468ad21
Output header/footer 2020-07-06 00:29:30 +03:00
51d9571a37
Save message to file 2020-07-05 10:08:51 +03:00

14
rsa.py
View File

@ -25,6 +25,8 @@ P=3
Q=4 Q=4
PHI=5 PHI=5
ID=6 ID=6
FILE_HEADER = "---------- START OF RSA ENCRYPTED MESSAGE ----------"
FILE_FOOTER = "---------- END OF RSA ENCRYPTED MESSAGE ----------"
def main(): def main():
print("hesham-rsa version ", VERSION) print("hesham-rsa version ", VERSION)
@ -58,8 +60,10 @@ def main():
for word in msg_list: for word in msg_list:
msg_encrypted = msg_encrypted + " " + hex(encrypt(word, key_public)) msg_encrypted = msg_encrypted + " " + hex(encrypt(word, key_public))
#msg_encrypted = encrypt(msg, key_public) #msg_encrypted = encrypt(msg, key_public)
sighned_msg = sign(msg_encrypted, signing_key)
print("Encrypted msg: \n", msg_encrypted) 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: else:
print("Not enough arguments") print("Not enough arguments")
print("rsa encrypt <message> <key> <signer>") print("rsa encrypt <message> <key> <signer>")
@ -284,6 +288,14 @@ def exportKey(keyFileName):
saveKeyFile(public_key, key[ID]+"-public") saveKeyFile(public_key, key[ID]+"-public")
print("Saved public form of key {} in keys folder".format(key[ID])) 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): def crackKey(keyName):
print("in crack") print("in crack")
key = readKeyFile(keyName) key = readKeyFile(keyName)