# Bitcoin

A peer-to-peer electronic cash payment system.

Created by Satoshi Nakamoto in 2008.

Zebpay(INDIA) – easy to use bitcoin wallet cum exchange

Get bitcoins worth ₹100 free on your first bitcoin buy/sell with referral code 'REF22116769'

# Secp256k1

## Actual calculations:

#### For R = public key pair of private key "2"

```m = 3Gx2 * ((2Gy)p-2 % p)
Rx = m2 - Gx - Gx (mod p)
Ry = m (Gx - Rx) - Gy (mod p)
```

#### For S = public key pair of private key "3"

```m = (Ry - Gy) * ((Rx - Gx)p-2 % p)
Sx = m2 - Gx - Rx (mod p)
Sy = m (Gx - Sx) - Gy (mod p)
```

This is what a python code would look like:

```#create a point class to store co-ordinates
from collections import namedtuple
Point = namedtuple("Point", "x y")
O = 'Origin'

#assign values to the variables
p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
a = 0
b = 7
G = Point(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798, 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8)

#calculate R
m = (3 * G.x**2) * pow((2 * G.y), p-2, p)
x = ((m**2) - G.x - G.x) % p
y = (m * (G.x - x) - G.y) % p
R = Point(x, y)

#calculate S
m = (R.y - G.y) * pow((R.x - G.x), p-2, p)
x = ((m**2) - G.x - R.x) % p
y = (m * (G.x - x) - G.y) % p
S = Point(x, y)
```
```Output:
>>> hex(R.x)
'0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'
>>> hex(R.y)
'0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a'
>>> hex(S.x)
'0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9'
>>> hex(S.y)
'0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
```

Zebpay(INDIA) – easy to use bitcoin wallet cum exchange

Get bitcoins worth ₹100 free on your first bitcoin buy/sell with referral code 'REF22116769'