我要做的是拿一把钥匙和信息并将两者结合起来。删除重复的字母并从组合字符串构造2d 5x5数组。 然后用2d数组中字母的反向位置替换消息字符。因此,如果字母A位于2,3位,我将用位置3,2处的字母替换该字母。
我不知道如何做到这一点。我一直在这里搜索和reddit和codeproject和一般谷歌查询。我走了很多路,没有什么成功。我只是不知道该怎么做。
// array of the alphabet for replacing string letters
string alphabetArray = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//char[][] alphabetArray = new Char[5,5] {{"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"}};
// "parse" user input from key textbox
string userCipherKey = ChipherTextBox.Text;
// "parse" user input from message textbox
string messageForEncryption = InputRichTextBox.Text;
// insert cipher key into alphabet string array begining at the 0 location
string combinedStrings = alphabetArray.Insert(0, userCipherKey);
// remove duplicate letters from newly created array
string arrayWithDuplicateCharsRemoved = ""; // localized decleration of new array name
foreach (char value in combinedStrings)
{
// See if character is in the result already.
if (arrayWithDuplicateCharsRemoved.IndexOf(value) == -1)
{
// Append to the result.
arrayWithDuplicateCharsRemoved += value;
}
}
// convert char values back to a string
string encryptionArray = arrayWithDuplicateCharsRemoved.ToString();
// turn the new string into a 2d array
//char[] encryptionArray = removedDuplicateCharsFromArray.ToCharArray();
string encryptedMessage;
for (int i = 0; i < encryptionArray.Length; i++)
{
encryptedMessage = messageForEncryption.Replace(messageForEncryption, encryptionArray);
}
string messageOutput = encryptedMessage.ToString();
return OutputRichTextBox.Text = messageOutput.ToString();
}