diff --git a/rsa.py b/rsa.py old mode 100755 new mode 100644 index 2a0c537..1629339 --- a/rsa.py +++ b/rsa.py @@ -112,6 +112,12 @@ def main(): elif sys.argv[1] == "crack": printHelp() sys.exit(1) + if sys.argv[1] == "is_prime" and len(sys.argv) == 4: #rsa is_prime + isPrime_cmd(0) + sys.exit(0) + if sys.argv[1] == "is_prime_mr" and len(sys.argv) == 4: #rsa is_prime_mr + isPrime_cmd(1) + sys.exit(0) if sys.argv[1] == "print" and len(sys.argv) == 3: #rsa print printKey(readKeyFile(sys.argv[2])) sys.exit(0) @@ -236,6 +242,32 @@ def verify(cipher_list): else: continue else: return None +def isPrime_cmd(func): + number = 0 + base = 0 + try: + base = int(sys.argv[2]) + except ValueError as e: + print(f'Value {sys.argv[2]} is not a valid base (2, 8, 10, 16)', + file=sys.stderr) + + try: + number = int(sys.argv[3], base) + except ValueError as e: + print(f'Value {sys.argv[3]} is not valid for as a base {base} number', + file=sys.stderr) + + if func == 0: + prime = isPrime(number) + elif func == 1: + prime = mr.is_prime(number) + + if prime: + print('Prime') + print(number) + else: + print('Not prime') + def readKeyFile(keyName): key = tuple() with open(keysFolder+keyName, "r") as keyFile: