def test_cryptrand(): # It's possible, but HIGHLY unlikely that a correct implementation # will fail by returning the same number twice s = cryptutil.getBytes(32) t = cryptutil.getBytes(32) assert len(s) == 32 assert len(t) == 32 assert s != t a = cryptutil.randrange(2**128) b = cryptutil.randrange(2**128) assert type(a) is int assert type(b) is int assert b != a # Make sure that we can generate random numbers that are larger # than platform int size cryptutil.randrange(int(sys.maxsize) + 1)
def __init__(self, modulus, generator): self.modulus = long(modulus) self.generator = long(generator) self._setPrivate(cryptutil.randrange(1, modulus - 1))
def __init__(self, modulus, generator): self.modulus = int(modulus) self.generator = int(generator) self._setPrivate(cryptutil.randrange(1, modulus - 1))