求一段dephi转c#的代码

LWWL 2009-03-04 02:49:08
function DenCrypt(Str: string; Key: string): string;
var
X, Y: integer;
a: Byte;
begin
if Key = '' then
Key := 'LW';
Y := 1;
for X := 1 to Length(Str) do begin
a := (Ord(Str[X]) and $0F) xor (Ord(Key[Y]) and $0F);
Str[X] := Char((Ord(Str[X]) and $F0) + a);
inc(Y);
if Y > Length(Key) then Y := 1;
end;
result := Str;
end;
...全文
87 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzxap 2009-03-04
  • 打赏
  • 举报
回复
public string DenCrypt(string str, string key)
{
int y = 0;
int a;
string result = "";

if(key == string.Empty)
key = "LW";

for(int x = 0; x < str.Length; x++)
{
a = ((byte)str[x] & 0x0F) ^ ((byte)key[y] & 0x0F);
result += (char)(((byte)str[x] & 0xF0) + a);

y++;
if (y >= key.Length)
y = 0;
}

retrun result;
}

LWWL 2009-03-04
  • 打赏
  • 举报
回复
byte a 改成 int a 就行了
谢谢
LWWL 2009-03-04
  • 打赏
  • 举报
回复
a = ((byte)str[x] & 0x0F) ^ ((byte)key[y] & 0x0F);
就这段
LWWL 2009-03-04
  • 打赏
  • 举报
回复
楼上的代码编译不过去啊
JaggerLee 2009-03-04
  • 打赏
  • 举报
回复
楼上不知是否正解
bomdy 2009-03-04
  • 打赏
  • 举报
回复

public string DenCrypt(string str, string key)
{
int y = 0;
byte a;
string result = "";

if(key == string.Empty)
key = "LW";

for(int x = 0; x < str.Length; x++)
{
a = ((byte)str[x] & 0x0F) ^ ((byte)key[y] & 0x0F);
result += (char)(((byte)str[x] & 0xF0) + a);

y++;
if (y >= key.Length)
y = 0;
}

retrun result;
}
csjtxy 2009-03-04
  • 打赏
  • 举报
回复
public string DenCrypt(string str, string key)
{
int x;
int y;
byte and;

if(key=="")
{
key = "LW";
}
y = 1;


for (x = 1; x <= sizeof(str); )
{
a=(Ord(str) and $OF) xof(Ord(key) and $OF);
str=char((Ord(str) and $FO) +a);
inc(y);

if(y>sizeof(key)
then y=1);

}
return str;
}
steal8275756 2009-03-04
  • 打赏
  • 举报
回复
public string DenCrypt(string str, string key)
{
int y;
Byte a;
string result;
if(key == string.Empty)
{
key = "LW";
y = 1;
}

for(int i = 0; i < str.Length; i++)
{
//a := (Ord(Str[X]) and $0F) xor (Ord(Key[Y]) and $0F); 不懂
//Str[X] := Char((Ord(Str[X]) and $F0) + a); 不懂
//inc(Y); 不懂
if (y > key.Length)
y = 1;
}

retrun result;
}
csjtxy 2009-03-04
  • 打赏
  • 举报
回复
沙发

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧