Kjetil's Information Center: A Blog About My Projects

Leetspeak Converter

You can never have access to enough leetspeak converters/generators. That's why I have written one in C. This one works as a filter; reading from standard input and writing to standard output. Some randomization code is included since characters can be written in many different ways.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char *leet[26][5] = {"4", "/\\", "@", "/-\\", "^",
                     "8", "13", "|3", "!3", "(3",
                     "[", "<", "(", "{", "©",
                     ")", "[)", "I>", "|>", "|)",
                     "3", "&", "£", "ë", "[-",
                     "|=", "|#", "/=", NULL, NULL,
                     "6", "9", "(_+", "(y,", "(_-",
                     "#", "/-/", "[-]", "]-[", ")-(",
                     "!", "|", "]", NULL, NULL,
                     "_|", "_/", "</", "(/", NULL,
                     "X", "|<", "|{", NULL, NULL,
                     "1", "1_", "|_", NULL, NULL,
                     "|v|", "]V[", "|\\/", "/\\/\\", "^^",
                     "/\\/", "[\\]", "<\\>", "{\\}", "^/",
                     "0", "()", "[]", "¤", NULL,
                     "|*", "|\"", NULL, "|7", "¶", "þ",
                     "()_", "0_", "<|", NULL, NULL,
                     "|?", "|2", "|^", "12", "®",
                     "5", "$", "z", "§", NULL,
                     "7", "+", "-|-", NULL, NULL,
                     "(_)", "|_|", "v", "L|",
                     "\\/", NULL, NULL, NULL, NULL,
                     "\\/\\/", "vv", "\\|/", "\\^/", "\\V/",
                     "%", "><", "}{", ")(", "*",
                     "j", "`/", "¥", NULL, NULL,
                     "2", ">_", "7_", NULL, NULL};

int main(void)
{
  int c, ci;
  char *cp;

  srandom(time(NULL));

  while ((c = fgetc(stdin)) != EOF) {
    if (c >= 0x41 && c <= 0x5a) { /* A-Z */
      ci = c - 0x41;
      while ((cp = leet[ci][random() % 5]) == NULL);
      fputs(cp, stdout);
    } else if (c >= 0x61 && c <= 0x7a) { /* a-z */
      ci = c - 0x61;
      while ((cp = leet[ci][random() % 5]) == NULL);
      fputs(cp, stdout);
    } else
      fputc(c, stdout);
  }

  return 0;
}
          


1[-37 \V/¤|?|>$ [/\/\/ !3£ &}{|7|^£$z[-) |^/ /-/v{\}I>12ë[)§ ()|= \V/^j5.

Topic: Scripts and Code, by Kjetil @ 07/12-2007, Article Link