unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
Type
ByteArray = array of byte;
type
enco = packed record
e1: Cardinal;
e2: Cardinal;
e3: Cardinal;
e4: Cardinal;
end;
var
Form1: TForm1;
Tenco: enco;
const
table : array [0..221] of word = (
$0068, $0005, $0007, $8000, $0002, $0005, $0005, $0007,
$000e, $0005, $000b, $0007, $8000, $0003, $8000, $003d,
$00d7, $8000, $8000, $000a, $0006, $0009, $8000, $8000,
$8000, $8000, $8000, $0025, $8000, $0005, $0004, $0008,
$0013, $0008, $0003, $001a, $0007, $0014, $0005, $0002,
$0005, $0001, $0005, $0002, $0002, $0011, $000f, $000a,
$0005, $8000, $0002, $0002, $000a, $028d, $8000, $0008,
$0007, $0009, $8000, $8000, $8000, $0002, $0025, $8000,
$00c9, $8000, $8000, $0229, $02c9, $0005, $8000, $000b,
$0049, $005d, $0005, $0009, $8000, $8000, $0006, $0002,
$8000, $8000, $8000, $0002, $000c, $0001, $000b, $006e,
$006a, $8000, $8000, $0004, $0002, $0049, $8000, $0031,
$0005, $0009, $000f, $000d, $0001, $0004, $8000, $0015,
$8000, $8000, $0003, $0009, $0013, $0003, $000e, $8000,
$001c, $8000, $0005, $0002, $8000, $0023, $0010, $0011,
$8000, $0009, $8000, $0002, $8000, $000d, $0002, $8000,
$003e, $8000, $0002, $0027, $0045, $0002, $8000, $8000,
$0042, $8000, $8000, $8000, $000b, $8000, $8000, $8000,
$0013, $0041, $8000, $0063, $8000, $0009, $8000, $0002,
$8000, $001a, $8000, $0102, $0135, $0033, $8000, $8000,
$0003, $0009, $0009, $0009, $0095, $8000, $8000, $0004,
$8000, $8000, $0005, $8000, $8000, $8000, $8000, $000d,
$8000, $8000, $8000, $8000, $8000, $0040, $0009, $8000,
$8000, $0003, $0006, $0009, $0003, $8000, $8000, $8000,
$0024, $8000, $8000, $8000, $0006, $00cb, $0001, $0031,
$0002, $0006, $0006, $0007, $8000, $0001, $8000, $004e,
$8000, $0002, $0019, $8000, $8000, $8000, $8000, $8000,
$8000, $010c, $8000, $8000, $0009, $8000
);
implementation
//uses C2PTypes
{$R *.dfm}
procedure enccalc(ip: cardinal);
var pi : cardinal;
begin
pi := ip xor -1; //bitwise NOT
Tenco.e1 := ((pi xor $1357) shl 16) or ((ip xor $aaaa) and $0000);
Tenco.e2 := ((ip xor $4321) shr 16) or ((pi xor $abcd) and $ffff);
Tenco.e3 := (((ip xor pi) and $0f0f) xor ip) xor $a76e;
Tenco.e4 := (((ip xor pi) and $0f0f) xor pi) xor $f4bc;
end;
function pcklength(data: byte): word;
begin
if(data < 222) then
begin
result := table[data];
end;
result := 0;
end;
procedure cryptin(data: ByteArray; len: integer);
var
t1, t2 : cardinal;
i : integer;
begin
for I := 0 to len do
begin
data[i] := data[i] xor Tenco.e1;
t1 := Tenco.e1;
t2 := Tenco.e2;
Tenco.e1 := ((t1 shr 1) or (t2 shl 31)) xor $7e7f;
t2 := ((t2 shr 1) or (t1 shl 31)) xor $a7ec;
Tenco.e2 := ((t2 shr 1) or (t1 shl 31)) xor $a7ed;
end;
end;
function logbuild(var buff: ByteArray; var come: ByteArray; var doit: ByteArray): Integer;
var
len : integer;
begin
buff[0] := $80;
//check this part
move(come[0], buff[1], 30) ;
move(doit[0], buff[31], 31);
len := pcklength(buff[0]);
cryptin(buff, len);
result:=(len);
end;
end.