Im doing a caesar cipher and decipher, and i need to ignore this letters from the String: "á é ó í ú", cause we need to cipher text in spanish too, is there any function to ignore this letters or a way to change them in the cipher and still work in the decipher?
private 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);
}
something i expect is, if i enter a String like : "wéts" with a key an2, i get an output "uéiy" and when i decipher the "uéiy" i get "wéts" again
Sure, here you go, here's 65536 character alphabet caesar cipher implementation:
private char cipher(char ch, int key)
{
return ch + key;
}
private char decipher(char ch, int key)
{
return ch - key;
}
or here's one that just ignore non-latin letters:
private char cipher(char ch, int key)
{
if (char < 'A' || char > 'z' || (char > 'Z' && char < 'a'))
{
return ch;
}
char d = char.IsUpper(ch) ? 'A' : 'a';
return (char)((((ch + key) - d) % 26) + d);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With