gpt4 book ai didi

c# - 将 JavaScript 转换为 C#

转载 作者:行者123 更新时间:2023-12-02 20:30:20 25 4
gpt4 key购买 nike

当谈到将此 javascript 转换为 C# 时,我有点困惑...

如有任何帮助,我们将不胜感激!

这是 JavaScript:

function d(strInput) {
strInput = decoder(strInput);
var strOutput = "";
var intOffset = (key + 112) / 12;
for (i = 4; i < strInput.length; i++) {
thisCharCode = strInput.charCodeAt(i);
newCharCode = thisCharCode - intOffset;
strOutput += String.fromCharCode(newCharCode)
}
document.write(strOutput)
}

这是我将其转换为 C# 的尝试。它在某些时候有效,但大多数时候负数作为关键......

public string decode(int key, string data)
{
int i;
string strInput = base64Decode(data);
StringBuilder strOutput = new StringBuilder("");

int intOffset = (key + 112) / 12;
for (i = 4; i < strInput.Length; i++)
{

int thisCharCode = strInput[i];
char newCharCode = (char)(thisCharCode - intOffset);
strOutput.Append(newCharCode);
}
return strOutput.ToString();
}

目前它输出以下内容:

(int key = 212, string data = "U0lra36DfImFkImOkImCW4OKj4h8hIdJfoqI")
Output = {c¬a¬¬¬¬¬¬¬¬@¬¬¬¬a¬¬.c¬¬}


(int key = -88, string data = "T1RXYmV0cHFkZ3R1MzQ1Ng==")
Output = {crnobers1234}

最佳答案

对于两个示例输入,此代码给出的结果与您的示例相同:

    public string decoder(string data)
{
string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
char o1, o2, o3;
int h1, h2, h3, h4, bits, i = 0;
string enc = "";
do
{
h1 = b64.IndexOf(data.Substring(i++, 1));
h2 = b64.IndexOf(data.Substring(i++, 1));
h3 = b64.IndexOf(data.Substring(i++, 1));
h4 = b64.IndexOf(data.Substring(i++, 1));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = (char)(bits >> 16 & 0xff);
o2 = (char)(bits >> 8 & 0xff);
o3 = (char)(bits & 0xff);
if (h3 == 64) enc += new string(new char[] { o1 });
else if (h4 == 64) enc += new string(new char[] { o1, o2 });
else enc += new string(new char[] { o1, o2, o3 });
} while (i < data.Length);
return enc;
}

public string d(int key, string data)
{
int i;
string strInput = decoder(data);
StringBuilder strOutput = new StringBuilder("");

int intOffset = (key + 112) / 12;
for (i = 4; i < strInput.Length; i++)
{

int thisCharCode = strInput[i];
char newCharCode = (char)(thisCharCode - intOffset);
strOutput.Append(newCharCode);
}
return strOutput.ToString();
}

我确信需要进行一些清理工作!这只是你的 Javascript detector() 函数的逐字翻译。

关于c# - 将 JavaScript 转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4282253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com