Created
March 22, 2015 18:49
-
-
Save UdjinM6/f369f88c4b2200477d8f to your computer and use it in GitHub Desktop.
node-x11-hash-algo example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x11 = require('node-x11-hash-algo'); | |
String.prototype.hexEncode = function(){ | |
var hex, i; | |
var result = ""; | |
for (i=0; i<this.length; i++) { | |
hex = this.charCodeAt(i).toString(16); | |
result += ("000"+hex).slice(-4); | |
} | |
return result | |
} | |
//var testString = "Hello world"; // you can get hex from any string to play with hashing | |
//var buffer = new Buffer(testString.hexEncode(), 'hex'); | |
var testStringHex = "0200000040671063c3723d92122b9b3921ab24fc5131286ca407c36e24a502000000000094042ca1ec29fbc59a60a20e2ec37ed5418d39eec78fdd3acbc63b7993085084b8d30e556cb10b1b1e570100"; // actual block 0000000000055c2ee0acc13e97d97097ee47875d4dd286b6549a03e51b08c02c header | |
var buffer = new Buffer(testStringHex, 'hex'); | |
var hashedData = x11.hash(buffer); | |
//console.log(testString, "\n", testString.hexEncode(), "\n", buffer); | |
console.log(testStringHex, "\n", buffer); | |
console.log(hashedData); | |
console.log(hashedData.toString('hex')); // for block header example 2cc0081be5039a54b686d24d5d8747ee9770d9973ec1ace02e5c050000000000 - reversed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment