Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Last active July 7, 2016 09:13
Show Gist options
  • Save netsi1964/8d73e7efb03afb9947224ad0e6a13cac to your computer and use it in GitHub Desktop.
Save netsi1964/8d73e7efb03afb9947224ad0e6a13cac to your computer and use it in GitHub Desktop.
IP => Hash

IP to Hash convertion

These two methods can be used to convert IP addresses to and from a hash value.

See the codepen for instructions.

toIp = function(hash) {
var hash = hash || this;
return hash.split('').map(function(_char) {
return String.fromCharCode(_char.charCodeAt(0) - 17).replace('g', '.');
}).join('');
};
toHash = function(ip) {
var ip = ip || this;
return ip.split('').map(function(_char) {
return String.fromCharCode(_char.charCodeAt(0) + 17).replace('?', 'x');
}).join('');
};
String.prototype.toHash = toHash
String.prototype.toIp = toIp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment