Last active
August 29, 2015 13:59
-
-
Save safareli/10532642 to your computer and use it in GitHub Desktop.
This file contains 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
String.prototype._toIntArray = function(func){ | |
func = (typeof func == 'undefined') ? function(a){return a;}: func; | |
for (var b = [], i=0; i<this.length;i++) | |
b.push(func(this.charCodeAt(i))); | |
return b; | |
}; | |
Array.prototype._intToString = function(func){ | |
func = (typeof func == 'undefined') ? function(a){return a;}: func; | |
for (var b = '', i=0; i<this.length;i++) | |
b += String.fromCharCode(func(this[i])); | |
return b; | |
}; | |
//usage | |
var somestr = 'dju65eki^*(*%(&$%*%^$hjydfjfcnhcv'; | |
var encodedarr = somestr._toIntArray(function(i){return (i*3-180)*6}); | |
var decodedstr = encodedarr._intToString(function(i){return (i/6+180)/3}); | |
console.log(decodedstr === somestr) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment