Bitcoin Forum

Bitcoin => BitcoinJ => Topic started by: tyrick on December 03, 2013, 03:03:52 AM



Title: Verifying mrkl root from two children nodes in JAVA
Post by: tyrick on December 03, 2013, 03:03:52 AM
I have a better formatted version of my issue here:
http://bitcoin.stackexchange.com/questions/17676/verifying-mrkl-root-from-two-children-nodes-in-java

I am convinced that there is a JAVA issue with my hexToAscii implementation.

Code:
	public String hexToBin(String hex) {
  StringBuilder sb = new StringBuilder();
  StringBuilder temp = new StringBuilder();
  //49204c6f7665204a617661 split into two characters 49, 20, 4c...
  for(int i = 0; i < hex.length() - 1; i += 2){
      //grab the hex in pairs
      String output = hex.substring(i, (i + 2));
      //convert hex to decimal
      int decimal = Integer.parseInt(output, 16);
      //convert the decimal to character
      temp.append(decimal);
  }
  return sb.toString();
}


Code:
d4 : parse=> Ô
9b : parse=> ›
95 : parse=> •
84 : parse=> „
9c : parse=> œ
87 : parse=> ‡
b8 : parse=> ¸
a4 : parse=> ¤

Why so many blanks? My friend's php implementation (which works) spits out characters for some of those.  Although our string lengths are the same size (32), his contains characters that mine doesn't.  (this results in the sha256 being different as well)

Some expertise would be appreciated here =/



Title: Re: Verifying mrkl root from two children nodes in JAVA
Post by: Mike Hearn on December 04, 2013, 10:57:59 AM
Why are you trying to parse a string from another hex-encoded string? Bitcoin doesn't require such an operation anywhere. If you're trying to verify a merkle tree, bitcoinj already has code to do that.