Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Function to ignore chars like 'á' 'é' 'ó' 'í' and 'ú'? [duplicate]

Tags:

c#

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

like image 843
Esteban Avatar asked Dec 12 '25 02:12

Esteban


1 Answers

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);
}
like image 65
Robert McKee Avatar answered Dec 13 '25 15:12

Robert McKee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!