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
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
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)
def testReverse(self): msg = sidewalk coded = main.encode(sidewalk, 2) self.assertEqual(sidewalk, main.encode(coded, -2))
def testNonalpha(self): msg = sidewalk coded = main.encode(msg) self.assertEqual(coded[69], ",") self.assertEqual(coded[-1], ".")
def testDefault(self): msg = sidewalk coded = main.encode(msg) test = "gurer vf n cynpr jurer gur fvqrjnyx raqf" self.assertEqual(coded[:len(test)], test)
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)
def testLarge(self): msg = hamlet coded = main.encode(msg, 2) self.assertTrue(True)
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]])
import hashlib, sys, base64 import main if __name__ == "__main__": for line in sys.stdin.readlines(): print(main.encode(line.strip()))
def test_encoding(self): assert "JrroYvahk" == main.encode("WeebLinux")
def OnButton2Click(self): self.label2Variable.set(main.encode(self.entry2Variable.get()))
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])
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)))
def test_encode(self): self.assertEqual(encode(list),"01011011101111011111")