Created
September 30, 2017 22:09
-
-
Save ceritium/7d0fbdbd88c69ddb66e48cb24fdb653b 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
},{}],349:[function(require,module,exports){ | |
var crypto = require('crypto'); | |
var request = require('request'); | |
var DIRSHA = 2; | |
var FILESHA = 2; | |
var FILEEXTENSION = '.db'; | |
var BUCLE = 1714; | |
var decrypt = function (text, password){ | |
var decipher = crypto.createDecipher('aes-256-cbc',password); | |
var dec = decipher.update(text,'hex','utf8'); | |
dec += decipher.final('utf8'); | |
return dec; | |
} | |
var hash = function (text){ | |
const hash = crypto.createHash('sha256') | |
.update(text) | |
.digest('hex'); | |
return hash; | |
} | |
var bucleHash = function (clau,numero){ | |
var x; | |
var clauTemp = clau; | |
for(x=0; x < numero; x++){ | |
clauTemp = hash(clauTemp); | |
} | |
return clauTemp; | |
} | |
var calcular = function (d, dn, cp, cb){ | |
var dni = d.toUpperCase().replace(/ /g,'').replace(/-/g,''); | |
var data_naixement = dn.toUpperCase().replace(/ /g,'').replace(/-/g,'').replace(/\//g,''); | |
var codi_postal = cp.toUpperCase(); | |
if (dni.length != 6) { | |
console.log("Només necessitem les 5 últimes xifres i la lletra."); | |
} | |
if (data_naixement.length != 8) { | |
console.log("La data de naixement ha de tenir el format AAAAMMDD."); | |
} | |
if (codi_postal.length != 5) { | |
console.log("El codi postal han de ser 5 xifres."); | |
} | |
var key = dni + data_naixement + codi_postal; | |
var firstSha256 = hash(bucleHash(key,BUCLE)); | |
var secondSha256 = hash(firstSha256); | |
var dir = secondSha256.substring(0,DIRSHA); | |
var file = secondSha256.substring(DIRSHA,DIRSHA+FILESHA); | |
var url = window.location.href.replace('/index.html','/'); | |
if ((url.match(/\/es\/donde-votar\//)) || | |
(url.match(/\/nl\/a-on-votar\//)) || | |
(url.match(/\/en\/where-to-vote\//))){ | |
url += '../'; | |
} | |
url += '../db.20170930/' +dir + "/" + file + FILEEXTENSION; | |
request( url, function (error, response, body) { | |
var found = false; | |
if (error){ | |
console.log("Error: " + error); | |
return; | |
} | |
var info = body.split("\n"); | |
info.forEach(function(line){ | |
if (line.substring(0,60) == secondSha256.substring(4)){ | |
var info = decrypt(line.substring(60),firstSha256).split('#'); | |
found = true; | |
cb(info); | |
} | |
}) | |
if (!found) { | |
cb("not-found"); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment