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

RossalaTTMRossalaTTM ✭✭Member ✭✭
edited March 23 in Xamarin.Forms
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 so far but I cannot work out how to link everything up, the code in the buttons does not work. Any help would be greatly appreciated.

Best Answer

Answers

Sign In or Register to comment.