Skip to content

Instantly share code, notes, and snippets.

@keanulee
Created August 14, 2017 00:44
Show Gist options
  • Save keanulee/7bf9eee30438bdcaeafce721fbd17da8 to your computer and use it in GitHub Desktop.
Save keanulee/7bf9eee30438bdcaeafce721fbd17da8 to your computer and use it in GitHub Desktop.
var crypto = require('crypto'),
shasum = crypto.createHash('sha1');
var fs = require('fs');
function checkHex(hex) {
console.log('searching for', hex);
var buffer = '';
var numLines = 0;
var rs = fs.createReadStream('data/pwned-passwords-1.0.txt');
rs.on('data', function(chunk) {
var lines = (buffer + chunk).split(/\r?\n/g);
buffer = lines.pop();
for (var i = 0; i < lines.length; ++i) {
if (lines[i] === hex) {
console.log('MATCH', lines[i], hex);
}
++numLines;
}
});
rs.on('end', function() {
console.log('Done searching numLines', numLines);
});
}
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
const data = chunk.slice(0, chunk.length - 1);
shasum.update(data);
const hex = shasum.digest('hex');
checkHex(hex.toUpperCase());
}
});
process.stdin.on('end', () => {
process.stdout.write('end');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment