[Solved] Encrypt ip addresses [closed]


Use Base64. It is widely used and probably already supported on your target framework. Just as base 10 allows only 10 possible glyphs within a character, base 64 allows 64 glyphs per characters. To express a 32 bit number such an an IP address, you would need at a base 64 number that has at least 6 values.

256 x 256 x 256 x 256        => ~4 billion
64 x 64 x 64 x 64 x 64       => ~1 billion  : 5 is not enough so lets use 6
64 x 64 x 64 x 64 x 64 x 64  => ~69 billion : it fits and there is still some headroom

This solution fits your 6 characters requirement. If you drop that requirement though, you could simply xor the original value using a 32 bit symmetrical key. This is crude, but strong enough to obfuscate the IP address if there isn’t any patterns in the data you are transferring (like if the IP always starts with 192.168). It is also susceptible to all zeros or all ones attacks.

IP address    => 1100 0000 1010 1000 0000 0000 0000 0001 <= 192.168.0.1
symmetric key => 1011 1101 0101 1010 1011 1101 0101 1010 <= 189.90.189.90
xor result    => 0111 1101 1111 0010 1011 1101 0101 1011 <= 125.242.189.91

If you simply xor the address again with the same key, you will end up with the original address again. As you can see, the third element leaks the key because xor simply flips the bits.

solved Encrypt ip addresses [closed]