Exemple #1
0
    def test_all(self):
        for test in ['', 'a', 'b', 'abc', 'abc' * 50, 'hello world']:
            #print test
            #print sha256.sha256(test).hexdigest()
            #print hashlib.sha256(test).hexdigest()
            #print
            assert sha256.sha256(test).hexdigest() == hashlib.sha256(
                test).hexdigest()

        def random_str(l):
            return ''.join(chr(random.randrange(256)) for i in xrange(l))

        for length in xrange(150):
            test = random_str(length)
            a = sha256.sha256(test).hexdigest()
            b = hashlib.sha256(test).hexdigest()
            assert a == b
        for i in xrange(100):
            test = random_str(int(random.expovariate(1 / 100)))
            test2 = random_str(int(random.expovariate(1 / 100)))

            a = sha256.sha256(test)
            a = a.copy()
            a.update(test2)
            a = a.hexdigest()

            b = hashlib.sha256(test)
            b = b.copy()
            b.update(test2)
            b = b.hexdigest()
            assert a == b
Exemple #2
0
 def test_all(self):
     for test in ['', 'a', 'b', 'abc', 'abc'*50, 'hello world']:
         #print test
         #print sha256.sha256(test).hexdigest()
         #print hashlib.sha256(test).hexdigest()
         #print
         assert sha256.sha256(test).hexdigest() == hashlib.sha256(test).hexdigest()
     def random_str(l):
         return ''.join(chr(random.randrange(256)) for i in xrange(l))
     for length in xrange(150):
         test = random_str(length)
         a = sha256.sha256(test).hexdigest()
         b = hashlib.sha256(test).hexdigest()
         #print length, a, b
         if a != b:
             print 'ERROR!'
             raise ValueError()
     for i in xrange(100):
         test = random_str(int(random.expovariate(1/100)))
         test2 = random_str(int(random.expovariate(1/100)))
         
         a = sha256.sha256(test)
         a = a.copy()
         a.update(test2)
         a = a.hexdigest()
         
         b = hashlib.sha256(test)
         b = b.copy()
         b.update(test2)
         b = b.hexdigest()
         #print a, b
         if a != b:
             print 'ERROR!'
             raise ValueError()
def prefix_to_hash_link(prefix, const_ending=''):
    assert prefix.endswith(const_ending), (prefix, const_ending)
    x = sha256.sha256(prefix)
    return dict(state=x.state,
                extra_data=x.buf[:max(0,
                                      len(x.buf) - len(const_ending))],
                length=x.length // 8)
Exemple #4
0
def check_hash_link(hash_link, data, const_ending=''):
    extra_length = hash_link['length'] % (512//8)

    assert len(hash_link['extra_data']) == max(0, extra_length - len(const_ending))
    extra = (hash_link['extra_data'] + const_ending)[len(hash_link['extra_data']) + len(const_ending) - extra_length:]
    assert len(extra) == extra_length
    return pack.IntType(256).unpack(hashlib.sha256(sha256.sha256(data, (hash_link['state'], extra, 8*hash_link['length'])).digest()).digest())
Exemple #5
0
def prefix_to_hash_link(prefix, const_ending=''):
    assert prefix.endswith(const_ending), (prefix, const_ending)
    x = sha256.sha256(prefix)

    #assert x.buf[:max(0, len(x.buf)-len(const_ending))] == "", (len(x.buf), len(const_ending), x.buf.encode('hex'), const_ending.encode('hex'))
    return dict(state=x.state,
                extra_data=x.buf[:max(0,
                                      len(x.buf) - len(const_ending))],
                length=x.length // 8)
Exemple #6
0
def check_hash_link(hash_link, data, const_ending=''):
    extra_length = hash_link['length'] % (512 // 8)
    assert len(hash_link['extra_data']) == max(
        0, extra_length - len(const_ending))
    extra = (hash_link['extra_data'] +
             const_ending)[len(hash_link['extra_data']) + len(const_ending) -
                           extra_length:]
    assert len(extra) == extra_length
    return pack.IntType(256).unpack(
        hashlib.sha256(
            sha256.sha256(data, (hash_link['state'], extra,
                                 8 * hash_link['length'])).digest()).digest())
Exemple #7
0
def prefix_to_hash_link(prefix, const_ending=''):
    assert prefix.endswith(const_ending), (prefix, const_ending)
    x = sha256.sha256(prefix)
    return dict(state=x.state, extra_data=x.buf[:max(0, len(x.buf)-len(const_ending))], length=x.length//8)
Exemple #8
0
print networks.nets['yacoin'].POW_FUNC(
    data.block_header_type.pack(block_header))

print data.pubkey_hash_to_script2(
    data.address_to_pubkey_hash('YJL3vTFn7m82zQRs7XAXcJXnBNNmZdb1Ty',
                                networks.nets['yacoin'])).encode('hex')

donate = '4104ffd03de44a6e11b9917f3a29f9443283d9871c9d743ef30d5eddcd37094b64d1b3d8090496b53256786bf5c82932ec23c3b74d9f05a6f95a8b5529352656664bac'.decode(
    'hex')
#print data.script2_to_address(donate, networks.nets['bitcoin'])
#print len("c8c6a3c0957d53698da14d7a2c176a133e92fc53".decode('hex'))
#print donate[1:-1].encode('hex')
#print data.pubkey_to_script2(donate[1:-1]).encode('hex')
#print donate[3:-2].encode('hex')
#print data.pubkey_hash_to_script2(donate[3:-2]).encode('hex')
#print len('0241b8aba0994f320a8b438c627dbf31fbdd7dc722dd8418d829d67a9c6e4fd690'.decode('hex'))
#print data.pubkey_to_script2('0241b8aba0994f320a8b438c627dbf31fbdd7dc722dd8418d829d67a9c6e4fd690'
#036fbd9d0a34a569f10b0431c8aeecf74ad796b99838b7272ef35ded130a794f9b
print data.base58_encode(
    'cac8509b8f959d14253e934585c52d04bf4ae21d28e62414a0c71c9fb80a5713'.decode(
        'hex'))
text = sha256.sha256(
    'cac8509f4ae21d28e62414a0c71c9fb80a5713sdfsdfsdfsdfsfsdssssssssss')
print text.state
print text.buf
print text.length
print len(text.buf)
print len('cac8509b8f959d14253e934585c52d04bf4ae21d28e62414a0c71c9fb80a5713')
print len(
    '21029df5832989ca91c766b0c2707eda848854b825efa650ec2d001138a5f8123650ac')
Exemple #9
0
def prefix_to_hash_link(prefix, const_ending=''):
    assert prefix.endswith(const_ending), (prefix, const_ending)
    x = sha256.sha256(prefix)

    #assert x.buf[:max(0, len(x.buf)-len(const_ending))] == "", (len(x.buf), len(const_ending), x.buf.encode('hex'), const_ending.encode('hex'))
    return dict(state=x.state, extra_data=x.buf[:max(0, len(x.buf)-len(const_ending))], length=x.length//8)
Exemple #10
0
timestamp=1367995782,
bits=data.FloatingInteger(0x1e0fffff),
nonce=58004,
)

DONATION_SCRIPT = '01210241b8aba0994f320a8b438c627dbf31fbdd7dc722dd8418d829d67a9c6e4fd69021036fbd9d0a34a569f10b0431c8aeecf74ad796b99838b7272ef35ded130a794f9b02ae'.decode('hex')
print DONATION_SCRIPT[2:35].encode('hex')
print data.pubkey_to_address(DONATION_SCRIPT[2:35], networks.nets['yacoin'])
print networks.nets['yacoin'].POW_FUNC(data.block_header_type.pack(block_header)) 

print data.pubkey_hash_to_script2(data.address_to_pubkey_hash('YJL3vTFn7m82zQRs7XAXcJXnBNNmZdb1Ty', networks.nets['yacoin'])).encode('hex')

donate = '4104ffd03de44a6e11b9917f3a29f9443283d9871c9d743ef30d5eddcd37094b64d1b3d8090496b53256786bf5c82932ec23c3b74d9f05a6f95a8b5529352656664bac'.decode('hex')
#print data.script2_to_address(donate, networks.nets['bitcoin'])
#print len("c8c6a3c0957d53698da14d7a2c176a133e92fc53".decode('hex'))
#print donate[1:-1].encode('hex')
#print data.pubkey_to_script2(donate[1:-1]).encode('hex')
#print donate[3:-2].encode('hex')
#print data.pubkey_hash_to_script2(donate[3:-2]).encode('hex')
#print len('0241b8aba0994f320a8b438c627dbf31fbdd7dc722dd8418d829d67a9c6e4fd690'.decode('hex'))
#print data.pubkey_to_script2('0241b8aba0994f320a8b438c627dbf31fbdd7dc722dd8418d829d67a9c6e4fd690'
#036fbd9d0a34a569f10b0431c8aeecf74ad796b99838b7272ef35ded130a794f9b
print data.base58_encode('cac8509b8f959d14253e934585c52d04bf4ae21d28e62414a0c71c9fb80a5713'.decode('hex'))
text = sha256.sha256('cac8509f4ae21d28e62414a0c71c9fb80a5713sdfsdfsdfsdfsfsdssssssssss')
print text.state
print text.buf
print text.length
print len(text.buf)
print len('cac8509b8f959d14253e934585c52d04bf4ae21d28e62414a0c71c9fb80a5713')
print len('21029df5832989ca91c766b0c2707eda848854b825efa650ec2d001138a5f8123650ac')