From 1a591cc75e609a7a197f0b5ec4db3edd0996c72d Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 16 Apr 2020 05:54:36 +0300 Subject: [PATCH] getPrime() method working. gets random prime based on bit size. --- rsa.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rsa.py b/rsa.py index 9b5f1f2..1c4e32b 100755 --- a/rsa.py +++ b/rsa.py @@ -4,16 +4,19 @@ # Hesham Banafa import math +import os def main(): - #test isPrime method - for i in range(2,999999): - if isPrime(i): - print(i, 'is prime') + #Prime of size 32 bit random + print(getPrime(32)) def getPrime(bits): - pass + while True: + x = int.from_bytes(os.urandom(int(bits/8)),"little") + if isPrime(x): + return x + def isPrime(number): if number == 2: