delphi的函数写成c#的怎么写?
function FEnc(Str:String):String;
const
fkey:array[0..7] of byte=($A9,$66,$12,$F1,$40,$A3,$E5,$4D);
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str[i]) xor fkey[j],2); //异或
j:=(j+1) mod 8;
end;
感谢万分!
function FEnc(Str:String):String;
const
fkey:array[0..7] of byte=($A9,$66,$12,$F1,$40,$A3,$E5,$4D);
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str[i]) xor fkey[j],2); //异或
j:=(j+1) mod 8;
end;
感谢万分!
public byte[] FEnc(byte[] Str)
{
byte[] _Key = new byte[] { 0xA9, 0x66, 0x12, 0xF1, 0x40, 0xA3, 0xE5, 0x4D }; byte[] _ReturnByte = new byte[Str.Length];
int j = 0;
for (int i = 0; i != Str.Length; i++)
{
_ReturnByte[i] =(byte)(Str[i] | _Key[j]); if (j % 8 == 0) j = 0;
}
return _ReturnByte;
}
public string FEnc(string str)
{
byte[] bytes = {(byte)0xA9,(byte)0x66,(byte)0x12,(byte)0xF1,(byte)0x40,(byte)0xA3,(byte)0xE5,(byte)0x4D};//Delphi没学过,数字不知道是不是这样转
string result = string.Empty; for (int i = 1, j = 0; i <= str.Length; i++, j=(j+1)%8)
{
result += IntToHex((byte)str[i] ^ bytes[j], 2);//IntToHex不知道是不是Delphi内置的
} return result;
}