Skip to content

Instantly share code, notes, and snippets.

@safareli
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safareli/10532642 to your computer and use it in GitHub Desktop.
Save safareli/10532642 to your computer and use it in GitHub Desktop.
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