def checkToken(token): currentTime = int(time.time()) for i in range(currentTime - 5, currentTime + 5): randomGen = MT19937(i) if randomGen.extract_number() == token: return True return False
def getRandomNumber(): print("Getting random number...") time.sleep(40 + random.randint(0, 960)) currentTime = int(time.time()) randomGen = MT19937(currentTime) randomNum = randomGen.extract_number() time.sleep(40 + random.randint(0, 960)) return randomNum
def findRandomSeed(randomInput): currentTime = int(time.time()) for i in range(0, 3600): newSeed = currentTime - i randomGen = MT19937(newSeed) randomNum = randomGen.extract_number() if randomNum == randomInput: return newSeed
def randomCipher(startBytes, seed): randomGen = MT19937(seed) keyBytes = bytearray() for i in range(len(startBytes)): # append least significant byte of number to key bytes newKeyByte = randomGen.extract_number() & 0xFF keyBytes.append(newKeyByte) resultBytes = streamXOR(startBytes, keyBytes) return resultBytes
def cloneMT19937(initialPRNG): newPRNG = MT19937(0) for i in range(0, 624): untempered = untemper(initialPRNG.extract_number()) newPRNG.mt[i] = untempered return newPRNG
return result # fully untempers a given value from MT19937 to get the untempered matrix value # returns untempered value (int) def untemper(value): result = value result = unShiftRightXOR(result, 18) result = unShiftLeftXOR(result, 15, 0xEFC60000) result = unShiftLeftXOR(result, 7, 0x9D2C5680) result = unShiftRightXOR(result, 11) return result # gets 624 random numbers from initialPRNG (MT19937) and untempers each of them. # these untempered values are spliced into another PRNG - the state of the PRNG is duplicated. # returns newPRNG (MT19937) def cloneMT19937(initialPRNG): newPRNG = MT19937(0) for i in range(0, 624): untempered = untemper(initialPRNG.extract_number()) newPRNG.mt[i] = untempered return newPRNG if __name__ == "__main__": currentTime = int(time.time()) randomGen = MT19937(currentTime) clonedGen = cloneMT19937(randomGen) print("Cloned output: " + str(clonedGen.extract_number())) print("Actual output: " + str(randomGen.extract_number()))
def generateToken(): currentTime = int(time.time()) randomGen = MT19937(currentTime) return randomGen.extract_number()