0

https://gist.github.com/vivosmith/f0e692d9aedbc39ec8d3eb4651bc107c

I was trying to implement this video in Python 3

But the issue is that, it was implemented in Python 2

So I tried to implement this with binascii instead of encode/decode. However I keep getting a binascii.Error: Odd-length string at line 22.

How to I correct this? Or if this is completely broken, then is there any other libraries that work better for python 3?

1

This is working for me:

import os
import ecdsa
import binascii
import hashlib

private_key = os.urandom(32)
PK_EN = binascii.hexlify(private_key)
print("Your Key" + "  " + str(PK_EN))
PK_CON = binascii.unhexlify(PK_EN)
sk = ecdsa.SigningKey.from_string(PK_CON, curve=ecdsa.SECP256k1)
vk = sk.verifying_key
msg = binascii.hexlify(b'Hello')
sign_msg = sk.sign(msg)
assert vk.verify(sign_msg, msg)

public_key = b'04' + binascii.hexlify(vk.to_string())
print(public_key)

ripemd160 = hashlib.new('ripemd160')

ripemd160.update(hashlib.sha256(binascii.unhexlify(public_key)).digest())

I've changed the way you concatenated the public key with the prefix, and the call to the ripmd160.update, since it was expecting a string, not a Hash object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.