From ea5a9195beca6488901a0331a575e60a3d74bc53 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 6 Sep 2020 06:09:12 +0300 Subject: [PATCH 1/3] Check number of args in 'gen' command interface --- rsa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsa.py b/rsa.py index 39d75e7..1371468 100644 --- a/rsa.py +++ b/rsa.py @@ -29,7 +29,7 @@ ID=6 def main(): print("hesham-rsa version ", VERSION) if len(sys.argv) > 1: - if sys.argv[1] == "gen": ##rsa gen + if sys.argv[1] == "gen" and len(sys.argv) == 4: ##rsa gen keyFileName = sys.argv[3] key = generateKeys(keyFileName, int(sys.argv[2])) print("e: ", key[E]) From a36de9cf67e0e43ec7d9fe9489d4b2384aeb8401 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 6 Sep 2020 06:13:19 +0300 Subject: [PATCH 2/3] Better output while finding primes: use \b instead of \r with the count of digits of tested number. still outputs a mess at start due to multithreads output at same time, however, stable after first itiration. --- rsa.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rsa.py b/rsa.py index 1371468..2f05cdb 100644 --- a/rsa.py +++ b/rsa.py @@ -165,11 +165,11 @@ def getPrime(bits): while True: #Byte order "little" or "big" does not matter here since we want a random number from os.urandom() x = int.from_bytes(os.urandom(int(bits/8)), byteOrder) - print("trying: ", x, end="") + print(x, end="") if mr.is_prime(x): print("\nprime: ", x) return x - print("\r",end="") + backTrack(x) def isPrime(number): @@ -339,5 +339,12 @@ def printHelp(): print("rsa print ") print("rsa list") +def backTrack(x): + #Back track and clear terminal with length of x + length = len(str(x)) + while length > 0: + print("\b",end="") + length -= 1 + if __name__ == "__main__": main() From 735b3bd71ba3d2fadcaff80b9c4002618a5748a5 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 6 Sep 2020 06:17:52 +0300 Subject: [PATCH 3/3] +x file mode --- rsa.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 rsa.py diff --git a/rsa.py b/rsa.py old mode 100644 new mode 100755