示例#1
0
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)
示例#2
0
文件: dh.py 项目: syurk738/labpin
    def __init__(self, modulus, generator):
        self.modulus = long(modulus)
        self.generator = long(generator)

        self._setPrivate(cryptutil.randrange(1, modulus - 1))
示例#3
0
    def __init__(self, modulus, generator):
        self.modulus = int(modulus)
        self.generator = int(generator)

        self._setPrivate(cryptutil.randrange(1, modulus - 1))