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; |