Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

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

$
0
0

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);
    }
}

}

I have this so far but I am not sure how to accept the user input and run the code when the buttons are pressed.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>