该算法的Vigenere在C#中的解释算法、Vigenere

2023-09-12 21:23:43 作者:许:清如许、许你一世

我碰到这个code:

字节的Vigenere密码,以解密误差

但试图遵循的规则我做了一个新问题了。

But trying to follow the rules I made a new question about it.

下面的算法使用,我设法得到一个更好的理解到它:

The following algorithm is used and I'm trying to get a better understanding into it:

Byte[] result= new Byte[plaintext.Length];

key = key.Trim().ToUpper();

int keyIndex = 0;
int keylength = key.Length;

for (int i = 0; i < plaintext.Length; i++)
{
    keyIndex = keyIndex % keylength;
    int shift = (int)key[keyIndex] - 65;
    result[i] = (byte)(((int)plaintext[i] + shift) % 256);
    keyIndex++;
}

我是正确的思维的关键需要进行修整,因为它是在统一code?因此,从资本中减去65产生一个共同的字符/符号?

Am I right in thinking the key needs to be trimmed as it is in Unicode? therefore subtracting 65 from a capital produces a common character/symbol?

推荐答案

为大写字母A的ASCII值是65. 键的所有字符被转换为大写,这仅返回每个字母的英文字母指数

The ASCII value for the capital A is 65. All characters in key are converted to uppercase, this would simply return the alphabetical index of each letter in key.

键,每个字母被转换为数字的方式,并在原字符串中的每个字母是移字母这个数字职务。

Each letter in key is converted to a number that way, and each letter in the original string is "shifted up the alphabet" that number of positions.

如果你的关键是,这会变成数字1,0和3,然后应用到的Hello World,如下所示:

If your key was BAD, this would turn into the numbers 1, 0 and 3, then applied to "hello world" as follows:

Hello world
10310310310 <-- added to each character
Ieomo#xoumd

您可以通过添加下面这属于你的code证明这一点:

You can demonstrate this by adding this code below yours:

StringBuilder demonstration = new StringBuilder();
foreach (byte b in result)
{
    demonstration.Append((char)b);
}
Console.WriteLine(demonstration.ToString());
 
精彩推荐