# Fully understanding bitcoin transcation verifying and secp256k1

Hello fellow cryptographers.

I have spent last few days trying to understand and find a way to generate secp256k1 private and public keys from scratch, but i failed.

I have seen tons of videos and read tons of pdfs about it but I still can't understand how to implement it even in pseudocode.

r = Random
k = PrivateKey (64bit hex string that should safely be generated from r and hashed)
K = PublicKey
G =

K = k * G



Now i know G has x,y and that 04 at the beginning means that its in uncompressed form. But i am confused with the way I should multiply k and G, since whenever I tried turning them into decimal values multiplying them and then encoding them into hex afterwards I would get wrong results.

Now lets say I have K(public key).

How would I go about encrypting an message, and then proving that I can decrypt it?

I really look forward to hearing your answers :D

• Elliptic curves aren't used for encryption. They're used for the exchange of symmetric keys (via ECDH) or for signatures (what Bitcoin uses). No encryption involved. It's possible to instantiate ElGamal with an elliptic curve, but that's basically never done in practice because asymmetric encryption is pretty useless compared to hybrid encryption. May 11, 2021 at 18:14
• Also, why are you trying to use decimal values for anything here? That's unnecessary complication. Programming questions are off-topic on this site (that's what StackOverflow is for), unless related to particular implementation details specific to cryptography (side-channel attacks and such). But you have some general questions about how ECC works (I think you're trying to ask why a public key is k*G, how to use ECC to transfer a message in secret, and maybe some other questions). It'd be better if you asked one question per post, each about the math and concepts you're confused about. May 11, 2021 at 18:19
• Finally, Cloudflare have a good primer on ECC: blog.cloudflare.com/… May 11, 2021 at 18:25
• Thx this helps a lot you can close the question :). May 11, 2021 at 18:55
• You might have the same conceptual problem Problem on Elliptic Curve Point Doubling, Can you tell me why doing scalar multiplication of a point on a Elliptic curve over a finite field gets to a point at infinity?. You need the formulas What is the point at infinity on secp256k1 and how to calculate it? to calculate it. Use SageMath,easier. May 11, 2021 at 18:56