예제 #1
0
파일: segwit.py 프로젝트: cryptotafkar/Halo
def segwit_multisign(tx, i, script, pk, amount, hashcode=SIGHASH_ALL, separator_index=None):
    wscript = segwit_strip_script_separator(script, index=separator_index)
    signing_tx = segwit_signature_form(tx, i, wscript, amount, hashcode=hashcode)
    hashed_signing_tx = hashlib.sha256(hashlib.sha256(binascii.unhexlify(signing_tx)).digest()).hexdigest()
    rawsig = ecdsa_raw_sign(hashed_signing_tx, pk)
    sig = der_encode_sig(*rawsig)+encode(hashcode, 16, 2)
    return sig
예제 #2
0
def hello_world():
    errors = []
    if 'image' not in request.files:
        errors.append('no image')
    if 'text' not in request.form:
        errors.append('no text')
    if 'key' not in request.form:
        errors.append('no key')
    if len(errors) > 0:
        return jsonify({'status': 400, 'errors': errors}), 400
    img_data = np.array(Image.open(request.files['image']).convert('RGBA'))
    encode(img_data, request.form['text'], request.form['key'])
    image = Image.fromarray(img_data, 'RGBA')
    img_io = BytesIO()
    image.save(img_io, format='PNG')
    img_io.seek(0)
    return jsonify({
        'status': 200,
        'data': base64.b64encode(img_io.getvalue()).decode('utf-8')
    }), 200
예제 #3
0
파일: segwit.py 프로젝트: cryptotafkar/Halo
def segwit_sign(tx, i, priv, amount, hashcode=SIGHASH_ALL, script=None, separator_index=None):
    i = int(i)
    txobj = tx if isinstance(tx, dict) else deserialize(tx)
    if not isinstance(tx, dict) and ((not is_python2 and isinstance(re, bytes)) or not re.match('^[0-9a-fA-F]*$', tx)):
        return binascii.unhexlify(sign(binascii.hexlify(tx), i, priv))
    if len(priv) <= 33:
        priv = binascii.hexlify(priv)
    pub = privkey_to_pubkey(priv)
    address = pubkey_to_address(pub)
    wscript = mk_pubkey_script(address) if not script else script
    stripped_script = segwit_strip_script_separator(wscript, separator_index)
    signing_tx = segwit_signature_form(tx, i, stripped_script, amount, hashcode=hashcode)
    rawsig = ecdsa_raw_sign(hashlib.sha256(hashlib.sha256(binascii.unhexlify(signing_tx)).digest()).hexdigest(), priv)
    sig = der_encode_sig(*rawsig)+encode(hashcode, 16, 2)
    if (hashcode & SIGHASH_FORKID):
        txobj['ins'][i]['script'] = serialize_script([sig, pub if not script else script])
    else:
        txobj['ins'][i]['txinwitness'] = [sig, pub if not script else script]
    return serialize(txobj)
예제 #4
0
 def testReverse(self): 
     msg = sidewalk
     coded = main.encode(sidewalk, 2)
     self.assertEqual(sidewalk, main.encode(coded, -2))
예제 #5
0
 def testNonalpha(self): 
     msg = sidewalk
     coded = main.encode(msg)
     self.assertEqual(coded[69], ",")
     self.assertEqual(coded[-1], ".")
예제 #6
0
 def testDefault(self): 
     msg = sidewalk
     coded = main.encode(msg)
     test = "gurer vf n cynpr jurer gur fvqrjnyx raqf"
     self.assertEqual(coded[:len(test)], test)
예제 #7
0
 def testOne(self):
     msg = sidewalk
     coded = main.encode(msg, 1)
     test = "uifsf jt b qmbdf xifsf uif tjefxbml foet"
     self.assertEqual(coded[:len(test)], test)
예제 #8
0
 def testLarge(self):
     msg = hamlet
     coded = main.encode(msg, 2)
     self.assertTrue(True)
예제 #9
0
파일: test.py 프로젝트: yt1n4/python-99
 def test(self):
     self.assertEqual(
         main.encode([1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5]),
         [[4, 1], [1, 2], [2, 3], [2, 1], [1, 4], [4, 5]])
예제 #10
0
 def testDefault(self):
     msg = sidewalk
     coded = main.encode(msg)
     test = "gurer vf n cynpr jurer gur fvqrjnyx raqf"
     self.assertEqual(coded[:len(test)], test)
예제 #11
0
import hashlib, sys, base64
import main

if __name__ == "__main__":
    for line in sys.stdin.readlines():
        print(main.encode(line.strip()))
예제 #12
0
 def test_encoding(self):
     assert "JrroYvahk" == main.encode("WeebLinux")
예제 #13
0
 def OnButton2Click(self):
     self.label2Variable.set(main.encode(self.entry2Variable.get()))
예제 #14
0
 def test(self):
     self.assertEqual(encode("scout", 1939), [20, 12, 18, 30, 21])
     self.assertEqual(encode("masterpiece", 1939),
                      [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8])
예제 #15
0
파일: test.py 프로젝트: jeefies/chencode
import main

r = main.encode('some hello')
print(r)
print(main.decode(r))

r = main.encode('我数据库好地方')
print(r)
print(main.decode(r))

r = main.encode('142857')
print(r)
print(main.decode(r))

r = main.encode(r)
print(r)
print(main.decode(r))

code = main.encode('你好啊,123')
print(code)
imdata = main.to_imdata_pixels(code)
print(imdata)
print(main.decode(main.origin_imdata_pixels(imdata)))
예제 #16
0
 def testLarge(self): 
     msg = hamlet
     coded = main.encode(msg, 2)
     self.assertTrue(True)
예제 #17
0
 def testOne(self): 
     msg = sidewalk
     coded = main.encode(msg, 1)
     test = "uifsf jt b qmbdf xifsf uif tjefxbml foet"
     self.assertEqual(coded[:len(test)], test)
예제 #18
0
 def testNonalpha(self):
     msg = sidewalk
     coded = main.encode(msg)
     self.assertEqual(coded[69], ",")
     self.assertEqual(coded[-1], ".")
예제 #19
0
 def testReverse(self):
     msg = sidewalk
     coded = main.encode(sidewalk, 2)
     self.assertEqual(sidewalk, main.encode(coded, -2))
 def test_encode(self):
     self.assertEqual(encode(list),"01011011101111011111")