term-output #4

Merged
Hesham merged 4 commits from term-output into master 2020-09-06 06:50:26 +02:00
Showing only changes of commit 66560b5f26 - Show all commits

43
rsa.py
View File

@ -15,7 +15,7 @@ import os
import sys
import MillerRabin as mr
VERSION="1.2.1"
VERSION="1.2.2"
keysFolder = "keys/"
byteOrder = "little"
N=0
@ -28,7 +28,6 @@ ID=6
def main():
print("hesham-rsa version ", VERSION)
if len(sys.argv) > 1:
if sys.argv[1] == "gen" and len(sys.argv) == 4: ##rsa gen <keysize> <keyname>
keyFileName = sys.argv[3]
key = generateKeys(keyFileName, int(sys.argv[2]))
@ -45,8 +44,7 @@ def main():
print(ex)
sys.exit(1)
sys.exit(0)
if sys.argv[1] == "encrypt": ##rsa encrypt <message> <key> <signer>
if len(sys.argv) == 5:
if sys.argv[1] == "encrypt" and len(sys.argv) == 5: ##rsa encrypt <message> <key> <signer>
msg = sys.argv[2]
msg_list = msg.split()
keyName = sys.argv[3]
@ -60,13 +58,12 @@ def main():
#msg_encrypted = encrypt(msg, key_public)
print("Encrypted msg: \n", msg_encrypted)
print("Signed: \n", sign(msg_encrypted, signing_key)) ## Adds an encrypted sig at the end of message.
else:
sys.exit(0)
elif sys.argv[1] == "encrypt":
print("Not enough arguments")
print("rsa encrypt <message> <key> <signer>")
#Make help function
sys.exit(0)
if sys.argv[1] == "decrypt": ##rsa decrypt "<cipher>" <key>
if len(sys.argv) == 4:
sys.exit(1)
if sys.argv[1] == "decrypt" and len(sys.argv) == 4: ##rsa decrypt "<cipher>" <key>
cipher = sys.argv[2]
cipher_list = cipher.split()
sig = verify(cipher_list)
@ -80,30 +77,38 @@ def main():
else:
print("Signed by: \033[92m " + sig + " \u2713\033[0m")
print("Decrypted message: \n", msg_decrypted)
else:
sys.exit(0)
elif sys.argv[1] == "decrypt":
print("Not enough arguments")
print("rsa decrypt \"<cipher>\" <keyid>")
sys.exit(0)
sys.exit(1)
if sys.argv[1] == "list":
listKeys()
sys.exit(0)
if sys.argv[1] == "export": #rsa export <key>
if len(sys.argv) == 3:
if sys.argv[1] == "export" and len(sys.argv) == 3: #rsa export <key>
key_file_name = sys.argv[2]
exportKey(key_file_name)
sys.exit(0)
else:
print("Not enough arguments")
print("rsa export <keyid>")
if sys.argv[1] == "crack": #rsa crack <key>
elif sys.argv[1] == "export":
printHelp()
sys.exit(1)
if sys.argv[1] == "crack" and len(sys.argv) == 3: #rsa crack <key>
keyName = sys.argv[2]
cracked_key = crackKey2(keyName)
printKey(cracked_key)
if sys.argv[1] == "print": #rsa print <key>
sys.exit(0)
elif sys.argv[1] == "crack":
printHelp()
sys.exit(1)
if sys.argv[1] == "print" and len(sys.argv) == 3: #rsa print <key>
printKey(readKeyFile(sys.argv[2]))
sys.exit(0)
elif sys.argv[1] == "print":
printHelp()
sys.exit(1)
if sys.argv[1] == "help":
printHelp()
sys.exit(0)
#No command exit code
printHelp()