c#实现密码学之轮转机加密过程

151 阅读2分钟
using System;

namespace luanzhuan
{
    
    
    class Program
    {
       

        static void Main(string[] args)
        {
        
        string[] Array1 = new string[] { "0","24", "25", "26", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23","0" };
        string[] Array2 = new string[] { "0","21", "3", "15", "1", "19", "10", "14", "26", "20", "8", "16", "7", "22", "4", "11", "5", "17", "9", "12", "23", "18", "2", "25", "6", "24", "13" ,"0"};
        string[] Array3 = new string[] { "0","26", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25" ,"0"};
        string[] Array4 = new string[] { "0","20", "1", "6", "4", "15", "3", "14", "12", "23", "5", "16", "2", "22", "19", "11", "18", "25", "24", "13", "7", "10", "8", "21", "9", "26", "17","0" };
        string[] Array5 = new string[] { "0","26", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25" ,"0"};
        string[] Array6 = new string[] { "0","14", "8", "18", "26", "17", "20", "22", "10", "3", "13", "11", "4", "23", "5", "24", "9", "12", "25", "16", "19", "6", "15", "21", "2", "7", "1" ,"0"};
            Console.WriteLine("请输入原文");
            string input = Console.ReadLine();
            int leng = System.Text.Encoding.Default.GetBytes(input).Length;
            byte[] array = new byte[leng];
            Console.WriteLine("是否继续执行是请输入1否则输入0");
            int c = 0;int d = 0;
            while (Convert.ToInt32(Console.ReadLine()) == 1)
            {
                Console.WriteLine("是否继续执行是请输入1否则输入0");

                for (int i = 0; i < leng; i++)
                {

                    array = System.Text.Encoding.ASCII.GetBytes(input);
                    int asciicode = (int)(array[i]) - 64;
                    for (int j = 1; j < 27; j++)
                    {
                        if (Array1[asciicode] == Array2[j])
                        {
                            asciicode = j;
                            break;
                        }

                    }

                    for (int k = 1; k < 27; k++)
                    {
                        if (Array3[asciicode] == Array4[k])
                        {
                            asciicode = k;
                            break;
                        }

                    }
                    for (int l = 1; l < 27; l++)
                    {
                        if (Array5[asciicode] == Array6[l])
                        {
                            asciicode = l;
                            break;
                        }
                    }
                    asciicode = asciicode + 64;
                    System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                    byte[] byteArray = new byte[] { (byte)asciicode };
                    string strCharacter = asciiEncoding.GetString(byteArray);
                    Console.WriteLine(strCharacter);
                    
                }
                for(int a=27;a>1;a--)
                {
                    Array1[a] = Array1[a - 1];
                    Array2[a] = Array2[a - 1];
                    
                }
                Array1[1] = Array1[27];
                Array2[1] = Array2[27];
                
                c++;
                
                if(c%12==0)
                {
                    for (int b = 27; b > 1; b--)
                    {
                        Array3[b] = Array3[b - 1];
                        Array4[b] = Array4[b - 1];
                    }
                    Array3[1] = Array3[27];
                    Array4[1] = Array4[27];
                    d++;
                    
                    if(d%12==0)
                    {
                        for(int e=27;e>1;e--)
                        {
                            Array5[e] = Array5[e - 1];
                            Array6[e] = Array6[e - 1];
                        }
                        Array5[1] = Array5[27];
                        Array6[1] = Array6[27];

                    }
                }
            }
            
        }

        
    }
}

请勿随意转载。