Skip to content

Instantly share code, notes, and snippets.

@RareSkills
Created January 30, 2023 12:19
Show Gist options
  • Save RareSkills/eb51623908f348663cd6a241d9dbf115 to your computer and use it in GitHub Desktop.
Save RareSkills/eb51623908f348663cd6a241d9dbf115 to your computer and use it in GitHub Desktop.
from ecpy.curves import Curve
from sha3 import keccak_256
private_key = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cv = Curve.get_curve('secp256k1')
pu_key = private_key * cv.generator # just multiplying the private key by generator point (EC multiplication)
concat_x_y = pu_key.x.to_bytes(32, byteorder='big') + pu_key.y.to_bytes(32, byteorder='big')
eth_addr = '0x' + keccak_256(concat_x_y).digest()[-20:].hex()
print('private key: ', hex(private_key))
print('eth_address: ', eth_addr)
@smallyunet
Copy link

Now that can calculate the address from the private key, why can't calculate the private key just using the reverse calculation process from the address?

@RareSkills
Copy link
Author

RareSkills commented Feb 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment