hippoman
asked on
Pascal -> Perl conversion needed
I am a shareware author and I want my soft-shop (an order processing company) to distribute my keys for me, but they need it in perl.
Here is the function in pascal
--code starts---
function GenKey(name,privatekey :string):string;
var code: string;
i, bl: integer;
ecx, checksum: longint;
begin
for i:=1 to length(privatekey) do
checksum := checksum + Ord(privatekey[i]);
for i:=1 to length(name) do
begin
if Ord(name[i]) = 44 then name[i]:=Chr($E9);
if Ord(name[i]) = 144 then name[i]:=Chr($C9);
if Ord(name[i]) = 198 then name[i]:=Chr($E3);
if Ord(name[i]) = 199 then name[i]:=Chr($C3);
ecx := (checksum shr 8) AND $FF;
name[i] := Chr((Ord(UpCase(name[i])) AND $FF) xor ecx);
ecx := Ord(name[i]);
checksum := (checksum + ecx) * $AD9C + $56CE;
end;
for i:=1 to 6 do
begin
bl:=Ord(name[i]);
bl:=bl shr 4;
bl:=bl + $31;
if bl > $39 then bl:=bl+7;
code:=code+Chr(bl);
bl:=Ord(name[i]);
bl:=bl AND $0F;
bl:=bl+$31;
if bl > $39 then bl:=bl+7;
code:=code+Chr(bl);
end;
insert('A', code, 2);
insert('AC', code, 5);
result := code; //Return value is the serial number
end;
--code ends---
privatekey is a special string for each of my products. name is of course the name of the person that bought the product. the private key can be hardcoded at the top as a constant i can change.
It needs to work with the below form:
http://swreg.org/cgi-bin/key_gen_test.cgi
Obviously it needs to get the name passed to it and work out the serial, returning it between <softshop> and </softshop> as described on the website above (http://swreg.org/cgi-bin/key_gen_test.cgi)
200 points! please help!
Here is the function in pascal
--code starts---
function GenKey(name,privatekey :string):string;
var code: string;
i, bl: integer;
ecx, checksum: longint;
begin
for i:=1 to length(privatekey) do
checksum := checksum + Ord(privatekey[i]);
for i:=1 to length(name) do
begin
if Ord(name[i]) = 44 then name[i]:=Chr($E9);
if Ord(name[i]) = 144 then name[i]:=Chr($C9);
if Ord(name[i]) = 198 then name[i]:=Chr($E3);
if Ord(name[i]) = 199 then name[i]:=Chr($C3);
ecx := (checksum shr 8) AND $FF;
name[i] := Chr((Ord(UpCase(name[i])) AND $FF) xor ecx);
ecx := Ord(name[i]);
checksum := (checksum + ecx) * $AD9C + $56CE;
end;
for i:=1 to 6 do
begin
bl:=Ord(name[i]);
bl:=bl shr 4;
bl:=bl + $31;
if bl > $39 then bl:=bl+7;
code:=code+Chr(bl);
bl:=Ord(name[i]);
bl:=bl AND $0F;
bl:=bl+$31;
if bl > $39 then bl:=bl+7;
code:=code+Chr(bl);
end;
insert('A', code, 2);
insert('AC', code, 5);
result := code; //Return value is the serial number
end;
--code ends---
privatekey is a special string for each of my products. name is of course the name of the person that bought the product. the private key can be hardcoded at the top as a constant i can change.
It needs to work with the below form:
http://swreg.org/cgi-bin/key_gen_test.cgi
Obviously it needs to get the name passed to it and work out the serial, returning it between <softshop> and </softshop> as described on the website above (http://swreg.org/cgi-bin/key_gen_test.cgi)
200 points! please help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant!
my $code = GenKey($query->param('init als') . " " . $query->param('name'), $privatekey);
Only modification I needed was I had to add " " so there was a space between the first & last name.
my $code = GenKey($query->param('init
Only modification I needed was I had to add " " so there was a space between the first & last name.
ASKER
Heres a grade A
$query = new CGI;
should of course be
my $query = new CGI;
Dave