Post
Topic
Board Development & Technical Discussion
Topic OP
(Same public key) * (Same public key) = Public key possible or not.
by
bjpark
on 15/10/2024, 03:10:21 UTC
Research Bitcoin I have a question. Public key*(private key) = Public key has operation and device. (Same public key) * (Same public key) = Public key
I'd like to know if the second one is possible or not.

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 (should be a valid uncompressed public key)
####Corresponds to the decimal value 0.234
input_hex1 = "b84a76136d0c86725a8a305f4a87aeeaa9f44eead621dd1e84d0ea1ad85d82ab" + \
             "9deccad50c1d1b9575d2fd2223215b5d74e29a87cd7879e343296eb688206713"

# Convert the hexadecimal string to a VerifyingKey object
pub_key1 = VerifyingKey.from_string(bytes.fromhex(input_hex1), curve=SECP256k1)

# Define a valid scalar (could be a private key or a large random integer)
# Corresponds to a private key value of 0.1
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 in 0x format
x_hex, y_hex = point_to_hex(result_point)
print(f"Result of multiplication in hex (x): {x_hex}")
print(f"Result of multiplication in hex (y): {y_hex}")