kevinatlasFull Member
Posts: 25 · Reputation: 253
#1Nov 23, 2017, 12:53 AM
Been digging into Bitcoin and have a question. If you multiply a public key by a private key, you get another public key, right? But what happens if you multiply the same public key by itself? Is that even a thing?
Here's some code I've been working with:
from ecdsa import SECP256k1, VerifyingKey
from ecdsa.ellipticcurve import Point
def public_key_to_scalar(public_key) -> int:
# Converts a public key to an integer scalar.
return int.from_bytes(public_key.to_string(), 'big')
def multiply_public_key_by_scalar(pub_key, scalar) -> Point:
# Multiplies a public key by a scalar.
return pub_key.pubkey.point * scalar
def point_to_hex(point) -> str:
# Converts an elliptic curve point to a hexadecimal string in 0x format.
x_hex = "0x" + format(point.x(), '064x')
y_hex = "0x" + format(point.y(), '064x')
return x_hex, y_hex
# Input public key as a hexadecimal string
input_hex1 = "b84a76136d0c86725a8a305f4a87aeeaa9f44eead621dd1e84d0ea1ad85d82ab" +
"9deccad50c1d1b9575d2fd2223215b5d74e29a87cd7879e343296eb688206713"
# Convert to VerifyingKey object
pub_key1 = VerifyingKey.from_string(bytes.fromhex(input_hex1), curve=SECP256k1)
# Define a scalar (could be a private key or large random integer)
scalar = 0x2 # Example scalar value
# Multiply the public key by the scalar
result_point = multiply_public_key_by_scalar(pub_key1, scalar)
# Convert the result to a hexadecimal string