-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenkey.pas
144 lines (133 loc) · 2.92 KB
/
genkey.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Program GenKey;
Uses
Linux,
Types, GeneralP, CRC,
TickType,
PTRegKey;
Type
TRegArray = Array[1..SizeOf(TRegInfo)] of Byte;
Var
f: File of TRegInfo;
s: String;
i: Integer;
p: ^TRegArray;
Function ConvWord(w: Word): Word;
Begin
{$IfDef BigEndian}
ConvWord := (w mod 256)*256 + (w SHR 8);
{$Else}
ConvWord := w;
{$EndIf}
End;
Function ConvULong(u: ULong): ULong;
Var
u2: ULong;
u2a: Array[1..4] of Byte absolute u2;
p1: ^Byte;
i: Byte;
Begin
{$IfDef BigEndian}
p1 := @u;
For i := 1 to 4 do Begin u2a[5-i] := p1^; Inc(p1); End;
ConvULong := u2;
{$Else}
ConvULong := u;
{$EndIf}
End;
Procedure Crypt(var Key: TRegInfo);
Var
p1, p2: ^Byte;
i: ULong;
NewKey: TRegInfo;
s1, s2: String;
Begin
{init vars}
p1 := @Key; p2 := @NewKey;
s1[0] := #255; s2[0] := #255;
For i := 1 to 255 do Begin s1[i] := #0; s2[i] := #0; End;
{porting stuff}
NewKey.Addr.Zone := ConvWord(NewKey.Addr.Zone);
NewKey.Addr.Net := ConvWord(NewKey.Addr.Net);
NewKey.Addr.Node := ConvWord(NewKey.Addr.Node);
NewKey.Addr.Point := ConvWord(NewKey.Addr.Point);
NewKey.Serial := ConvULong(NewKey.Serial);
NewKey.Copies := ConvULong(NewKey.Copies);
NewKey.CryptCRC := ConvULong(NewKey.CryptCRC);
NewKey.DeCryptCRC := ConvULong(NewKey.DeCryptCRC);
{calculate CRC, exclude CRCs}
For i := 1 to SizeOf(TRegInfo)-8 do
Begin
p2^ := byte(P1^ XOR (55+i));
s1[i] := char(p1^); s2[i] := char(p2^);
{$IfDef FPC}
Inc(ULong(P1)); Inc(ULong(P2));
{$Else}
Inc(P1); Inc(P2);
{$EndIf}
End;
NewKey.DeCryptCRC := CalcCRC(s1); NewKey.CryptCRC := CalcCRC(s2);
Key := NewKey;
End;
Begin
Randomize;
If (RegInfo.Ver <> 0) then
Begin
Write('Key already exists. Overwrite? ');
ReadLn(s);
If (Pos('Y', UpStr(s)) = 0) then Halt(1);
WriteLn;
End;
p := @RegInfo;
For i := 1 to SizeOf(RegInfo) do p^[i] := Random(256);
Write('Name: ');
ReadLn(RegInfo.Name);
Write('Addr: ');
ReadLn(s);
Str2Addr(s, RegInfo.Addr);
Write('Serial #: ');
ReadLn(s);
Val(s, RegInfo.Serial, i);
Write('Version (1=noncommercial, 2=commercial, 3=author): ');
ReadLn(s);
Val(s, RegInfo.Ver, i);
Write('Copies: ');
ReadLn(s);
Val(s, RegInfo.Copies, i);
Crypt(RegInfo);
Assign(f, 'protick.key');
{$I-} ReWrite(f); {$I+}
If (IOResult <> 0) then
Begin
WriteLn('Couldn''t create protick.key!');
Halt(3);
End;
{$I-} Write(f, RegInfo); {$I+}
If (IOResult <> 0) then
Begin
WriteLn('Couldn''t write to protick.key!');
{$I-} Close(f); {$I+}
If (IOResult <> 0) then WriteLn('Couldn''t close protick.key!');
Halt(4);
End;
{$I-} Close(f); {$I+}
If (IOResult <> 0) then
Begin
WriteLn('Couldn''t close protick.key!');
Halt(5);
End;
WriteLn;
RegInfo := EvalKey;
GetKey;
WriteLn('GetKey report:');
WriteLn('Name: ', RegInfo.Name);
WriteLn('Addr: ', Addr2Str(RegInfo.Addr));
WriteLn('Serial #: ', RegInfo.Serial);
WriteLn('Version: ', RegInfo.Ver);
WriteLn('Copies: ', RegInfo.Copies);
WriteLn;
WriteLn('<Enter>');
{$IfDef UNIX}
ChMod('protick.key', 288);
{$EndIf}
ReadLn;
End.