Caesar code in C #

If I want to write a Caesar C # cipher, should I go through each case? It makes no sense for me to convert to ASCII or UTF (perhaps because I don’t understand how this will work). I just need a point in the right direction.

Should I assign 1-26 to each letter?

+5
source share
4 answers

You can put each letter in an array and use the index of the array (wrapping at the end), or you can just use the asccii value to write and transfer to the first when you reach the last. The trick here is that all characters are sorted sequentially, starting with A = 0x41

+2
source

, - , :

  • , # , a = b% c - b, c. c = n b = n, a = 0. c = n b = n + 1, a = 1. .
  • # : char[] chars = new char[]{'a', 'b',...};
+2

Caesar Cypher , char [a-z] [A-Z], .

, b, μ ¶, U + 10FFFF ( ) U + 0000 ( , - , , string .

, UTF-16. 1 char U + FFFF U + 0000. UTF-16 ( , string, . , .

+1

.

    public static string Encrypt(string str, int n)
    {
        return string.Join("", str.Select(x => Encrypt(x, n)));
    }

    public static string Decrypt(string str, int n)
    {
        return string.Join("", str.Select(x => Decrypt(x, n)));
    }

    public static char Encrypt(char chr, int n)
    {
        int x = chr - 65;

        return (char)((65) + ((x + n) % 26));
    }

    public static char Decrypt(char chr, int n)
    {
        int x = chr - 65;

        return (char)((65) + ((x - n) % 26));
    }

P.S.

.

:

+1

All Articles