Reputation: 488
The below function is a basic decryption routine from a legacy application written in Delphi 2007.
function TMainFrm.DecodePsw(Passw : String) : String;
var
i : Integer;
ss : String;
Begin
ss := Passw;
for i:=1 to Length(ss) do begin
ss[i] := Chr( Ord(ss[i]) - i*21 + 15);
end;
Result := ss;
end;
On some client computers it returns a different result with the same input data, what could be the possible causes of this?
Upvotes: 1
Views: 111
Reputation: 613013
The problem, one imagines, is that this treats a string as if it were a byte array. But a string's value also depends on an assumed encoding. And since you are using ANSI strings, your byte arrays will be interpreted as though they are encoded in whatever the prevailing locale is. So, the same byte array is interpreted one way on a Windows 1252 locale, another way on a Windows 1251 locale, and so on.
That is why your code behaves differently on different machines. Exactly how you are to resolve your problem I cannot say with the limited information present. I would say that what you have here is not what I would describe as encryption, but I guess you know that. I would also suggest that it is unusual to be decrypting passwords. That is considered bad practise.
Upvotes: 3