sara.ghavam
یک شنبه 14 آذر 1395, 14:39 عصر
سلام دوستان من یک الگوریتم رمز نگاری پیدا کردم که به زبان دلفی نوشته شده میخوام اون رو به جاوا تبدیلش کنم اما چند تا سوال برام پیش اومده
یکی اینکه آیا کسی میتونه در این زمینه کمکم کنه؟
این دو خط رو اصلا متوجه نمیشم
کسی میتونه کمکم کنه که این کدهارو یه جاوا تبدیلش کنم؟
RStr :RawByteString;
RStrB :TBytes Absolute RStr;
const CKEY1 = 5376171757175; CKEY2 = 3261871757175;
function EncryptStr(const S :WideString; Key: LongInt): String;
var i :Integer;
RStr :RawByteString;
RStrB :TBytes Absolute RStr;
begin
Result:= '';
RStr:= UTF8Encode(S);
for i := 0 to Length(RStr)-1 do
begin
RStrB[i] := RStrB[i] xor (Key shr 8);
Key := (RStrB[i] + Key) * CKEY1 + CKEY2;
end;
for i := 0 to Length(RStr)-1 do
begin
Result:= Result + IntToHex(RStrB[i], 2);
end;
end;
function DecryptStr(const S: String; Key: LongInt): String;
var i, tmpKey :Integer;
RStr :RawByteString;
RStrB :TBytes Absolute RStr;
tmpStr :string;
begin
tmpStr:= UpperCase(S);
SetLength(RStr, Length(tmpStr) div 2);
i:= 1;
try
while (i < Length(tmpStr)) do
begin
RStrB[i div 2]:= StrToInt('$' + tmpStr[i] + tmpStr[i+1]);
Inc(i, 2);
end;
except
Result:= '';
Exit;
end;
for i := 0 to Length(RStr)-1 do
begin
tmpKey:= RStrB[i];
RStrB[i] := RStrB[i] xor (Key shr 8);
Key := (tmpKey + Key) * CKEY1 + CKEY2;
end;
Result:= UTF8Decode(RStr);
end;
یکی اینکه آیا کسی میتونه در این زمینه کمکم کنه؟
این دو خط رو اصلا متوجه نمیشم
کسی میتونه کمکم کنه که این کدهارو یه جاوا تبدیلش کنم؟
RStr :RawByteString;
RStrB :TBytes Absolute RStr;
const CKEY1 = 5376171757175; CKEY2 = 3261871757175;
function EncryptStr(const S :WideString; Key: LongInt): String;
var i :Integer;
RStr :RawByteString;
RStrB :TBytes Absolute RStr;
begin
Result:= '';
RStr:= UTF8Encode(S);
for i := 0 to Length(RStr)-1 do
begin
RStrB[i] := RStrB[i] xor (Key shr 8);
Key := (RStrB[i] + Key) * CKEY1 + CKEY2;
end;
for i := 0 to Length(RStr)-1 do
begin
Result:= Result + IntToHex(RStrB[i], 2);
end;
end;
function DecryptStr(const S: String; Key: LongInt): String;
var i, tmpKey :Integer;
RStr :RawByteString;
RStrB :TBytes Absolute RStr;
tmpStr :string;
begin
tmpStr:= UpperCase(S);
SetLength(RStr, Length(tmpStr) div 2);
i:= 1;
try
while (i < Length(tmpStr)) do
begin
RStrB[i div 2]:= StrToInt('$' + tmpStr[i] + tmpStr[i+1]);
Inc(i, 2);
end;
except
Result:= '';
Exit;
end;
for i := 0 to Length(RStr)-1 do
begin
tmpKey:= RStrB[i];
RStrB[i] := RStrB[i] xor (Key shr 8);
Key := (tmpKey + Key) * CKEY1 + CKEY2;
end;
Result:= UTF8Decode(RStr);
end;