예제 #1
0
파일: data.py 프로젝트: smurfix/p2pool
 def from_target_upper_bound(cls, target):
     n = bases.natural_to_string(target)
     if n and ord(n[0]) >= 128:
         n = '\x00' + n
     bits2 = (chr(len(n)) + (n + 3*chr(0))[:3])[::-1]
     bits = struct.unpack('<I', bits2)[0]
     return cls(bits)
예제 #2
0
파일: data.py 프로젝트: finway-china/p2pool
 def from_target_upper_bound(cls, target):
     n = bases.natural_to_string(target)
     if n and ord(n[0]) >= 128:
         n = '\x00' + n
     bits2 = (chr(len(n)) + (n + 3 * chr(0))[:3])[::-1]
     bits = struct.unpack('<I', bits2)[0]
     return cls(bits)
예제 #3
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)
예제 #4
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)
예제 #5
0
파일: data.py 프로젝트: gyver/p2pool
 def _target_to_bits(self, target, _check=True):
     n = bases.natural_to_string(target)
     if n and ord(n[0]) >= 128:
         n = '\x00' + n
     bits2 = (chr(len(n)) + (n + 3*chr(0))[:3])[::-1]
     bits = struct.unpack('<I', bits2)[0]
     if _check:
         if self._bits_to_target(bits) != target:
             raise ValueError(repr((target, self._bits_to_target(bits, _check=False))))
     return bits
예제 #6
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))
예제 #7
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)
예제 #8
0
파일: base58.py 프로젝트: gyver/p2pool
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))
예제 #9
0
파일: base58.py 프로젝트: gyver/p2pool
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)