Click here to Skip to main content
Click here to Skip to main content

L33t Tr4nsl4t0r (Leet Translator)

, 7 Jun 2011
Rate this:
Please Sign up or sign in to vote.
Code to change text to Leet.
This is a little funny method that changes text to Leet[^] text. It is a C# version of a website[^] translator.
 
1 th1nk 1t 1s fun t0 us3 4nd m4k3s y0ur br41n w0rk t0 f1nd 0ut wh4t 1t s4ys.
1s 1t us3ful, m4yb3?
1s 1t funny, y3s Smile | :)
 
To use it, just call the static method Translate that takes two parameters: a string that has to be translated to Leet and an integer that tells the degree of translating.
 
// Orginal text
string myText = "Leet Translator";
 
// Translated text
string leetText = Leet.Translate(myText, 30);
 
// Output is: L33t Tr4nsl4t0r
Console.WriteLine(leetText);
 
// Do it again, and change degree to 100.
string leetText = Leet.Translate(myText, 100);
 
// Output is: £337 7®4|\|$£470®
Console.WriteLine(leetText);
 
// Leet class has an extension method to string class that allows us to
// Output is: L33t Tr4nsl4t0r
Console.WriteLine(myText.ToLeet());

Here is the Leet class:

public static class Leet
{
    /// <summary>
    /// Translate text to Leet - Extension methods for string class
    /// </summary>
    /// <param name="text">Orginal text</param>
    /// <param name="degree">Degree of translation (0 - 100%)</param>
    /// <returns>Leet translated text</returns>
    public static string ToLeet(this string text, int degree = 30)
    {
      return Translate(text, degree);
    }
    /// <summary>
    /// Translate text to Leet
    /// </summary>
    /// <param name="text">Orginal text</param>
    /// <param name="degree">Degree of translation (0 - 100%)</param>
    /// <returns>Leet translated text</returns>
    public static string Translate(string text, int degree = 30)
    {
      // Adjust degree between 0 - 100
      degree = degree >= 100 ? 100 : degree <= 0 ? 0 : degree;
      // No Leet Translator
      if (degree == 0)
        return text;
      // StringBuilder to store result.
      StringBuilder sb = new StringBuilder(text.Length);
      foreach (char c in text)
      {
        #region Degree > 0 and < 17
        if (degree < 17 && degree > 0)
        {
          switch (c)
          {
            case 'e': sb.Append("3"); break;
            case 'E': sb.Append("3"); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
        #region Degree > 16 and < 33
        else if (degree < 33 && degree > 16)
        {
          switch (c)
          {
            case 'a': sb.Append("4"); break;
            case 'e': sb.Append("3"); break;
            case 'i': sb.Append("1"); break;
            case 'o': sb.Append("0"); break;
            case 'A': sb.Append("4"); break;
            case 'E': sb.Append("3"); break;
            case 'I': sb.Append("1"); break;
            case 'O': sb.Append("0"); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
        #region Degree > 32 and < 49
        else if (degree < 49 && degree > 32)
        {
          switch (c)
          {
            case 'a': sb.Append("4"); break;
            case 'e': sb.Append("3"); break;
            case 'i': sb.Append("1"); break;
            case 'o': sb.Append("0"); break;
            case 'A': sb.Append("4"); break;
            case 'E': sb.Append("3"); break;
            case 'I': sb.Append("1"); break;
            case 'O': sb.Append("0"); break;
            case 's': sb.Append("$"); break;
            case 'S': sb.Append("$"); break;
            case 'l': sb.Append("£"); break;
            case 'L': sb.Append("£"); break;
            case 'c': sb.Append("("); break;
            case 'C': sb.Append("("); break;
            case 'y': sb.Append("¥"); break;
            case 'Y': sb.Append("¥"); break;
            case 'u': sb.Append("µ"); break;
            case 'U': sb.Append("µ"); break;
            case 'd': sb.Append("Ð"); break;
            case 'D': sb.Append("Ð"); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
        #region Degree > 48 and < 65
        else if (degree < 65 && degree > 48)
        {
          switch (c)
          {
            case 'a': sb.Append("4"); break;
            case 'e': sb.Append("3"); break;
            case 'i': sb.Append("1"); break;
            case 'o': sb.Append("0"); break;
            case 'A': sb.Append("4"); break;
            case 'E': sb.Append("3"); break;
            case 'I': sb.Append("1"); break;
            case 'O': sb.Append("0"); break;
            case 'k': sb.Append("|{"); break;
            case 'K': sb.Append("|{"); break;
            case 's': sb.Append("$"); break;
            case 'S': sb.Append("$"); break;
            case 'g': sb.Append("9"); break;
            case 'G': sb.Append("9"); break;
            case 'l': sb.Append("£"); break;
            case 'L': sb.Append("£"); break;
            case 'c': sb.Append("("); break;
            case 'C': sb.Append("("); break;
            case 't': sb.Append("7"); break;
            case 'T': sb.Append("7"); break;
            case 'z': sb.Append("2"); break;
            case 'Z': sb.Append("2"); break;
            case 'y': sb.Append("¥"); break;
            case 'Y': sb.Append("¥"); break;
            case 'u': sb.Append("µ"); break;
            case 'U': sb.Append("µ"); break;
            case 'f': sb.Append("ƒ"); break;
            case 'F': sb.Append("ƒ"); break;
            case 'd': sb.Append("Ð"); break;
            case 'D': sb.Append("Ð"); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
        #region Degree > 64 and < 81
        else if (degree < 81 && degree > 64)
        {
          switch (c)
          {
            case 'a': sb.Append("4"); break;
            case 'e': sb.Append("3"); break;
            case 'i': sb.Append("1"); break;
            case 'o': sb.Append("0"); break;
            case 'A': sb.Append("4"); break;
            case 'E': sb.Append("3"); break;
            case 'I': sb.Append("1"); break;
            case 'O': sb.Append("0"); break;
            case 'k': sb.Append("|{"); break;
            case 'K': sb.Append("|{"); break;
            case 's': sb.Append("$"); break;
            case 'S': sb.Append("$"); break;
            case 'g': sb.Append("9"); break;
            case 'G': sb.Append("9"); break;
            case 'l': sb.Append("£"); break;
            case 'L': sb.Append("£"); break;
            case 'c': sb.Append("("); break;
            case 'C': sb.Append("("); break;
            case 't': sb.Append("7"); break;
            case 'T': sb.Append("7"); break;
            case 'z': sb.Append("2"); break;
            case 'Z': sb.Append("2"); break;
            case 'y': sb.Append("¥"); break;
            case 'Y': sb.Append("¥"); break;
            case 'u': sb.Append("µ"); break;
            case 'U': sb.Append("µ"); break;
            case 'f': sb.Append("ƒ"); break;
            case 'F': sb.Append("ƒ"); break;
            case 'd': sb.Append("Ð"); break;
            case 'D': sb.Append("Ð"); break;
            case 'n': sb.Append("|\\|"); break;
            case 'N': sb.Append("|\\|"); break;
            case 'w': sb.Append("\\/\\/"); break;
            case 'W': sb.Append("\\/\\/"); break;
            case 'h': sb.Append("|-|"); break;
            case 'H': sb.Append("|-|"); break;
            case 'v': sb.Append("\\/"); break;
            case 'V': sb.Append("\\/"); break;
            case 'm': sb.Append("|\\/|"); break;
            case 'M': sb.Append("|\\/|"); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
        #region Degree < 100 and > 80
        else if (degree > 80 && degree < 100)
        {
          switch (c)
          {
            case 'a': sb.Append("4"); break;
            case 'e': sb.Append("3"); break;
            case 'i': sb.Append("1"); break;
            case 'o': sb.Append("0"); break;
            case 'A': sb.Append("4"); break;
            case 'E': sb.Append("3"); break;
            case 'I': sb.Append("1"); break;
            case 'O': sb.Append("0"); break;
            case 's': sb.Append("$"); break;
            case 'S': sb.Append("$"); break;
            case 'g': sb.Append("9"); break;
            case 'G': sb.Append("9"); break;
            case 'l': sb.Append("£"); break;
            case 'L': sb.Append("£"); break;
            case 'c': sb.Append("("); break;
            case 'C': sb.Append("("); break;
            case 't': sb.Append("7"); break;
            case 'T': sb.Append("7"); break;
            case 'z': sb.Append("2"); break;
            case 'Z': sb.Append("2"); break;
            case 'y': sb.Append("¥"); break;
            case 'Y': sb.Append("¥"); break;
            case 'u': sb.Append("µ"); break;
            case 'U': sb.Append("µ"); break;
            case 'f': sb.Append("ƒ"); break;
            case 'F': sb.Append("ƒ"); break;
            case 'd': sb.Append("Ð"); break;
            case 'D': sb.Append("Ð"); break;
            case 'n': sb.Append("|\\|"); break;
            case 'N': sb.Append("|\\|"); break;
            case 'w': sb.Append("\\/\\/"); break;
            case 'W': sb.Append("\\/\\/"); break;
            case 'h': sb.Append("|-|"); break;
            case 'H': sb.Append("|-|"); break;
            case 'v': sb.Append("\\/"); break;
            case 'V': sb.Append("\\/"); break;
            case 'k': sb.Append("|{"); break;
            case 'K': sb.Append("|{"); break;
            case 'r': sb.Append("®"); break;
            case 'R': sb.Append("®"); break;
            case 'm': sb.Append("|\\/|"); break;
            case 'M': sb.Append("|\\/|"); break;
            case 'b': sb.Append("ß"); break;
            case 'B': sb.Append("ß"); break;
            case 'q': sb.Append("Q"); break;
            case 'Q': sb.Append("Q¸"); break;
            case 'x': sb.Append(")("); break;
            case 'X': sb.Append(")("); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
        #region Degree 100
        else if (degree > 99)
        {
          switch (c)
          {
            case 'a': sb.Append("4"); break;
            case 'e': sb.Append("3"); break;
            case 'i': sb.Append("1"); break;
            case 'o': sb.Append("0"); break;
            case 'A': sb.Append("4"); break;
            case 'E': sb.Append("3"); break;
            case 'I': sb.Append("1"); break;
            case 'O': sb.Append("0"); break;
            case 's': sb.Append("$"); break;
            case 'S': sb.Append("$"); break;
            case 'g': sb.Append("9"); break;
            case 'G': sb.Append("9"); break;
            case 'l': sb.Append("£"); break;
            case 'L': sb.Append("£"); break;
            case 'c': sb.Append("("); break;
            case 'C': sb.Append("("); break;
            case 't': sb.Append("7"); break;
            case 'T': sb.Append("7"); break;
            case 'z': sb.Append("2"); break;
            case 'Z': sb.Append("2"); break;
            case 'y': sb.Append("¥"); break;
            case 'Y': sb.Append("¥"); break;
            case 'u': sb.Append("µ"); break;
            case 'U': sb.Append("µ"); break;
            case 'f': sb.Append("ƒ"); break;
            case 'F': sb.Append("ƒ"); break;
            case 'd': sb.Append("Ð"); break;
            case 'D': sb.Append("Ð"); break;
            case 'n': sb.Append("|\\|"); break;
            case 'N': sb.Append("|\\|"); break;
            case 'w': sb.Append("\\/\\/"); break;
            case 'W': sb.Append("\\/\\/"); break;
            case 'h': sb.Append("|-|"); break;
            case 'H': sb.Append("|-|"); break;
            case 'v': sb.Append("\\/"); break;
            case 'V': sb.Append("\\/"); break;
            case 'k': sb.Append("|{"); break;
            case 'K': sb.Append("|{"); break;
            case 'r': sb.Append("®"); break;
            case 'R': sb.Append("®"); break;
            case 'm': sb.Append("|\\/|"); break;
            case 'M': sb.Append("|\\/|"); break;
            case 'b': sb.Append("ß"); break;
            case 'B': sb.Append("ß"); break;
            case 'j': sb.Append("_|"); break;
            case 'J': sb.Append("_|"); break;
            case 'P': sb.Append("|°"); break;
            case 'q': sb.Append("¶"); break;
            case 'Q': sb.Append("¶¸"); break;
            case 'x': sb.Append(")("); break;
            case 'X': sb.Append(")("); break;
            default: sb.Append(c); break;
          }
        }
        #endregion
      }
      return sb.ToString(); // Return result.
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kim Togo
Software Developer Miralix
Denmark Denmark
Has worked as a programmer since 1999, starting with C++/MFC, Java, PHP and MySQL. Now it is all about C# (my favorite programming language), MS SQL, Azure and Xamarin (iOS/Android/WP8)
 
My primary work is to create applications that interacts with PABC/PBX, Microsoft Lync / UCMA.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
General7h1$ 1$ jµ$7 $0 (00£ 7h4n|{$! PinmemberSeth00716-Jun-11 5:27 
GeneralRe: 1'm gl4d y0u l1k3 1t :-) PinmemberKim Togo16-Jun-11 5:30 
1'm gl4d y0u l1k3 1t Smile | :)
GeneralRe: Check out <a href="http://www.google.com/webhp?hl=xx-hacker"... PinmemberKim Togo16-Jun-11 5:33 
GeneralReason for my vote of 5 I just like it PinmemberFDW7-Jun-11 8:13 
GeneralRe: Thanks :-) PinmemberKim Togo7-Jun-11 9:54 
GeneralWhen will you show us the decoder? or will that just deleet ... PinmemberFDW7-Jun-11 7:24 
GeneralRe: Decoding Leet text will not give the original text back. Cha... PinmemberKim Togo7-Jun-11 10:00 
GeneralReason for my vote of 5 Good work PinmemberToniyo Jackson7-Jun-11 1:19 
GeneralRe: Thanks Toniyo. It seams that you vote has gone way. PinmemberKim Togo7-Jun-11 10:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 7 Jun 2011
Article Copyright 2011 by Kim Togo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid