Created
December 19, 2011 23:11
-
-
Save 19h/1499348 to your computer and use it in GitHub Desktop.
Short JS Encryption (Custom)
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 e = (function (i, d) { | |
if (null == d || 0 >= d.length) return null; | |
for (var a = "", b = 0; b < d.length; b++) a += d.charCodeAt(b).toString(); | |
var b = Math.floor(a.length / 5), | |
g = parseInt(a.charAt(b) + a.charAt(2 * b) + a.charAt(3 * b) + a.charAt(4 * b) + a.charAt(5 * b), 10), | |
j = Math.ceil(d.length / 2), | |
h = Math.pow(2, 31) - 1; | |
if (2 > g) return null; | |
for (var c = Math.round(1E9 * Math.random()) % 1E8, a = a + c; 10 < a.length;) a = (parseInt(a.substring(0, 10), 10) + parseInt(a.substring(10, a.length), 10)).toString(); | |
for (var a = (g * a + j) % h, e = "", f = "", b = 0; b < i.length; b++) e = parseInt(i.charCodeAt(b) ^ Math.floor(255 * (a / h)), 10), f = 16 > e ? f + ("0" + e.toString(16)) : f + e.toString(16), a = (g * a + j) % h; | |
for (c = c.toString(16); 8 > c.length;) c = "0" + c; | |
return f + c | |
}); console.log(e("He is blue blonde \u00fc\u00e4\u00e4\u00e4\u00e4\u00e4\u00e4", "Ksnad")); | |
// OR THE CUT&PASTE CODE // | |
console.log(function(i,d){if(null==d||0>=d.length)return alert("Please enter a password with which to encrypt the message."),null;for(var a="",b=0;b<d.length;b++)a+=d.charCodeAt(b).toString();var b=Math.floor(a.length/5),g=parseInt(a.charAt(b)+a.charAt(2*b)+a.charAt(3*b)+a.charAt(4*b)+a.charAt(5*b),10),j=Math.ceil(d.length/2),h=Math.pow(2,31)-1;if(2>g)return alert("Algorithm cannot find a suitable hash. Please choose a different password. \nPossible considerations are to choose a more complex or longer password."), | |
null;for(var c=Math.round(1E9*Math.random())%1E8,a=a+c;10<a.length;)a=(parseInt(a.substring(0,10),10)+parseInt(a.substring(10,a.length),10)).toString();for(var a=(g*a+j)%h,e="",f="",b=0;b<i.length;b++)e=parseInt(i.charCodeAt(b)^Math.floor(255*(a/h)),10),f=16>e?f+("0"+e.toString(16)):f+e.toString(16),a=(g*a+j)%h;for(c=c.toString(16);8>c.length;)c="0"+c;return f+c}("He is blue blonde \u00fc\u00e4\u00e4\u00e4\u00e4\u00e4\u00e4", "Ksnad")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment