def test_bases(self): for i in xrange(10): alphabet = generate_alphabet() for i in xrange(100): n = random.randrange(100000000000000000000000000000) s = math.natural_to_string(n, alphabet) n2 = math.string_to_natural(s, alphabet) #print n, s.encode('hex'), n2 self.assertEquals(n, n2)
def test_bases(self): for i in xrange(10): alphabet = generate_alphabet() for i in xrange(100): n = random.choice([ random.randrange(3), random.randrange(300), random.randrange(100000000000000000000000000000), ]) s = math.natural_to_string(n, alphabet) n2 = math.string_to_natural(s, alphabet) #print n, s.encode('hex'), n2 self.assertEquals(n, n2)
def base58_decode(b58data): b58data2 = b58data.lstrip(base58_alphabet[0]) return chr(0) * (len(b58data) - len(b58data2)) + math.natural_to_string( math.string_to_natural(b58data2, base58_alphabet))
def base58_encode(bindata): bindata2 = bindata.lstrip(chr(0)) return base58_alphabet[0] * ( len(bindata) - len(bindata2)) + math.natural_to_string( math.string_to_natural(bindata2), base58_alphabet)
def base58_decode(b58data): b58data2 = b58data.lstrip(base58_alphabet[0]) return chr(0)*(len(b58data) - len(b58data2)) + math.natural_to_string(math.string_to_natural(b58data2, base58_alphabet))
def base58_encode(bindata): bindata2 = bindata.lstrip(chr(0)) return base58_alphabet[0]*(len(bindata) - len(bindata2)) + math.natural_to_string(math.string_to_natural(bindata2), base58_alphabet)
def _(f): length_str = f.read(size_len) length = math.string_to_natural(length_str[::-1].lstrip(chr(0))) data = f.read(length) return data
def _(f): length_str, f = pack.read(f, size_len) length = math.string_to_natural(length_str[::-1].lstrip(chr(0))) data, f = pack.read(f, length) return data, f