c# - 我如何将此异或加密转换为 C#?

标签 c# encryption xor

我不知道这段代码是用什么语言编写的,但我正在尝试将其转换为 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/

相关文章:

c# - 检查整数是否== null

c# - 从 webBrowser 控件读取 XML

c++ - 如何在 C++ 应用程序中使用 GnuPG(不是命令行工具)?

c - 使用哪种类型的神经网络?

c++ - XOR 运算符在 C++ 中无法正确评估

c# - ASP.NET Core 中的 ConfigureServices() 和 Configure() 有什么区别?

javascript - 加密 JS : TripleDES not encrypting properly

android - Android 4.2 上的加密错误

java.lang.ArrayIndexOutOfBoundsException : -85 java alogrithm

c# - C# 中的简单条形图