From 7fe70657005cb5b5b2384d90168a538badab2fcb Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 16 Apr 2020 05:07:52 +0300 Subject: [PATCH] isPrime() method working with good accuracy. needs more testing. --- rsa.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/rsa.py b/rsa.py index 4546b5a..9b5f1f2 100755 --- a/rsa.py +++ b/rsa.py @@ -3,16 +3,39 @@ #program to generate rsa key pair using methods in EE-305 # Hesham Banafa +import math def main(): - pass + + #test isPrime method + for i in range(2,999999): + if isPrime(i): + print(i, 'is prime') def getPrime(bits): pass def isPrime(number): - pass + if number == 2: + return True + #if 2 devides number then num is not prime. pg.21 + if number % 2 == 0 or number == 1: + return False + + #largest integer less than or equal square root of number (K) + rootOfNum = math.sqrt(number) + K = math.floor(rootOfNum) + + #Take odd D such that 1 < D <= K + #If D devides number then number is not prime. otherwise prime. + for D in range(2, K): + if D % 2 == 0: + pass + else: + if number % D == 0 or number % 5 == 0: + return False + return True if __name__ == "__main__":