C# Help RRS feed

  • Question

  • Hello,
    first time I ask here question, sorry if I ask in the wrong place.

    anyway, my question is:

    I want to make something that can change the keys I write(sorry for my English) for example:

    if I write ABCD, I will press Enter and then I will see 1978, and if I write 1978 I will see ABCD, like a secret language.
    I think I need to use a dictionary but I don't really know how to use it.

    Monday, November 27, 2017 8:33 PM

All replies

  • Hello,

     You can use XOR, Hash, or Encryption on data. Depends on the level of security

    you are wanting to have in the project.  Respectively, easy code/low security to

    complex code/high security.


     Please provide more details about your project,such as input/output expectations,

    project VS version, .Net target, UI, and OS platform.


     Thanks :)

    Monday, November 27, 2017 10:56 PM
  • There are many details of what you are asking that can influence the solution. Such as, what determines when you do the lookup? Do you do it whenever a key is typed that is neither a letter or a number? Do you do it immediately for every word or do you do it after a sentence or a paragraph or something else? Is this just for data typed into an edit box (text box) or do you want something that works in other places too?

    Sam Hobbs

    Tuesday, November 28, 2017 12:32 AM
  • Hey,

    I'm trying to make it with Console application

    for example:

    if someone type "a" he will get "1", "b", "2" and if someone type "ab" he will get "12"

    • Edited by DanielKirtc Wednesday, November 29, 2017 1:45 PM
    Wednesday, November 29, 2017 1:43 PM
  • Unfortunately the Console class does not have any events defined for user input, that's why it might be easier to accomplish in Winforms, where you can use a lot of predefined Key events.

    Create a little Winforms form with just a TextBox control for practising and implement a KeyDown and a KeyPress event by double-clicking the respective input fields in the Events properties window of your TextBox (its default name is textBox1). Then open to the code file of your form (default name is Form1.cs) and insert the following code right after your constructor Form1() with its single 'InitializeComponent()' line:

            bool _keyHandled = false;
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
                if (_keyHandled)
                    e.Handled = true;
                    _keyHandled = false;
            private void textBox1_KeyDown(object sender, KeyEventArgs e)
                switch (e.KeyCode)
                    case Keys.A:
                        textBox1.Text += "1";
                        _keyHandled = true;
                        SetToEndOfLine(sender as TextBox);
                    case Keys.B:
                        textBox1.Text += "9";
                        _keyHandled = true;
                        SetToEndOfLine(sender as TextBox);
            void SetToEndOfLine(TextBox tb)
                tb.SelectionStart = tb.SelectionLength;


    • Proposed as answer by Anil Sachin Thursday, December 7, 2017 2:22 PM
    Friday, December 1, 2017 11:25 AM
  • Hi Daniel,

    I think you just want to use a dictionary to change string you get. Below is an example to do this, when you input a char not in the dictionary, it will be replaced by '*'.

            static void Main(string[] args)
                Dictionary<char, char> dictionary = new Dictionary<char, char>();
                dictionary.Add('A', '1');
                dictionary.Add('B', '9');
                dictionary.Add('C', '7');
                dictionary.Add('D', '8');
                dictionary.Add('1', 'A');
                dictionary.Add('9', 'B');
                dictionary.Add('7', 'C');
                dictionary.Add('8', 'D');
                string input = Console.ReadLine();
                string output = "";
                foreach (char c in input)
                    output += (dictionary.ContainsKey(c) ? dictionary[c] : '*');
                Console.WriteLine("The input string is: {0}", input);
                Console.WriteLine("The output string is: {0}", output);

    The result is:

    What's more, if your dictionary contains many key-values, you can store your key-values in a file and read it by code.

    Follow this link and you can get more information about how to use Dictionary.

    Best Regards,

    Charles He

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, December 8, 2017 6:19 AM