【发布时间】:2021-02-04 13:51:29
【问题描述】:
我实际上是在尝试将 pascal 代码转换为 c# 代码(我们正在重写旧应用程序)。
帕斯卡码:
function DecryptStr(Source: PChar): string;
var
st: string;
i, k, mask: byte;
begin
Result := '';
try
SetString(st, Source, 32);
if st[1] <> #0 then
begin
mask := ord(st[1]);
k := ord(st[2]) xor mask;
SetLength(Result, k);
for i := 1 to k do
begin
inc(mask);
k := ord(st[i + 2]) xor mask;
Result[i] := chr(k);
// Result := Result + chr(k);
end;
end;
except
end;
end;
还有我的 C# 代码:
public static string decrypt(string hash)
{ string buffer;
byte i, k, mask;
string result = "";
buffer = hash.Substring(0, 32);
mask = (byte)(buffer[0]);
k = (byte)((byte)(buffer[1])^mask);
for (i = 0; i<k-1; i++)
{
mask += 1;
k = (byte)((byte)(buffer[i+2])^mask);
result+=(char)(k);
}
// string decoded = System.
return (result);
}
请告诉我,是不是很相似,还是帕斯卡有一些隐藏的东西?
示例: 在c#中输入:
акРЖђЏГ€€њљђНѓGН q6™&і—'n1•\›ЛH[
c# 输出:
\u0011$\f\v&\t\b
但它看起来不像真正的密码。 请告诉我出了什么问题。
【问题讨论】:
-
什么是真正的密码/帕斯卡码的输出是什么?
-
术语
hash不正确。您无法解密哈希。 -
旧代码是用什么版本的delphi编写的?知道字符串是 ANSI 还是 UTF-8 可能很重要...
-
Pascal 的哪个版本?似乎原始字符串是Unicode。在这种情况下,您不能简单地将其转换为
(byte)。你可以看看Encoding.GetBytes() -
谢谢,我正在尝试!