def __init__(self,multiplier=1025,shifter=7): # If key sent in is not relatively prime with the length of # symbols then keep adding 1 until it is. while cryptoMath.modinv(multiplier,len(self.SYMBOLS)) == None: multiplier += 1 # Set Multiplier to the possibly adjusted Multiplier self.Multiplier = multiplier self.Shifter = shifter print(self.Multiplier,self.Shifter) # Get the inverse key using our mod inverse function self.InverseMultiplier = cryptoMath.modinv(self.Multiplier,len(self.SYMBOLS))
def generateKey(self): # 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 = rabinMiller.generateLargePrime(self.keySize) print('Generating q prime...') q = rabinMiller.generateLargePrime(self.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**(self.keySize - 1), 2**(self.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.modinv(e, (p - 1) * (q - 1)) self.publicKey = (n, e) self.privateKey = (n, d) print('Public key:', self.publicKey) print('Private key:', self.privateKey) print()
def __init__(self, multiplier=1025, shifter=7): # If key sent in is not relatively prime with the length of # symbols then keep adding 1 until it is. while cryptoMath.modinv(multiplier, len(self.SYMBOLS)) == None: multiplier += 1 # Set Multiplier to the possibly adjusted Multiplier self.Multiplier = multiplier self.Shifter = shifter print(self.Multiplier, self.Shifter) # Get the inverse key using our mod inverse function self.InverseMultiplier = cryptoMath.modinv(self.Multiplier, len(self.SYMBOLS))
def generateKey(self): # 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 = rabinMiller.generateLargePrime(self.keySize) print('Generating q prime...') q = rabinMiller.generateLargePrime(self.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 ** (self.keySize - 1), 2 ** (self.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.modinv(e, (p - 1) * (q - 1)) self.publicKey = (n, e) self.privateKey = (n, d) print('Public key:', self.publicKey) print('Private key:', self.privateKey) print()