String substitution (C#)

c#

Solution

It isn't a very strong encryption, but you the following version would be extremely efficient and requires very little data to define the encryption:

private string EncryptFn(string Sinput)
{
    string coding = "QWERTYUIOPASDFGHJKLZXCVBNM";

    StringBuilder result = new StringBuilder();
    foreach (char c in Sinput)
    {
        int index = (Char.ToUpper(c) - 'A');
        if (index >= 0 && index < coding.Length)
            result.Append(coding[index]);
        else
            result.Append(c);
    }
    return result.ToString();
}

Problem

Programming in c#. I'm trying to substitute every char in a string with another char (Encryption), but I need some help. I was going to do this using two arrays, one with the alphabet in it, then the other with the substitute values, but I realized I'd have to do a else-if the size of the whole alphabet, which I don't really have time for. I'd like to know if there is an easier, faster way. This is what I have so far ``` private string EncryptFn(string Sinput) { string STencryptedResult = "Null for now"; char[] CAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); char[] Encrypt = "QWERTYUIOPASDFGHJKLZXCVBNM".ToCharArray(); return STencryptedResult; } ``` Thanks

Original source

Related problems