Bitcoin Forum
May 26, 2024, 05:48:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 3 »  All
  Print  
Author Topic: Issues with programming, Bitcoin, Private Keys, and Public Keys  (Read 4914 times)
dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 23, 2014, 03:34:53 AM
 #1


http://coliru.stacked-crooked.com/a/74648b16c2692525

That is my C++ code where I'm trying to spit out a bunch of sequential private keys.  I know that's not a good idea, but if my program can't do it sequentially, its not going to work in any other manner either, so, I've got to start somewhere.

This program results in the proper X,Y coordinates for private key 0x03, but 0x04 and 0x05 both have the wrong Y values but proper X values, and 0x06 and on are both wrong X values and Y values.  This whole thing is very confusing and I am not getting it and have already put well over a week into just getting this far in this program (I don't exactly have the greatest knowledge or experience in C++).  Any help anyone could provide from looking at my code would be greatly appreciated.

If this doesn't really belong in this forum, please let me know.
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
June 23, 2014, 09:49:53 PM
 #2

took a quick look.

Why aren't you simply using an ECDSA library?



dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 23, 2014, 09:53:05 PM
 #3

I'm not aware of one.  I had a hell of a time even finding a 256+ bit integer library as it was.  Do you recommend a particular ecdsa library?
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
June 23, 2014, 10:43:29 PM
 #4

I took a look at your code and honestly I am not sure what you are doing.   As pointed out trying to reinvent ECDSA support is probably not a good idea.   There are a number of Bitcoin specific libraries but if you want to drop down a level both bouncy castle and openssl support all the ECDSA functions needed to implement a bitcoin node.
dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 24, 2014, 12:32:43 AM
 #5

Current theory is the only thing wrong with my code is something to do with the inverse function.  My programming abilities are not....all that great.  I would DEFINITELY like to implement opencl as it would run substantially faster to (at least that is my understanding) but I might trip over those ideas even harder than my current dilemmas.  Based upon your suggestions I will look into those things in the meantime though, thank you.
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
June 24, 2014, 01:15:45 AM
 #6

I'm not aware of one.  I had a hell of a time even finding a 256+ bit integer library as it was.  Do you recommend a particular ecdsa library?

no offense but you need to work on your googling skills...

looks like plenty of options.

https://www.google.com/?gws_rd=ssl#q=ECDSA+library+C%2B%2B


DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
June 24, 2014, 01:39:31 AM
 #7

Current theory is the only thing wrong with my code is something to do with the inverse function.  My programming abilities are not....all that great.  I would DEFINITELY like to implement opencl as it would run substantially faster to (at least that is my understanding) but I might trip over those ideas even harder than my current dilemmas.  Based upon your suggestions I will look into those things in the meantime though, thank you.

If your programming skills are "not all that great" I would strongly recommend not trying to implement the nuts and bolts of low level crypto.  Even working with high level bitcoin specific libraries (like bitcoinj for java) can be a challenge and using libraries like that all the low level plumbing is abstracted away.   This isn't to say you shouldn't ever build a crypto library but to start there but it would be like someone deciding they want to make a video game and despite having limited programming skills accepting nothing less than writing it all in assembly language so it is optimized.

As for using OpenCL for acceleration I am pretty sure it would be a decelerator.  I would recommend a lot of reading (both wiki and the bitcoin core source code) about how Bitcoin works.  Verification of transactions and blocks is almost never CPU limited.   The disk (IO not capacity) and network bandwidth are more significant bottlenecks, after that is probably memory space (although luckily RAM is dirt cheap), far behind that would probably be disk capacity (especially for higher performance disks like SSD), and then way way way behind that would be processing power.
dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 24, 2014, 05:32:01 AM
 #8

jonald_fyookball, I didn't say I had searched for that in particular.  I hadn't googled it at that time.  I hadn't considered that phrasing or consider the existence of something as simple as an "ECDSA library".

DeathandTaxes, I do not doubt the accuracy of your analogy, but to the extent I can piece things together, I intend to continue.  Your references to speed are accurate.  Though when my processing power is bottlenecked by my SSD I also have RAMDisk and can run the entire operation from RAM if I need too, though my bottleneck has actually been the processing.

If anyone can make sense of:

def inverse(x, p):
"""
Calculate the modular inverse of x ( mod p )
the modular inverse is a number such that:
(inverse(x, p) * x) % p == 1
you could think of this as: 1/x
"""
inv1 = 1
inv2 = 0
while p != 1 and p!=0:
inv1, inv2 = inv2, inv1 - inv2 * (x / p)
x, p = p, x % p
 
return inv2

Which is in Python, it would solve my dilemma.  The commas don't make sense to me (IE: "How can a comma work with the equal sign").  That seems to be the part of my program which doesn't function correctly.  Yes, my code has that as well; that's the only part of my code I don't understand piece for piece (as I had to copy and paste that part).  All I'm really trying to do is to get this code to work.  This code should just spit out the public key for addresses represented by the number 4 through the number 10.
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
June 24, 2014, 02:03:39 PM
 #9

see this:

http://stackoverflow.com/questions/17818092/unpacking-strange-commas-in-python

dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 25, 2014, 05:01:48 AM
 #10

Thanks jonald_fyookball, I checked that out.  Turns out that wasn't enough to get it fully going.  Currently researching how to do the modular arithmetic from scratch, its basically the next step.
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
June 25, 2014, 10:52:27 AM
 #11

If the man wants to reimplement something, let him. That is how he is going to learn.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 25, 2014, 09:18:43 PM
 #12

Even if what I'm doing fully fits the definition of "reimplementation", It doesn't sound so bad due to the following:

All of us are trusting Bitcoin, the programming, the algorithms, etc.  I think it stands to reason that we have nothing to lose by better understanding the equations as fundamentally as we really can.  What if one in a million people notices something..."wrong" with it?  That's kind of one of the very points of "open source".  Anyone who wishes to verify the coding is permitted and able to do so.  Obviously understanding it is another matter, but with posts like mine, we may be able to assist people in doing just that.
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
June 25, 2014, 09:46:25 PM
 #13

Even if what I'm doing fully fits the definition of "reimplementation", It doesn't sound so bad due to the following:

All of us are trusting Bitcoin, the programming, the algorithms, etc.  I think it stands to reason that we have nothing to lose by better understanding the equations as fundamentally as we really can.  What if one in a million people notices something..."wrong" with it?  That's kind of one of the very points of "open source".  Anyone who wishes to verify the coding is permitted and able to do so.  Obviously understanding it is another matter, but with posts like mine, we may be able to assist people in doing just that.
You'll have to excuse Death and Taxes's god complex, he likes to butt in conversations and push his own views onto people(i.e discourage them from reimplementing stuff).

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
June 25, 2014, 10:13:28 PM
 #14

If the man wants to reimplement something, let him. That is how he is going to learn.

I agree... let him code it if he wants to!

Gotta say though, I don't agree at all about DeathandTaxes having any kind
of superiority complex.  I've been in several conversations
with him, and read many of his posts, and I've never seen him talk
down to anyone.

dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 26, 2014, 01:57:17 AM
 #15

Appreciate the support.  Though I have provided a large portion of the necessary program for people to understand some of the bitcoin equations...  I wouldn't mind some additional input either. 

http://rosettacode.org/wiki/Modular_inverse

Supposedly shows the coding for C++ for modular multiplicative inverse (which is my "mul_inv" function).  Mine is basically the same equation but the results are not what they are supposed to be.  If anyone can gleen any insight on that and how, maybe, I need to modify it, I'd really appreciate it.  Once this is solved it could assist anyone in understanding this stuff....including (and, perhaps, especially) myself.

This whole dilemma arises because with the 512 int variables, one cannot divide them normally in C++ as C++ and these particular integers do not convert into decimals, so one has to work with them solely as integers (which is kind of a pain).
dalydir (OP)
Member
**
Offline Offline

Activity: 63
Merit: 10


View Profile
June 26, 2014, 02:40:56 AM
 #16

the gunpowder treason and plot, i can see no reason why the fifth of november should ever be forgot.

sorry, couldn't resist.
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
June 26, 2014, 04:21:32 AM
 #17

Appreciate the support.  Though I have provided a large portion of the necessary program for people to understand some of the bitcoin equations...  I wouldn't mind some additional input either. 

http://rosettacode.org/wiki/Modular_inverse

Supposedly shows the coding for C++ for modular multiplicative inverse (which is my "mul_inv" function).  Mine is basically the same equation but the results are not what they are supposed to be.  If anyone can gleen any insight on that and how, maybe, I need to modify it, I'd really appreciate it.  Once this is solved it could assist anyone in understanding this stuff....including (and, perhaps, especially) myself.

This whole dilemma arises because with the 512 int variables, one cannot divide them normally in C++ as C++ and these particular integers do not convert into decimals, so one has to work with them solely as integers (which is kind of a pain).

I really don't have much interest in bogging myself down in low level functions but
With a quick look , seems you are not using the same equation...they are staring off
Defining r as a mod b, and I don't see you doing that.

jw!
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
June 26, 2014, 08:33:16 PM
 #18

your code
while (b != 0)

the rosetta code
while (a > 1)

your while loop will terminate for very different reasons.
The keys you got right you must have gotten lucky with
now mind telling me what the heck your doing?

calculating the modular multiplicative inverse, how does that make bitcoin?

I thought bitcoin took a big ulgy number and computed it's sha1.
if the sha1 was less then some other ulgy number called the merkle root then the mining program would say yea!
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
June 26, 2014, 08:52:32 PM
 #19

your code
while (b != 0)

the rosetta code
while (a > 1)

your while loop will terminate for very different reasons.
The keys you got right you must have gotten lucky with
now mind telling me what the heck your doing?

calculating the modular multiplicative inverse, how does that make bitcoin?

I thought bitcoin took a big ulgy number and computed it's sha1.
if the sha1 was less then some other ulgy number called the merkle root then the mining program would say yea!
SHA1? I haven't read the bitcoin protocol in a while, but last I checked it was SHA-256.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
June 26, 2014, 08:53:38 PM
 #20

your code
while (b != 0)

the rosetta code
while (a > 1)

your while loop will terminate for very different reasons.
The keys you got right you must have gotten lucky with
now mind telling me what the heck your doing?

calculating the modular multiplicative inverse, how does that make bitcoin?

I thought bitcoin took a big ulgy number and computed it's sha1.
if the sha1 was less then some other ulgy number called the merkle root then the mining program would say yea!
SHA1? I haven't read the bitcoin protocol in a while, but last I checked it was SHA-256.

Poster is talking nonsense  Wink

Pages: [1] 2 3 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!