我不知道这段代码是用什么语言编写的,但我正在尝试将其转换为 C#。我有原始算法的测试语句和加密结果。我的 C# 代码生成了不同的结果。
这是原始算法:
KeyStr='testKey'
j#=1; KeyLen#=Len(Clip(KeyStr))
Loop i#=1 To Len(Clip(InStr))
OutStr[i#]=Chr(BXor(Val(InStr[i#]),Val(KeyStr[j#])+j#))
!Message(InStr[i#]&'='&Val(InStr[i#])&' '&KeyStr[j#]&'='&Val(KeyStr[j#])&' '&OutStr[i#]&'='&Val(OutStr[i#]))
j#+=1; If j#>KeyLen# Then j#=1.
End
我用 C# 重写了它:
static string MyXOR(string data)
{
string key = "testKey";
string retValue = "";
int i = 0;
int x = 0;
int[] cipher = new int[data.Length];
x = 0;
for (i = 0; i < data.Length; i++)
{
//Console.Write((char)((data[i] ^ key[x])));
retValue = retValue + (char)((data[i] ^ key[x]));
cipher[i] = (data[i] ^ key[x]);
x++;
if (x >= key.Length)
x = 0;
}
return retValue;
}
最佳答案
我是这样认为的:
//Console.Write((char)((data[i] ^ key[x])));
retValue = retValue + (char)((data[i] ^ (key[x] + x)));
cipher[i] = (data[i] ^ key[x]);
x++;
关于c# - 我如何将此异或加密转换为 C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33867396/