From db2a852cf3718410e7b19f32a2f34cfe5bb6687c Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 16 Apr 2020 21:51:36 +0300 Subject: [PATCH] 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. --- rsa.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rsa.py b/rsa.py index 19340f8..dd83535 100755 --- a/rsa.py +++ b/rsa.py @@ -112,8 +112,8 @@ def isPrime(number): #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: + for D in range(1, K, 2): + if D % 2 == 0 or D == 1: pass else: if number % D == 0 or number % 5 == 0: