1
votes

I'm using inno setup to "crypt" a password:

function XORcrypt(Value,Key: string): string;
var
    p,k,pl,kl: integer;
begin
    {very basic encryption, using bitwise XOR}
    result:=Value;
    pl:=Length(Value);
    kl:=Length(Key);
    if (pl>0) and (kl>0) then
    begin
        p:=1; k:=1;
        while (p<=pl) do
        begin
            Result[p]:=Char(Ord(Value[p]) XOR Ord(Key[k]));
            if k=kl then k:=1 else k:=k+1;
                p:=p+1
        end; {while}
    end; {if}
end; {XORcrypt}

inno seems not to know the pascal function Ord which returns the ASCII value of a requested character (67 for 'C')

Any solutions?

1

1 Answers

3
votes

The problem is not Ord() it's Char() you need to use Chr() instead.

function XORcrypt(Value,Key: String): String;
var
    p,k,pl,kl: integer;
begin
    {very basic encryption, using bitwise XOR}
    result:=Value;
    pl:=Length(Value);
    kl:=Length(Key);
    if (pl>0) and (kl>0) then
    begin
        p:=1; k:=1;
        while (p<=pl) do
        begin
            Result[p]:=Chr(Ord(Value[p]) XOR Ord(Key[k]));
            if k=kl then k:=1 else k:=k+1;
                p:=p+1
        end; {while}
    end; {if}
end; {XORcrypt}