主要代码如下:
Console.WriteLine("请输入需要加密的明文:");
string m = Console.ReadLine();
char[] str=new char[80];
int[] t = {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,26 };
char[] t1 = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char[] t2 = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int i,b,temp;
for (i = 0; i < m.Length;i++ )
{
for(int j=0;j
if (m[i] == t2[j])
{
temp = t[j];
b = ((temp + 3))%26;
str[i] = t1[b];
}
}
}
Console.WriteLine("凯撒密码加密所得的密文为:");
Console.WriteLine(str);
Console.ReadLine();