<p><code>k</code> and <code>n</code> are not values that you calculate. <code>k</code> is randomly generated while <code>n</code> is predefined by the curve parameters.</p>

<p><code>n</code> is the order of the curve <code>G.</code> It is defined by the curve parameters for the secp256k1 curve which are defined here: <a href="http://www.secg.org/sec2-v2.pdf" rel="nofollow noreferrer">http://www.secg.org/sec2-v2.pdf</a>. In those parameters, <code>n = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141</code>.</p>

<p><code>k</code> is a randomly generated integer that is used only once for a signature. It is known as the nonce and acts as a source of randomness. If the same <code>k</code> is used to sign two different messages with the same private key, the private key will be leaked.</p>

CC BY-SA 4.0
2018-09-14T05:39:21.707Z
sorry, I'm still confused with the parameter n, whether the parameter n is the support point FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F or what ???  for example i got R = 0x00656073615d18ef82d884366dfcf8f84fd1a95ee7ae431ad8f23a30f7ecc5489c
S =0x00705324ea8a6f796c9c38df621ee07fd86515308a33e1f5acf2d6ae436c4a67ba
Z=0x00264e4672395b1fe67c9c6a6787ad69490585bc45ee7a046593620b1c0ccafb56 but im can't calculate value K and N and X ?? I've tried many times but can't find the correct value ??                                       thanks for your helping me sir. @AndrewChow
Mas Ndoloxz
CC BY-SA 4.0
2018-09-14T13:41:03.407Z
I already told you what `n` is and it is not that. As I said in my answer, you do not calculate `n` or `k`. `n` is given to you by the parameters for secp256k1, and `k` is randomly generated. You cannot calculate them.
Ava Chow
CC BY-SA 4.0
2018-09-14T14:33:37.100Z
@MasNdoloxz+ as shown in SEC2, the number you quote here is 'p', the modulus of the underlying finite field F_p. Like a,b,G,n it is fixed as part of the definition of the curve and you do not compute it. (All the parameters were actually computed once, decades ago, following the process in SEC1 as modified by the Koblitz constraint, but it's neither necessary nor practical for you to re-do that computation.)
dave_thompson_085
CC BY-SA 4.0
2018-09-18T15:03:43.883Z
@AndrewChow im sorry, im newbie for this, but im always continue to study this. i just want know step by step from zero. so i need teacher for this. sorry my bad english, im from indonesia. one again, the point is prime G = fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f , N = fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 . i need teacher for this thanksyou
Mas Ndoloxz
CC BY-SA 4.0
2018-09-18T15:13:29.077Z
@AndrewChow i need teacher step by step for secp256k1 and recovering PrivateKey used value R S Z this sounds impossible, 
actually I already have a private key, only I want to test it.  I am interested in https://bitcoin.stackexchange.com/questions/25814/ecdsa-signature-and-the-z-value/32546#32546   from this question must be two different messages with the same private key. what about 1 message, can i recover?
Mas Ndoloxz
CC BY-SA 4.0
2018-09-18T15:14:59.860Z
@dave_thompson_085 oke thanksyou for help. but i'm still consufed hehehehe
Mas Ndoloxz
CC BY-SA 4.0
2018-09-18T15:34:21.147Z
G is not that value. It is the point defined in the sec2 pdf I linked in my answer. You cannot recover a private key from the same message signed with different `k` values. That would mean that ECDSA is broken. You can only recover the private key if the same `k` values are used in signing two different messages. As has been said multiple times, `n` is not a value you calculate, it is given to you.
Ava Chow
CC BY-SA 4.0
2018-09-19T02:06:03.970Z
@AndrewChow oke now i'm understand. thanksyou for help
Mas Ndoloxz
CC BY-SA 4.0
2018-09-14T04:41:57.300Z
2018-09-14T04:41:57.300Z
Ava Chow
<p>How to find Value <code>N</code> and <code>K</code> ? I have the values for <code>R</code>, <code>S</code> and <code>Z</code>. </p>

<p>for example these: </p>

<pre><code>BigInteger R =("00d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1"));
BigInteger S =("0044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e"));
BigInteger Z =("00c0e2d0a89a348de88fda08211c70d1d7e52ccef2eb9459911bf977d587784c6e"));
BigInteger X  =("00c477f9f65c22cce20657faa5b2d1d8122336f851a508a1ed04e479c34985bf96"));
</code></pre>

<p>Now, how to get these:</p>

<pre><code>BigInteger K =("007a1a7e52797fc8caaa435d2a4dace39158504bf204fbe19f14dbb427faee50ae"));
BigInteger N =("00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")); 
</code></pre>

<p>How to get the values <code>K</code> and <code>N</code> ?<br>
I am confused about how to calculate it, can somebody tell me how it is done?</p>

<ecdsa>
How to find Values N and K given R,S and Z in ECDSA?
Mas Ndoloxz
# How to find Values N and K given R,S and Z in ECDSA?

(Asked by: username_0 on 2018-09-14)

How to find Value `N` and `K` ? I have the values for `R`, `S` and `Z`.

for example these:

```
BigInteger R =("00d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1"));
BigInteger S =("0044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e"));
BigInteger Z =("00c0e2d0a89a348de88fda08211c70d1d7e52ccef2eb9459911bf977d587784c6e"));
BigInteger X  =("00c477f9f65c22cce20657faa5b2d1d8122336f851a508a1ed04e479c34985bf96"));

```

Now, how to get these:

```
BigInteger K =("007a1a7e52797fc8caaa435d2a4dace39158504bf204fbe19f14dbb427faee50ae"));
BigInteger N =("00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")); 

```

How to get the values `K` and `N` ?  
I am confused about how to calculate it, can somebody tell me how it is done?

**Tags:** ecdsa


---

## 1 answers

### Answer by username_1 on 2018-09-14. Score: 2

`k` and `n` are not values that you calculate. `k` is randomly generated while `n` is predefined by the curve parameters.

`n` is the order of the curve `G.` It is defined by the curve parameters for the secp256k1 curve which are defined here: <http://www.secg.org/sec2-v2.pdf>. In those parameters, `n = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141`.

`k` is a randomly generated integer that is used only once for a signature. It is known as the nonce and acts as a source of randomness. If the same `k` is used to sign two different messages with the same private key, the private key will be leaked.

> **Comments:**
> **username_0**: sorry, I'm still confused with the parameter n, whether the parameter n is the support point FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F or what ???  for example i got R = 0x00656073615d18ef82d884366dfcf8f84fd1a95ee7ae431ad8f23a30f7ecc5489c S =0x00705324ea8a6f796c9c38df621ee07fd86515308a33e1f5acf2d6ae436c4a67ba Z=0x00264e4672395b1fe67c9c6a6787ad69490585bc45ee7a046593620b1c0ccafb56 but im can't calculate value K and N and X ?? I've tried many times but can't find the correct value ??                                       thanks for your helping me sir. @AndrewChow  
> **username_1**: I already told you what `n` is and it is not that. As I said in my answer, you do not calculate `n` or `k`. `n` is given to you by the parameters for secp256k1, and `k` is randomly generated. You cannot calculate them.  
> **username_2**: @username_0+ as shown in SEC2, the number you quote here is 'p', the modulus of the underlying finite field F_p. Like a,b,G,n it is fixed as part of the definition of the curve and you do not compute it. (All the parameters were actually computed once, decades ago, following the process in SEC1 as modified by the Koblitz constraint, but it's neither necessary nor practical for you to re-do that computation.)  
> **username_0**: @AndrewChow im sorry, im newbie for this, but im always continue to study this. i just want know step by step from zero. so i need teacher for this. sorry my bad english, im from indonesia. one again, the point is prime G = fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f , N = fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 . i need teacher for this thanksyou  
> **username_0**: @AndrewChow i need teacher step by step for secp256k1 and recovering PrivateKey used value R S Z this sounds impossible,  actually I already have a private key, only I want to test it.  I am interested in https://bitcoin.stackexchange.com/questions/25814/ecdsa-signature-and-the-z-value/32546#32546   from this question must be two different messages with the same private key. what about 1 message, can i recover?  
> **username_0**: @username_2 oke thanksyou for help. but i'm still consufed hehehehe  
> **username_1**: G is not that value. It is the point defined in the sec2 pdf I linked in my answer. You cannot recover a private key from the same message signed with different `k` values. That would mean that ECDSA is broken. You can only recover the private key if the same `k` values are used in signing two different messages. As has been said multiple times, `n` is not a value you calculate, it is given to you.  
> **username_0**: @AndrewChow oke now i'm understand. thanksyou for help  

---

