- else
- ircsnprintf(outbuf, HOSTLEN, "%X%X.%s",
- hosthash2, hosthash, ServerInfo.network_name);
+ else if (!strchr(outbuf, '.'))
+ return;
+
+ for (tptr = outbuf; *tptr != '\0'; tptr++)
+ {
+ if (*tptr == ':' || *tptr == '.')
+ {
+ sepcount++;
+ continue;
+ }
+
+ if (ipv6 && sepcount < totalcount / 2)
+ continue;
+
+ if (!ipv6 && sepcount < 2)
+ continue;
+
+ *tptr = chartable[(*tptr + accum) % 20];
+ accum = (accum << 1) | (accum >> 31);
+ }
+}
+
+static void
+do_host_cloak_host(const char *inbuf, char *outbuf)
+{
+ char b26_alphabet[] = "abcdefghijklmnopqrstuvwxyz";
+ char *tptr;
+ uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32);
+
+ rb_strlcpy(outbuf, inbuf, HOSTLEN + 1);
+
+ /* pass 1: scramble first section of hostname using base26
+ * alphabet toasted against the FNV hash of the string.
+ *
+ * numbers are not changed at this time, only letters.
+ */
+ for (tptr = outbuf; *tptr != '\0'; tptr++)
+ {
+ if (*tptr == '.')
+ break;
+
+ if (isdigit(*tptr) || *tptr == '-')
+ continue;
+
+ *tptr = b26_alphabet[(*tptr + accum) % 26];
+
+ /* Rotate one bit to avoid all digits being turned odd or even */
+ accum = (accum << 1) | (accum >> 31);
+ }
+
+ /* pass 2: scramble each number in the address */
+ for (tptr = outbuf; *tptr != '\0'; tptr++)
+ {
+ if (isdigit(*tptr))
+ *tptr = '0' + (*tptr + accum) % 10;
+
+ accum = (accum << 1) | (accum >> 31);
+ }