using System;
public class ReadWriteTxt // Read and write to/from text files
{
public static string cipherTxt()
{
return System.IO.File.ReadAllText(@"myfile1");
}
internal static void decipherTxt(string result)
{
System.IO.File.WriteAllText(@"myfile2", result);
}
}
public class LetterArray
{
internal static string[] Alphabet()
{
var letterValues = new string[26];
letterValues[0] = "A";
letterValues[1] = "B";
letterValues[2] = "C";
letterValues[3] = "D";
letterValues[4] = "E";
letterValues[5] = "F";
letterValues[6] = "G";
letterValues[7] = "H";
letterValues[8] = "I";
letterValues[9] = "J";
letterValues[10] = "K";
letterValues[11] = "L";
letterValues[12] = "M";
letterValues[13] = "N";
letterValues[14] = "O";
letterValues[15] = "P";
letterValues[16] = "Q";
letterValues[17] = "R";
letterValues[18] = "S";
letterValues[19] = "T";
letterValues[20] = "U";
letterValues[21] = "V";
letterValues[22] = "W";
letterValues[23] = "X";
letterValues[24] = "Y";
letterValues[25] = "Z";
return letterValues;
}
}
public class Decipher
{
public static void Main() //Main method
{
int res = 34;
string[] letterValues = LetterArray.Alphabet();
//Create for loop that runs through every possible shift value
for (int shift = 0; shift <= 25; shift++)
{
Console.WriteLine("\nShift Value = " + shift + ": ");
// For each character in the text file
foreach (var ch in ReadWriteTxt.cipherTxt())
{
string result = string.Empty;
if (ch == ' ')
{
}
else
{
for (int i = 0; i <= 25; i++)
{
if ((ch.ToString().ToUpper()) == letterValues[i])
{
res = i;
if (shift > res)
{
// print results out
Console.Write(letterValues[26 - (shift - res)][0]);
}
else
{
Console.Write(letterValues[res - shift][0]);
}
}
}
ReadWriteTxt.decipherTxt(result);
}
}
}
}
}
我正在使用Caesar Cipher程序解密从文件中读取的密文。 它列出了整个字母表中的所有可能的变化。
我需要允许用户输入正确的&#39;移位值(例如,最接近解密文本应该翻译的那个)然后将相应的字符串写入文件。
最好的是什么?
P.S。我对C#的理解有点基础所以请温柔地对待我;)。