Has anyone got any insight as to how I could write a Caesar cipher in xamarin forms.

RossalaTTMRossalaTTM Member ✭✭

public void Encrypt_Clicked(object sender, EventArgs e)
{
if (txtPlainText != null)
{
string ciphertext = Encipher(txtPlainText,);
}
}

    public void Decrypt_Clicked(object sender, EventArgs e)
    {
        if (txtEncryptedText != null)
        {
            string Deciphertext = Decipher(txtEncryptedText,);
        }
    }

    public static string Encipher(string input, int key)
    {
        string output = string.Empty;

        foreach (char ch in input)
            output += cipher(ch, key);

        return output;
    }

    public static string Decipher(string input, int key)
    {
        return Encipher(input, 26 - key);
    }

    public static char cipher(char ch, int key)
    {
        if (!char.IsLetter(ch))
        {
            return ch;
        }

        char d = char.IsUpper(ch) ? 'A' : 'a';
        return (char)((((ch + key) - d) % 26) + d);
    }
}

}

This is what I have gotten so far, I can`t get the code in the buttons to work, to actually accept user input and output the values. Any help would be greatly appreciated.

Sign In or Register to comment.