Created
December 4, 2013 18:51
-
-
Save dualbus/7793250 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Input jobs | |
var jobs = [ | |
{'hash': 'abc', 'initial': 0, 'final': 99}, | |
{'hash': 'abc', 'initial': 100, 'final': 199}, | |
{'hash': 'abc', 'initial': 200, 'final': 299}, | |
..., | |
]; | |
// Task definition | |
var task = function(description) { | |
require('hashlib'); | |
var i; | |
for(i = description.initial, i <= description.final; i++) { | |
// number_to_string converts an integer number to the ASCII | |
// string composed of the bytes that make up that number. For | |
// example, 16 -> "\x01\x00", 15 -> "\xff". | |
var try_ = number_to_string(i); | |
if(description.hash == hashlib.md5(try_)) { | |
return {'password': try_, 'hash': description.hash}; | |
} | |
} | |
return null | |
} | |
var filter = function(previous, current) { | |
if(previous != null) { | |
return previous; | |
} | |
return current; | |
} | |
require('google/mapreduce'); | |
require('dbapi'); | |
var url = 'mrs://ctrl0034.googlemapreduce.com:9876'; | |
var api_cred = { key: 'foo', secret: 'bar' }; | |
var db_cred = { key: 'foo', secret: 'bar' }; | |
var controller = google.mapreduce.Controller(url, api_cred); | |
controller.send({ | |
input: jobs, | |
map: task, | |
reduce: filter, | |
finished: function(result) { | |
if(result == null) { | |
return false; | |
} | |
var db = dbapi.connect('pgs://dualbus.me', db_cred); | |
var st = db.prepare( | |
'insert into passwords (password, hash) values (?, ?);' | |
); | |
st.execute(result.password, result.hash); | |
st.close(); | |
db.close(); | |
return true; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment