Question
Here's the link for the Howework that I need also, in case you want to have a look at it. The code that was there, did not work :(
https://www.chegg.com/homework-help/questions-and-answers/build-crypto-system-c-python-please-able-run-code-without-errors-build-rsa-crypto-system-f-q16806815
b 4 0000011111100100 1001001001000110 b 3. 11010101011011001010100101100001 b 2 100011 11011101001100001010010000 b 1. 01010100010 100111101111101001101 b 0 0000000010110010 1111010000101111 Number 00000000000000000000000001010111 87 87 (q) is not prime b 4 01000000011001010 1011001 10111011 b 3. 01001001 110000111100001100001111 b 2 011011111111100001001 01000011100 b 1. 110011 10101010111110100000100001 b 0 10101100101000111011101100100 110 Number: 117 00000000000000000000000001110101 117 (q) is not prime b 4 101011 11001010001111000000110111 b 3. 10101010000000001111110101100011 b 2 11111100100000 101110 b 1. 00111101 110100100110001101101100 b 0 101111000010110101100110011 10110 Number: 113 00000000000000000000000001110001 113 (q) is probably prime line 149 p: 71. q: 113 8023 line 155 Totient of 8023 is 7840 Chosen e: 3 is relatively prime with totient 7840 Multiplicative i nverse of n 8023 and e 3 is d: 5349 line 171 71 q 113 n 8023 e 3 d 5349 00000000000000000000000001000111 00000000000000000000000001110001 00000000000000000001111101010 111 11 000000000000000000000000000000 0000000000000000000101001110010
Explanation / Answer
def miller_rabin(n, k=10): if n == 2: return True if not n & 1: return False def check(a, s, d, n): x = pow(a, d, n) if x == 1: return True for i in xrange(s - 1): if x == n - 1: return True x = pow(x, 2, n) return x == n - 1 s = 0 d = n - 1 while d % 2 == 0: d >>= 1 s += 1 for i in xrange(k): a = randrange(2, n - 1) if not check(a, s, d, n): return False return True # benchmark of 10000 iterations of miller_rabin(100**10-1); Which is not prime. # 10000 calls, 11111 per second. # 74800 function calls in 0.902 seconds