def setSeed(self, seed): while seed < 3 or seed % self.p == 0 or seed % self.q == 0: seed = cu.get_int(cu.hash_val(cu.get_bytes(seed))) self.state = seed
nonce = 0 count = 0 totalnonce = 0 difficulty = 2**5 done = False testing = True salt = bcrypt.gensalt(12) while (not done): totalmessage = str(testmessage) + str(nonce) totalmessage = totalmessage.encode('utf-8') hashed = bcrypt.hashpw((cu.hash_hex_val(totalmessage)).encode('utf-8'), salt) vals = hashed.split(b'$') val = base64.b64decode(vals[3][22:] + b'=', './') val = cu.get_int(val) nonce = nonce + 1 if val % difficulty == 0: print('Hash Found!') totalnonce = totalnonce + nonce nonce = 0 count = count + 1 if count > 10: done = True print(totalnonce / count)
self.p = self.getPrime(int(bits / 2)) while True: self.q = self.getPrime(int(bits / 2)) # make sure p != q (almost always true, but just in case, check) if self.p != self.q: self.m = self.p * self.q return def __init__(self, bits, primeseed, initialseed): random.seed(primeseed) self.generateVals(bits) self.setSeed(initialseed) def setSeed(self, seed): while seed < 3 or seed % self.p == 0 or seed % self.q == 0: seed = cu.get_int(cu.hash_val(cu.get_bytes(seed))) self.state = seed def next(self): self.state = (self.state**2) % self.m return self.state if __name__ == "__main__": bbs = BlumBlumShub( 256, b"I drive a chevrolet movie theater", cu.get_int(cu.hash_val(b"Interior Crocodile Alligator"))) for i in range(256): print(bbs.next())
def generate_public_key(privkey): newpubkey = [] for x in range(len(privkey)): newpubkey.append(cu.get_int(cu.hash_val(cu.get_bytes(privkey[x])))) return newpubkey