Example #1
0
    def test_endian(self):
        from pycoin.intbytes import int_from_bytes, int_to_bytes, from_bytes, to_bytes
        assert int_from_bytes(int_to_bytes(768)) == 768
        assert int_from_bytes(int_to_bytes(3)) == 3
        assert int_from_bytes(int_to_bytes(66051)) == 66051

        for e in ("big", "little"):
            assert from_bytes(to_bytes(768, 2, e), e) == 768
            assert from_bytes(to_bytes(3, 1, e), e) == 3
            assert from_bytes(to_bytes(66051, 3, e), e) == 66051
Example #2
0
    def test_endian(self):
        from pycoin.intbytes import int_from_bytes, int_to_bytes, from_bytes, to_bytes
        assert int_from_bytes(int_to_bytes(768)) == 768
        assert int_from_bytes(int_to_bytes(3)) == 3
        assert int_from_bytes(int_to_bytes(66051)) == 66051

        for e in ("big", "little"):
            assert from_bytes(to_bytes(768, 2, e), e) == 768
            assert from_bytes(to_bytes(3, 1, e), e) == 3
            assert from_bytes(to_bytes(66051, 3, e), e) == 66051
Example #3
0
 def __init__(self, n=0):
     negative = (n < 0)
     if negative:
         n = -n
     the_len = (n.bit_length() + 7)//8
     sign = b'\x80' if negative else b'\0'
     the_bytes = struct.pack(">L", the_len+1) + sign + to_bytes(n, the_len, "big")
     library.BN_mpi2bn(the_bytes, the_len + 5, self)
Example #4
0
 def __init__(self, n=0):
     negative = (n < 0)
     if negative:
         n = -n
     the_len = (n.bit_length() + 7) // 8
     sign = b'\x80' if negative else b'\0'
     the_bytes = struct.pack(">L", the_len + 1) + sign + to_bytes(
         n, the_len, "big")
     library.BN_mpi2bn(the_bytes, the_len + 5, self)