【发布时间】:2015-12-16 02:42:34
【问题描述】:
我正在尝试为作业制作 C# Caesar Cipher。我一直在尝试这样做很长一段时间,但没有取得任何进展。
我现在遇到的问题是,而不是使用我的 encrypted_text 并对其进行解密,它只是 cycles through that alphabet, ignoring the character that it started on.应该发生的事情是它意味着采用 encrypted_text 并循环遍历字母表,将每个字母更改为某个数字.
这是我目前所拥有的:
using System;
using System.IO;
class cipher
{
public static void Main(string[] args)
{
string encrypted_text = "exxego";
string decoded_text = "";
char character;
int shift = 0;
bool userright = false;
char[] alphabet = new char[26] { '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' };
do
{
Console.WriteLine("How many times would you like to shift? (Between 0 and 26)");
shift = Convert.ToInt32(Console.ReadLine());
if (shift > 26)
{
Console.WriteLine("Over the limit");
userright = false;
}
if (shift < 0)
{
Console.WriteLine("Under the limit");
userright = false;
}
if (shift <= 26 && shift >= 0)
{
userright = true;
}
} while (userright == false);
for (int i = 0; i < alphabet.Length; i++)
{
decoded_text = "";
foreach (char c in encrypted_text)
{
character = c;
if (character == '\'' || character == ' ')
continue;
shift = Array.IndexOf(alphabet, character) - i;
if (shift <= 0)
shift = shift + 26;
if (shift >= 26)
shift = shift - 26;
decoded_text += alphabet[shift];
}
Console.WriteLine("\nShift #{0} \n{1}", i + 1, decoded_text);
}
StreamWriter file = new StreamWriter("decryptedtext.txt");
file.WriteLine(decoded_text);
file.Close();
}
}
正如你从我的照片中看到的,我越来越近了。我只需要能够破解这个。任何帮助将不胜感激。如果这是一个简单的问题/解决方案,请原谅我,我对此真的很陌生。
【问题讨论】:
-
我很抱歉,但我忍不住要交织一个双关语:你不能去死...
-
只是好奇这个类是什么和在哪里,这不是今天的第一个实例。这里是other question。
-
这是林肯大学。那个人和我做的评价一模一样……小世界!
标签: c# encryption caesar-cipher