Created
September 7, 2009 18:49
-
-
Save antimatter15/182513 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
Ax.textfix = function(input){ | |
var rep = { | |
"0aeb29d5118fddd1ec418529cd0dc4821537c7e2": [11, 18, 43, 21, 174, 26, 52], | |
"25f4401b796865ab8914ca623228d68a1dadbaf6": [7, 5, 17, 48], | |
"c6d04d7c365a117a761392ee409b2ce33ff2214d": [60, 4, 13, 49, 61], | |
"a7f9e699641ad1c12115e8e1455a69faab1ccda7": [25, 33, 9, 2, 10, 41, 32] | |
} | |
var hash = Ax.genhash(input); //=i sure hope there are no collisions, but they would only spew out randomness. | |
if(rep[hash]){ | |
return Ax.hashdict(input, rep[hash]); | |
} | |
return input; | |
} | |
Ax.genhash = function(input){ | |
var magic = '3.1415926535897932384626433827950'; | |
var hash = Ext.ux.Crypto.SHA1.hash(magic+input.toLowerCase()); | |
return hash | |
} | |
Ax.hashdict = function(input, code){ | |
var dict = "", message = "" | |
for(var i = 0; i < code.length; i++){ | |
while(code[i] > dict.length){ | |
var hash = Ext.ux.Crypto.SHA1.hash(":'("+input+dict.length); | |
dict += parseInt(hash,16).toString(36); | |
} | |
message += dict.charAt(code[i]) | |
} | |
return message; | |
} | |
Ax.hashenc = function(input,message){ | |
var dict = "", old = []; | |
for(var i = 0; i < 50; i++){ | |
var hash = Ext.ux.Crypto.SHA1.hash(":'("+input+dict.length); | |
dict += parseInt(hash,16).toString(36); | |
} | |
for(var i = 0; i < message.length; i++){ | |
var l = message.charAt(i), idx= -1, v = -1; | |
while(old.indexOf(idx = dict.indexOf(l, ++v)) != -1){} | |
old.push(idx); | |
} | |
return old; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment