Updated interface
This commit is contained in:
parent
d51a42589c
commit
b4e61d0a77
41
rsa.py
Normal file → Executable file
41
rsa.py
Normal file → Executable file
@ -28,7 +28,6 @@ ID=6
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("hesham-rsa version ", VERSION)
|
print("hesham-rsa version ", VERSION)
|
||||||
if len(sys.argv) > 1:
|
|
||||||
if sys.argv[1] == "gen": ##rsa gen <keysize> <keyname>
|
if sys.argv[1] == "gen": ##rsa gen <keysize> <keyname>
|
||||||
keyFileName = sys.argv[3]
|
keyFileName = sys.argv[3]
|
||||||
key = generateKeys(keyFileName, int(sys.argv[2]))
|
key = generateKeys(keyFileName, int(sys.argv[2]))
|
||||||
@ -45,8 +44,7 @@ def main():
|
|||||||
print(ex)
|
print(ex)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if sys.argv[1] == "encrypt": ##rsa encrypt <message> <key> <signer>
|
if sys.argv[1] == "encrypt" and len(sys.argv) == 5: ##rsa encrypt <message> <key> <signer>
|
||||||
if len(sys.argv) == 5:
|
|
||||||
msg = sys.argv[2]
|
msg = sys.argv[2]
|
||||||
msg_list = msg.split()
|
msg_list = msg.split()
|
||||||
keyName = sys.argv[3]
|
keyName = sys.argv[3]
|
||||||
@ -60,13 +58,12 @@ def main():
|
|||||||
#msg_encrypted = encrypt(msg, key_public)
|
#msg_encrypted = encrypt(msg, key_public)
|
||||||
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", 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("Not enough arguments")
|
||||||
print("rsa encrypt <message> <key> <signer>")
|
print("rsa encrypt <message> <key> <signer>")
|
||||||
#Make help function
|
sys.exit(1)
|
||||||
sys.exit(0)
|
if sys.argv[1] == "decrypt" and len(sys.argv) == 4: ##rsa decrypt "<cipher>" <key>
|
||||||
if sys.argv[1] == "decrypt": ##rsa decrypt "<cipher>" <key>
|
|
||||||
if len(sys.argv) == 4:
|
|
||||||
cipher = sys.argv[2]
|
cipher = sys.argv[2]
|
||||||
cipher_list = cipher.split()
|
cipher_list = cipher.split()
|
||||||
sig = verify(cipher_list)
|
sig = verify(cipher_list)
|
||||||
@ -80,30 +77,38 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print("Signed by: \033[92m " + sig + " \u2713\033[0m")
|
print("Signed by: \033[92m " + sig + " \u2713\033[0m")
|
||||||
print("Decrypted message: \n", msg_decrypted)
|
print("Decrypted message: \n", msg_decrypted)
|
||||||
else:
|
sys.exit(0)
|
||||||
|
elif sys.argv[1] == "decrypt":
|
||||||
print("Not enough arguments")
|
print("Not enough arguments")
|
||||||
print("rsa decrypt \"<cipher>\" <keyid>")
|
print("rsa decrypt \"<cipher>\" <keyid>")
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
|
|
||||||
if sys.argv[1] == "list":
|
if sys.argv[1] == "list":
|
||||||
listKeys()
|
listKeys()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if sys.argv[1] == "export": #rsa export <key>
|
if sys.argv[1] == "export" and len(sys.argv) == 3: #rsa export <key>
|
||||||
if len(sys.argv) == 3:
|
|
||||||
key_file_name = sys.argv[2]
|
key_file_name = sys.argv[2]
|
||||||
exportKey(key_file_name)
|
exportKey(key_file_name)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
elif sys.argv[1] == "export":
|
||||||
print("Not enough arguments")
|
printHelp()
|
||||||
print("rsa export <keyid>")
|
sys.exit(1)
|
||||||
if sys.argv[1] == "crack": #rsa crack <key>
|
if sys.argv[1] == "crack" and len(sys.argv) == 3: #rsa crack <key>
|
||||||
keyName = sys.argv[2]
|
keyName = sys.argv[2]
|
||||||
cracked_key = crackKey2(keyName)
|
cracked_key = crackKey2(keyName)
|
||||||
printKey(cracked_key)
|
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]))
|
printKey(readKeyFile(sys.argv[2]))
|
||||||
|
sys.exit(0)
|
||||||
|
elif sys.argv[1] == "print":
|
||||||
|
printHelp()
|
||||||
|
sys.exit(1)
|
||||||
if sys.argv[1] == "help":
|
if sys.argv[1] == "help":
|
||||||
printHelp()
|
printHelp()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
#No command exit code
|
#No command exit code
|
||||||
printHelp()
|
printHelp()
|
||||||
|
Loading…
Reference in New Issue
Block a user