Last active
June 10, 2018 12:58
-
-
Save jonathanmarvens/6444626 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
( function () { | |
var DEFAULT_ENCODING_BASE = 2; | |
function _properBase( base ) { | |
if ( ! ( base === 2 || base === 16 ) ) { | |
base = DEFAULT_ENCODING_BASE; | |
} | |
return base; | |
} | |
String.prototype.encode = function encode( base ) { | |
var bytes = []; | |
var character_code = null; | |
var string = this; | |
base = _properBase( base ); | |
for ( | |
var | |
a = 0, | |
b = string.length | |
; a < b; a++ | |
) { | |
character_code = string.charCodeAt( a ); | |
bytes.push( character_code.toString( base ) ); | |
} | |
character_code = null; | |
string = null; | |
bytes = bytes.join( "." ); | |
return bytes; | |
}; | |
String.prototype.decode = function decode( base ) { | |
var bytes = null; | |
var character_code = null; | |
var string = this; | |
base = _properBase( base ); | |
bytes = string.split( "." ); | |
string = ""; | |
for ( | |
var | |
a = 0, | |
b = bytes.length | |
; a < b; a++ | |
) { | |
character_code = parseInt( bytes[ a ], base ); | |
string += String.fromCharCode( character_code ); | |
} | |
bytes = null; | |
character_code = null; | |
return string; | |
}; | |
} )(); |
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
!function(){function n(n){return 2!==n&&16!==n&&(n=r),n}var r=2;String.prototype.encode=function(r){var t=[],l=null,o=this;r=n(r);for(var u=0,e=o.length;e>u;u++)l=o.charCodeAt(u),t.push(l.toString(r));return l=null,o=null,t=t.join(".")},String.prototype.decode=function(r){var t=null,l=null,o=this;r=n(r),t=o.split("."),o="";for(var u=0,e=t.length;e>u;u++)l=parseInt(t[u],r),o+=String.fromCharCode(l);return t=null,l=null,o}}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment