-
-
Save dsamarin/1153832 to your computer and use it in GitHub Desktop.
Fun with v8’s Number#toString bug
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
var fs = require('fs'); | |
var repl = require('repl'); | |
console.log("Loading dictionary..."); | |
var words = fs.readFileSync("/usr/share/dict/american-english-small", "ascii"); | |
var wordlist = {}; | |
var regex = /[a-z]{4,}/g; | |
var match; | |
var word; | |
console.log("Building dictionary..."); | |
while (match = regex.exec(words)) { | |
word = match[0].toLowerCase(); | |
wordlist[word] = true; | |
} | |
var find = function(expr, radix, min) { | |
var regex = new RegExp("[a-z]{"+min+",}", "g"); | |
var num = Number(eval(expr)); | |
var str = num.toString(radix); | |
var matches = str.match(regex); | |
if (!matches) return; | |
var len = matches.length; | |
while (len--) { | |
if (wordlist[matches[len]]) { | |
console.log("Found: ("+expr+").toString("+radix+").match("+regex+")["+len+"]; // '"+matches[len]+"'"); | |
} | |
} | |
} | |
var info = "Use the find() function to scan through all possibilities of hidden words.\nThe arguments are: find(string_eval, radix, minimum_word_length)\n\nIt's best if you loop through as many different numerator/denominator possibilities as you can.\n\tExample: var a = 65535; while (a--) { find ('238/'+a, 33, 6); }\n\nWhen you want to stop it, you might have to kill the running node process with `ps xa | grep node` and then `kill <pid>`.\n\nHave fun!"; | |
console.log("\n"+info); | |
var c = repl.start("find(eval, radix, min)> ").context; | |
c.find = find; | |
c.inc = 0.00000000000001; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment