isPrime() function/algo optimization:

insted of taking all integers from 2 to K, take only odds
	since we know that the even prime is 2. This should in theory
	reduce the time to check primilaty to half.
This commit is contained in:
HeshamTB 2020-04-16 21:51:36 +03:00
parent 1954308cb4
commit db2a852cf3
Signed by: Hesham
GPG Key ID: 74876157D199B09E

4
rsa.py
View File

@ -112,8 +112,8 @@ def isPrime(number):
#Take odd D such that 1 < D <= K #Take odd D such that 1 < D <= K
#If D devides number then number is not prime. otherwise prime. #If D devides number then number is not prime. otherwise prime.
for D in range(2, K): for D in range(1, K, 2):
if D % 2 == 0: if D % 2 == 0 or D == 1:
pass pass
else: else:
if number % D == 0 or number % 5 == 0: if number % D == 0 or number % 5 == 0: