def generateKey(keySize): # Creates public/private keys keySize bits in size. p = 0 q = 0 # Step 1: Create two prime numbers, p and q. Calculate n = p * q: print('Generating p prime...') while p == q: p = primeNum.generateLargePrime(keySize) q = primeNum.generateLargePrime(keySize) n = p * q # Step 2: Create a number e that is relatively prime to (p-1)*(q-1): print('Generating e that is relatively prime to (p-1)*(q-1)...') while True: # Keep trying random numbers for e until one is valid: e = random.randrange(2**(keySize - 1), 2**(keySize)) if cryptomath.gcd(e, (p - 1) * (q - 1)) == 1: break # Step 3: Calculate d, the mod inverse of e: print('Calculating d that is mod inverse of e...') d = cryptomath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) print('Public key:', publicKey) print('Private key:', privateKey) return (publicKey, privateKey)
def generateKey(keySize): p = 0 q = 0 # Step1: create two prime numbers, p and q. calculate n = p * q: print('Generating p prime...') while p == q: p = primeNum.generateLargePrime(keySize) q = primeNum.generateLargePrime(keySize) n = p * q # Step2: Create a number e that is relatively prime to (p-1)*(q-1): print('Generating e that is relatively prime to (p-1)*(q-1)...') x = (p - 1) * (q - 1) while True: e = random.randrange(2**(keySize - 1), 2**(keySize)) if cryptomath.gcd(e, x) == 1: break # Step3: Calculate d, the mod inverse of e: print('Calculating d that is mod inverse of e...') d = cryptomath.findModInverse(e, x) publicKey = (n, e) privateKey = (n, d) print('Public Key:\n', publicKey) print('Private Key:\n', privateKey) return (publicKey, privateKey)
def generateKey(keysize): p = 0 q = 0 print('Generating p prime...') while p == q: p = primeNum.generateLargePrime(keysize) q = primeNum.generateLargePrime(keysize) n = p * q print('Generating e that is relatively prime to (p-1)*(q-1)...') while True: e = random.randrange(2**(keysize - 1), 2**(keysize)) if cryptomath.gcd(e, (p - 1) * (q - 1)) == 1: break print('Calculating d that is mod inverse of e...') d = cryptomath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) print('Public key:', publicKey) print('Private key:', privateKey) return (publicKey, privateKey)
def generateKey(keySize): # Create public/private keys keySize bits in size p = 0 q = 0 # Create two primes, p and q. Calculate n = p * q print("Generating p prime...") while p == q: p = primeNum.generateLargePrime(keySize) q = primeNum.generateLargePrime(keySize) n = p * q # Create number e that is relatively prime to (p-1)*(q-1) print("Generating e that is relatively prime to (p-1) * (q-1)...") while True: # Keep trying rand numbers for e until one is valid e = random.randrange(2**(keySize - 1), 2**keySize) if cryptomath.gcd(e, (p - 1) * (q - 1)) == 1: break # Calculate d, mod inverse of e print("Calculating d that is the mod inverse of e...") d = cryptomath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) print(f"Public key: {publicKey}") print(f"Private key: {privateKey}") return publicKey, privateKey
def generateKey(keySize): # Creates a public/private key pair with keys that are keySize bits in size. #This function may take a while to run # Step 1: Create two prime numbers, p and q. Calculate n = p * q. print("Generating p prime...") p = primeNum.generateLargePrime(keySize) print("Generating q prime...") q = primeNum.generateLargePrime(keySize) n = p * q # Step 2: Create a number e that is relatively prime to (p-1)*(q-1). print("Generating e that is relitively prime to (p-1)*(q-1)...") while True: # keep trying random numbers for e until a valid one is found e = random.randrange(2**(keySize - 1), 2**(keySize)) if cryptomath.gcd(e, (p - 1) * (q - 1)) == 1: break # step 3: calculate d, the mod inverse of e print("calculating d, the mod inverse of e") d = cryptomath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) print("Public Key") print("Private Key") return (publicKey, privateKey)
def generateKey(keySize): p = 0 q = 0 while p == q: p = primeNum.generateLargePrime(keySize) q = primeNum.generateLargePrime(keySize) n = p * q while True: e = random.randrange(2**(keySize - 1), 2**keySize) if cryptoMath.gcd(e, (p - 1) * (q - 1)) == 1: break d = cryptoMath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) return publicKey, privateKey
def generateKey(keySize): p = 0 q = 0 while p == q: p = primeNum.generateLargePrime(keySize) q = primeNum.generateLargePrime(keySize) n = p * q print('Generating e that is realativly prime to (p-1)*(q-1)...') while True: e = random.randrange(2**(keySize - 1), 2**(keySize)) if cryptomath.gcd(e, (p - 1) * (q - 1)) == 1: break d = cryptomath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) print('Public key', publicKey) print('Private key', privateKey) return publicKey, privateKey
def createKey(keysize): p = 0 q = 0 e = 0 d = 0 print('finding p, q, and n') while q == p: q = primeNum.generateLargePrime(keysize=1024) p = primeNum.generateLargePrime(keysize=1024) n = p * q print('finding e') while cryptoMath.gcd(e, (p - 1) * (q - 1)) != 1: e = random.randrange(2**(keysize - 1), 2**(keysize)) print('finding d') d = cryptoMath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) return (publicKey, privateKey)