-2

c# で Vigenere 暗号のプログラムを作成していますが、"Ñ" がなくて困っています。 " このコードに? key と s の両方がこのように残るように: a=0 b=1... n=13 ñ=14... z=26

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
    static void VigenereEncrypt(ref StringBuilder s, string key)
    {
        for (int i = 0; i < s.Length; i++) s[i] = Char.ToUpper(s[i]);
        key = key.ToUpper();
        int j = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (Char.IsLetter(s[i]))
            {
                s[i] = (char)(s[i] + key[j] - 'A');
                if (s[i] > 'Z') s[i] = (char)(s[i] - 'Z' + 'A' - 1);
            }
            j = j + 1 == key.Length ? 0 : j + 1;
        }
    }

    static void VigenereDecrypt(ref StringBuilder s, string key)
    {
        for (int i = 0; i < s.Length; i++) s[i] = Char.ToUpper(s[i]);
        key = key.ToUpper();
        int j = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (Char.IsLetter(s[i]))
            {
                s[i] = s[i] >= key[j] ?
                          (char)(s[i] - key[j] + 'A') :
                          (char)('A' + ('Z' - key[j] + s[i] - 'A') + 1);
            }
            j = j + 1 == key.Length ? 0 : j + 1;
        }
    }

    public static void Main()
    {
        while (true)
        {
            StringBuilder s = new StringBuilder(Console.ReadLine());
            string key = Console.ReadLine();
            VigenereEncrypt(ref s, key);
            Console.WriteLine(s);
            VigenereDecrypt(ref s, key);
            Console.WriteLine(s);
            Console.ReadLine();
        }
    }

 }
}
4

1 に答える 1