Skip to content

Instantly share code, notes, and snippets.

View PoolloverNathan's full-sized avatar

PoolloverNathan

  • 17:45 (UTC -04:00)
View GitHub Profile
@andrewrk
andrewrk / test.js
Created January 1, 2013 08:02
how to generate minecraft hex digests
var crypto = require('crypto');
var assert = require('assert');
function mcHexDigest(str) {
var hash = new Buffer(crypto.createHash('sha1').update(str).digest(), 'binary');
// check for negative hashes
var negative = hash.readInt8(0) < 0;
if (negative) performTwosCompliment(hash);
var digest = hash.toString('hex');
// trim leading zeroes