Bitcoin Forum
October 22, 2018, 12:58:48 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: I need a source code of WIF checksum checking  (Read 1361 times)
tywors
Sr. Member
****
Offline Offline

Activity: 414
Merit: 250


View Profile
September 17, 2014, 04:38:40 PM
 #1

Hello! I have one problem with this exemple:



I try duplicate this form to my hosting but i can't.  I try convertirn to Base58 but my result is different.  Huh

Any have the source code of this form?    In Java/PHP/etc..

Thanks!  Wink

1540213128
Hero Member
*
Offline Offline

Posts: 1540213128

View Profile Personal Message (Offline)

Ignore
1540213128
Reply with quote  #2

1540213128
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
davec
Newbie
*
Offline Offline

Activity: 39
Merit: 0


View Profile
September 17, 2014, 06:59:53 PM
 #2

It's not for the form, but this is code to encode and decode a WIF written in Go and is used by the btcd suite and fully tested.

https://github.com/conformal/btcutil/blob/master/wif.go

In particular, look at the DecodeWIF function:

DecodeWIF -- https://github.com/conformal/btcutil/blob/master/wif.go#L84-L121
tywors
Sr. Member
****
Offline Offline

Activity: 414
Merit: 250


View Profile
September 17, 2014, 07:22:33 PM
 #3

It's not for the form, but this is code to encode and decode a WIF written in Go and is used by the btcd suite and fully tested.

https://github.com/conformal/btcutil/blob/master/wif.go

In particular, look at the DecodeWIF function:

DecodeWIF -- https://github.com/conformal/btcutil/blob/master/wif.go#L84-L121


Thanks!!  Grin

davec
Newbie
*
Offline Offline

Activity: 39
Merit: 0


View Profile
September 17, 2014, 07:25:05 PM
 #4

Also, here is some Go code to do exactly what's in the screenshot using the btcd suite packages:

package main

import (
   "fmt"
   "github.com/conformal/btcutil"
   "github.com/conformal/btcwire"
)

func main() {
   step1 := "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"
   fmt.Printf("1 - Wallet import format: %s\n", step1)

   step2 := btcutil.Base58Decode(step1)
   fmt.Printf("2 - Converting WIF as Base58 string to byte array: %x\n", step2)

   step3 := step2[:len(step2)-4]
   fmt.Printf("3 - Dropping last 4 checksum bytes from 2: %x\n", step3)

   step5 := btcwire.DoubleSha256(step3)
   fmt.Printf("4/5 - Double SHA-256 hash of 3: %x\n", step5)

   fmt.Printf("6 - First 4 bytes of 5, this is the calculated checksum: %x\n", step5[:4])

   step7 := step2[len(step2)-4:]
   fmt.Printf("7 - Take the last 4 bytes of 2, this is the original checksum: %x\n", step7)
}


And the result of running that program:

1 - Wallet import format: 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
2 - Converting WIF as Base58 string to byte array: 800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d
3 - Dropping last 4 checksum bytes from 2: 800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
4/5 - Double SHA-256 hash of 3: 507a5b8dfed0fc6fe8801743720cedec06aa5c6fca72b07c49964492fb98a714
6 - First 4 bytes of 5, this is the calculated checksum: 507a5b8d
7 - Take the last 4 bytes of 2, this is the original checksum: 507a5b8d
tywors
Sr. Member
****
Offline Offline

Activity: 414
Merit: 250


View Profile
September 18, 2014, 10:46:09 AM
 #5

Also, here is some Go code to do exactly what's in the screenshot using the btcd suite packages:

package main

import (
   "fmt"
   "github.com/conformal/btcutil"
   "github.com/conformal/btcwire"
)

func main() {
   step1 := "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"
   fmt.Printf("1 - Wallet import format: %s\n", step1)

   step2 := btcutil.Base58Decode(step1)
   fmt.Printf("2 - Converting WIF as Base58 string to byte array: %x\n", step2)

   step3 := step2[:len(step2)-4]
   fmt.Printf("3 - Dropping last 4 checksum bytes from 2: %x\n", step3)

   step5 := btcwire.DoubleSha256(step3)
   fmt.Printf("4/5 - Double SHA-256 hash of 3: %x\n", step5)

   fmt.Printf("6 - First 4 bytes of 5, this is the calculated checksum: %x\n", step5[:4])

   step7 := step2[len(step2)-4:]
   fmt.Printf("7 - Take the last 4 bytes of 2, this is the original checksum: %x\n", step7)
}


And the result of running that program:

1 - Wallet import format: 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
2 - Converting WIF as Base58 string to byte array: 800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d
3 - Dropping last 4 checksum bytes from 2: 800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
4/5 - Double SHA-256 hash of 3: 507a5b8dfed0fc6fe8801743720cedec06aa5c6fca72b07c49964492fb98a714
6 - First 4 bytes of 5, this is the calculated checksum: 507a5b8d
7 - Take the last 4 bytes of 2, this is the original checksum: 507a5b8d


Perfect!!

i never dev in GO. One question i need strings.EqualFold("Go", "go") but i need to differentiate between uppercase and lowercase.

Thanks!

davec
Newbie
*
Offline Offline

Activity: 39
Merit: 0


View Profile
September 19, 2014, 10:59:01 PM
 #6

The == and != operators work with strings in a case sensitive fashion in Go.

fmt.Println("Go" == "Go")
fmt.Println("Go" == "go")

Result:

true
false
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!