Skip to content

Instantly share code, notes, and snippets.

@e7d
Created July 9, 2015 09:20
Show Gist options
  • Save e7d/a4b70e77aa7842eba7a8 to your computer and use it in GitHub Desktop.
Save e7d/a4b70e77aa7842eba7a8 to your computer and use it in GitHub Desktop.
Crypt URI with JavaScript
(function() {
String.prototype.asciiEncode = function() {
var i, result = [];
for (i = 0; i < this.length; i++) {
result.push("%", this.charCodeAt(i).toString(16));
}
return result.join('');
}
String.prototype.cryptUri = function() {
return this.replace(/((?![\w]+:\/\/)[\w\.-]+)/g, function(match) {
return match.asciiEncode();
});
};
})();
"https://e7d.io/".cryptUri(); // https://%65%37%64%2e%69%6f/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment