Laden...

string -> 1337: Konvertierung in Leet-Schrift

Erstellt von gelöschtem Konto vor 14 Jahren Letzter Beitrag vor 14 Jahren 7.490 Views
Gelöschter Account
vor 14 Jahren
string -> 1337: Konvertierung in Leet-Schrift

Hallo Zusammen,

3 klassen, um normale strings in 1337 zu verwandeln 😃

  1. SimpleLeet ist eine klasse die noch relativ lesbaren output liefert
  2. Leet ist eine klasse die schon recht schwer lesbaren output in 1337 liefert, das nur noch von informatikern und freaks gelesen werden kann...
  3. Ultraleet ist was für die nerds unter den freaks 😉

hier ein beispiel:
origianal: "Des einen Glück ist des anderen Pech"
SimpleLeet: "D35 3in3n 91ück i5t d35 4nd323n P3ch"
Leet: "D£? &in£n 6£ück i5t d€5 ?nd3®€n P£ch"
UltraLeet: "Ð3§ €][|1£|V 6||_|3[|< 1?+ 3$ ±//|]£?&|V |>&[]-["

die spezifikation für das mapping habe ich wikipedia entnommen, wobei ich dann selber definiert habe, was davon noch normal und simple ist. ultraleet erfüllt dann aber die komplette spezifikation.


    interface IStringManipulator
    {
        string Manipulate(string toManipulate);
        string Revert(string manipulated);
    }
    /// <summary>
    /// manipulates strings into a simplified leet-speech. this is good readable.
    /// </summary>
    /// <remarks>only several letters are translated into their 1337 number representation</remarks>
    class SimpleLeet : IStringManipulator
    {
        private Dictionary<char, char> m_Mapping = new Dictionary<char, char>();

        public SimpleLeet()
        {
            m_Mapping.Add('A', '4');
            m_Mapping.Add('a', '4');

            m_Mapping.Add('B', '8');
            m_Mapping.Add('b', '8');

            m_Mapping.Add('E', '3');
            m_Mapping.Add('e', '3');

            m_Mapping.Add('g', '9');
            m_Mapping.Add('G', '9');

            m_Mapping.Add('l', '1');
            m_Mapping.Add('L', '1');

            m_Mapping.Add('r', '2');
            m_Mapping.Add('R', '2');

            m_Mapping.Add('s', '5');
            m_Mapping.Add('S', '5');

        }

        /// <summary>
        /// changes the given string into a simplified leet-string
        /// </summary>
        /// <param name="toManipulate">the string to change into 1337</param>
        /// <returns>the 1337 string</returns>
        public string Manipulate(string toManipulate)
        {
            StringBuilder builder = new StringBuilder(toManipulate);
            m_Mapping.Keys.ToList().ForEach(key => builder.Replace(key,m_Mapping[key]));
            Debug.WriteLine(builder.ToString());
            return builder.ToString();
        }

        /// <summary>
        /// tries to revert a 1337 string into its readable origin
        /// </summary>
        /// <param name="manipulated">the 1337 string</param>
        /// <returns>the original string (not every character could be converted in its original)</returns>
        public string Revert(string manipulated)
        {
            StringBuilder builder = new StringBuilder(manipulated);
            m_Mapping.Values.ToList().ForEach(value => builder.Replace(value, m_Mapping.First(pair => pair.Value == value).Key));
            return builder.ToString();
        }
    }
    /// <summary>
    /// this class supports converting of strings into nerdlanguage
    /// </summary>
    class Leet : IStringManipulator
    {
        private readonly Dictionary<char, string[]> m_Mapping = new Dictionary<char, string[]>();
        private readonly Random m_Rand = new Random();

        public Leet()
        {
            m_Mapping.Add('A', new[] {"4", "@", @"/\", @"/-\", "?", "^", "±", "»"});
            m_Mapping.Add('a', new[] {"4", "@", @"/\", @"/-\", "?", "^", "±", "»"});

            m_Mapping.Add('B', new[] {"8", "|3", "ß", "b", "l³", "|>", "13", "I3"});
            m_Mapping.Add('b', new[] {"8", "|3", "ß", "b", "l³", "|>", "13", "I3"});

            m_Mapping.Add('E', new[] {"3", "€", "&", "£", "µ"});
            m_Mapping.Add('e', new[] {"3", "€", "&", "£", "µ"});

            m_Mapping.Add('g', new[] {"6", "&", "9"});
            m_Mapping.Add('G', new[] {"6", "&", "9"});

            m_Mapping.Add('l', new[] {"1", "|_", "£", "|", "][_"});
            m_Mapping.Add('L', new[] {"1", "|_", "£", "|", "][_"});

            m_Mapping.Add('r', new[] {"2", "|2", "1²", "®", "?", "O"});
            m_Mapping.Add('R', new[] {"2", "|2", "1²", "®", "?", "O"});

            m_Mapping.Add('s', new[] {"5", "$", "§", "?", "]", "_"});
            m_Mapping.Add('S', new[] {"5", "$", "§", "?", "]", "_"});

        }

        /// <summary>
        /// changes the given string into a nearly readable leed-string
        /// </summary>
        /// <param name="toManipulate">the string to change into advanced 1337</param>
        /// <returns>the 1337 string</returns>
        public string Manipulate(string toManipulate)
        {
            StringBuilder builder = new StringBuilder();
            foreach (char c in toManipulate)
            {
                if (!m_Mapping.ContainsKey(c))
                {
                    builder.Append(c);
                    continue;
                }

                builder.Append(m_Mapping[c][m_Rand.Next(0, m_Mapping[c].Length - 1)]);
            }
            Debug.WriteLine(builder.ToString());
            return builder.ToString();
        }

        /// <summary>
        /// tries to revert a 1337 string into its readable origin
        /// </summary>
        /// <param name="manipulated">the 1337 string</param>
        /// <returns>the original string (not every character could be converted in its original)</returns>
        public string Revert(string manipulated)
        {
            StringBuilder builder = new StringBuilder(manipulated);
            m_Mapping.Values.ToList().ForEach(stringarr => stringarr.ToList().ForEach(value => builder.Replace(value, m_Mapping.First(pair => pair.Value.Contains(value)).Key.ToString())));
            return builder.ToString();
        }
    }
    /// <summary>
    /// this class supports converting of strings into nerd-language... this is no more readable by healthy humans
    /// </summary>
    class UltraLeet : IStringManipulator
    {
        private readonly Dictionary<string, string[]> m_Mapping = new Dictionary<string, string[]>();
        private readonly Random m_Rand = new Random();

        public UltraLeet()
        {
            m_Mapping.Add("A", new[] {"4", "@", @"/\", @"/-\", "?", "^", "±", "»"});
            m_Mapping.Add("B", new[] {"8", "|3", "ß", "b", "l³", "|>", "13", "I3"});
            m_Mapping.Add("C", new[] {"(", "[", "<", "©", "¢"});
            m_Mapping.Add("D", new[] {"|)", "|]", "Ð", "", "1)"});
            m_Mapping.Add("E", new[] {"3", "€", "&", "£", "µ"});
            m_Mapping.Add("F", new[] {"|=", "PH", "|*|-|", "|\"", "ƒ", "l²"});
            m_Mapping.Add("G", new[] {"6", "&", "9"});
            m_Mapping.Add("H", new[] {"4", "|-|", "#", "}{", "]-[", "/-/"});
            m_Mapping.Add("I", new[] {"!", "1", "|", "][", "É"});
            m_Mapping.Add("J", new[] {"_|", "¿"});
            m_Mapping.Add("K", new[] {"|<", "|{", "|(", "X"});
            m_Mapping.Add("L", new[] {"1", "|_", "£", "|", "][_"});
            m_Mapping.Add("M", new[] {"/\\/\\", "/v\\", "|V|", "]V[", "|\\/|", "AA", "[]V[]", "|11", "/|\\", "^^", "(V)", "|Y|"});
            m_Mapping.Add("N", new[] {"|\\|", "/\\/", "/V", "|V", "/\\/", "|1", "2", "?", "(\\)", "11"});
            m_Mapping.Add("O", new[] {"0", "9", "()", "[]", "*", "°", "<>", "ø", "{[]}"});
            m_Mapping.Add("P", new[] {"|°", "p", "|>", "|*", "[]D", "][D", "|²", "|?", "|D"});
            m_Mapping.Add("Q", new[] {"0_", "0,"});
            m_Mapping.Add("R", new[] {"2", "|2", "1²", "®", "?", "O"});
            m_Mapping.Add("S", new[] {"5", "$", "§", "?", "]", "_"});
            m_Mapping.Add("T", new[] {"7", "+", "†", "']['", "|"});
            m_Mapping.Add("U", new[] {"|_|", "µ", "[_]", "v"});
            m_Mapping.Add("V", new[] {"\\/", "|/", "\\|", "\\'"});
            m_Mapping.Add("W", new[] {"\\/\\/", "VV", "\\A/", "\\'", "uu", "\\^/", "\\|/"});
            m_Mapping.Add("X", new[] {"><", ")(", "}{", "%", "?", "×", "]["});
            m_Mapping.Add("Y", new[] {"`/", "°/", "9", "¥"});
            m_Mapping.Add("Z", new[] {"z", "2", "\"/_"});
            m_Mapping.Add("Ä", new[] {"43", "°A°"});
            m_Mapping.Add("Ö", new[] {"03", "°O°"});
            m_Mapping.Add("Ü", new[] {"|_|3", "°U°"});
        }

        /// <summary>
        /// changes the given string into a nerd-like leet-string
        /// </summary>
        /// <param name="toManipulate">the string to change into ulimative unreadable 1337</param>
        /// <returns>the 1337 string</returns>
        public string Manipulate(string toManipulate)
        {
            StringBuilder builder = new StringBuilder();
            foreach (char c in toManipulate.ToUpper())
            {
                if(!m_Mapping.ContainsKey(c.ToString()))
                {
                    builder.Append(c);
                    continue;
                }

                builder.Append(m_Mapping[c.ToString()][m_Rand.Next(0, m_Mapping[c.ToString()].Length - 1)]);
            }
            Debug.WriteLine(builder.ToString());
            return builder.ToString();
        }

        /// <summary>
        /// tries to revert a 1337 string into its readable origin
        /// </summary>
        /// <param name="manipulated">the 1337 string</param>
        /// <returns>the original string (only some character could be converted in its original) do not expect something like the original...</returns>
        public string Revert(string manipulated)
        {
            StringBuilder builder = new StringBuilder(manipulated);
            m_Mapping.Values.ToList().ForEach(stringarr => stringarr.ToList().ForEach(value => builder.Replace(value, m_Mapping.First(pair => pair.Value.Contains(value)).Key)));
            return builder.ToString();
        }
    }

Schlagwörter: leet, 1337, convert, string

S
178 Beiträge seit 2009
vor 14 Jahren

Coole Sache, sowas hab ich mal in Basic gemacht.

Aber ein Hinweis: Die Sprache heißt Leet mit t und nicht mit d!
http://de.wikipedia.org/wiki/Leet

Gelöschter Account
vor 14 Jahren

Aber ein Hinweis: Die Sprache heißt Leet mit t und nicht mit d!

oha. danke für den hinweis. ich lass es dennoch mal so wie es ist.

=)

5.942 Beiträge seit 2005
vor 14 Jahren

Salute Jack

Nett nett, werde ich zwar nie brauchen, aber nett 😃.
Jedoch hat mir <IEnumerable>.ToList().ForEach(.... in den Augen richtig gebrannt.

Gruss Peter

--
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland 2007 - 2011

Gelöschter Account
vor 14 Jahren

Hallo Peter Bucher,

Jedoch hat mir <IEnumerable>.ToList().ForEach(.... in den Augen richtig gebrannt.

mir am anfang auch aber es ist in wirklichkeit ein <ICollection<T>>.ToList().ForEach(.... , was den aufwand reduziert, da das eine sonderbehandlung im konstruktor von List<T>(IEnumerable) hat.

5.942 Beiträge seit 2005
vor 14 Jahren

Salute Jack

Das macht doch keinen Unterschied und ist irgendwie unrelevant und zu low-level.
Mir macht das in den Augen weh, das du ein List<T> hernimmst, so kopierst und schlussendlich etwas machst, was du auch direkt machen kannst.

Gruss Peter

--
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland 2007 - 2011

Gelöschter Account
vor 14 Jahren

Das macht doch keinen Unterschied

doch 😃
damit reduziert sich der aufwand erheblich.

das problem ist, das es keine extensionmethode für IEnumerable gibt, die einfach nur ein ForEach macht.

aber ja ich hätte es optimalerweise in ein konventionelles foreach-konstrukt packen sollen.

5.942 Beiträge seit 2005
vor 14 Jahren

Salute Jack

doch 😃
damit reduziert sich der aufwand erheblich.

Für einen Aufruf, ne.

Für mehrere, klar. Count ist bekannt und der Array muss nicht neu dimensioniert werden.

das problem ist, das es keine extensionmethode für IEnumerable gibt, die einfach nur ein ForEach macht.

aber ja ich hätte es optimalerweise in ein konventionelles foreach-konstrukt packen sollen.

Entweder foreach nutzen oder eine Extensionmethod schreiben und dazupacken, sind 4 Zeilen.

Es geht aber - wie so häufig - nicht primär um Performance, mir hier überhaupt nicht, sondern um die Lesbarkeit sowie, das es mit einfacheren Mitteln genau so geht.

Gruss Peter

--
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland 2007 - 2011

1.820 Beiträge seit 2005
vor 14 Jahren

Hallo,

endlich mal ein vernünftiger Vorschlag, wie man Passwörter unleserlich im Quellcode speichern kann 😉

Nobody is perfect. I'm sad, i'm not nobody 🙁

Gelöschter Account
vor 14 Jahren

vorsicht... das "revert" funktioniert nur teilweise bis fast garnicht 😉

aber die klassen eigenen sich sehr gut um nervige leute im ICQ abzuwimmeln 😁

1.820 Beiträge seit 2005
vor 14 Jahren

Hallo,

vorsicht... das "revert" funktioniert nur teilweise bis fast garnicht 😉

meine Aussage würde ja durch ein mögliches revert ad absurdum geführt werden, weil das Passwort ja dann wieder lesbar gemacht werden könnte.

Aber dein 😉 lässt mich vermuten, dass du genau darauf hinauswolltest ...

Nobody is perfect. I'm sad, i'm not nobody 🙁

Gelöschter Account
vor 14 Jahren

wäre da nciht der zufallsfaktor (zumindest beim ultraleed und beim leed), dann könnte man das tatsächlich dafür verwenden. allerdings könnte man dann auch recht schnell die anzahl der möglkichkeiten herausfinden, die spezifikationsbedingt nciht gerade vielfältig wären.