Exemple #1
0
 def test_all(self):
     for i in xrange(10):
         alphabet = generate_alphabet()
         for i in xrange(100):
             n = random.randrange(100000000000000000000000000000)
             s = bases.natural_to_string(n, alphabet)
             n2 = bases.string_to_natural(s, alphabet)
             #print n, s.encode('hex'), n2
             self.assertEquals(n, n2)
Exemple #2
0
 def test_all(self):
     for i in xrange(10):
         alphabet = generate_alphabet()
         for i in xrange(100):
             n = random.randrange(100000000000000000000000000000)
             s = bases.natural_to_string(n, alphabet)
             n2 = bases.string_to_natural(s, alphabet)
             #print n, s.encode('hex'), n2
             self.assertEquals(n, n2)
Exemple #3
0
def base58_decode(b58data):
    b58data2 = b58data.lstrip(base58_alphabet[0])
    return chr(0)*(len(b58data) - len(b58data2)) + bases.natural_to_string(bases.string_to_natural(b58data2, base58_alphabet))
Exemple #4
0
def base58_encode(bindata):
    bindata2 = bindata.lstrip(chr(0))
    return base58_alphabet[0]*(len(bindata) - len(bindata2)) + bases.natural_to_string(bases.string_to_natural(bindata2), base58_alphabet)
Exemple #5
0
 def _(f):
     length_str, f = bitcoin_data.read(f, size_len)
     length = bases.string_to_natural(length_str[::-1].lstrip(chr(0)))
     data, f = bitcoin_data.read(f, length)
     return data, f
Exemple #6
0
def base58_decode(data):
    return chr(0)*(len(data) - len(data.lstrip(base58_alphabet[0]))) + bases.natural_to_string(bases.string_to_natural(data, base58_alphabet))
Exemple #7
0
def base58_encode(data):
    return base58_alphabet[0]*(len(data) - len(data.lstrip(chr(0)))) + bases.natural_to_string(bases.string_to_natural(data), base58_alphabet)
Exemple #8
0
 def _(f):
     length_str, f = bitcoin_data.read(f, size_len)
     length = bases.string_to_natural(length_str[::-1].lstrip(chr(0)))
     data, f = bitcoin_data.read(f, length)
     return data, f
Exemple #9
0
 def _bits_to_target1(self, bits):
     bits = bits[::-1]
     length = ord(bits[0])
     return bases.string_to_natural((bits[1:] + '\0'*length)[:length])