This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeygen.pas
More file actions
367 lines (335 loc) · 8.1 KB
/
keygen.pas
File metadata and controls
367 lines (335 loc) · 8.1 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
unit keygen;
interface
uses
Classes, Windows;
const
TripBufMax = 1024;
type
TKeyRecord = record
TripKey: String;
pubKey: String;
secKey: String;
TripStr: String;
end;
TSearchType = (stNums, stAlpha, st7bit, stAll);
TTripList = class(TObject)
private
FTrips: array[0..TripBufMax] of TKeyRecord;
FReadBlock: Integer;
FWriteBlock: Integer;
// 読むときはWriteBlockのところから読む。
// 書くときはReadBlockのところから書く。
// 読み込みが終了して不要になればWriteBlockを先に進める
// 書き込みが終了して読み込み可になればReadBlockを先に進める
public
constructor Create;
function ReadNext(out Trips: TKeyRecord): Boolean;
function WriteNext(const Trips: TKeyRecord): Boolean;
function IsEmpty: Boolean;
end;
TKeyGenerater = class(TThread)
private
FpreFixed: String;
FpostFixed: String;
FvarString: String;
FSearchType: TSearchType;
FSearchForward: Boolean;
procedure SetPreFixed(s: String);
procedure SetPostFixed(s: String);
procedure SetVarString(s: String);
procedure SetSearchType(s: TSearchType);
procedure SetSearchDirection(sForward: Boolean);
function GetNextKey: String;
protected
procedure Execute; override;
public
property preFixed: String read FpreFixed write SetPreFixed;
property postFixed: String read FpostFixed write SetPostFixed;
property varString: String read FvarString write SetVarString;
property SerachType: TSearchType read FSearchType write SetSearchType;
property SerachForward: Boolean read FSearchForward write SetSearchDirection;
constructor Create;
end;
function NextChar(var c: Char; sType: TSearchType): Boolean;
function PreviousChar(var c: Char; sType: TSearchType): Boolean;
implementation
uses
StrUtils, Unit1, apollo;
function NextChar(var c: Char; sType: TSearchType): Boolean;
begin
Result := False;
case sType of
stNums:
begin
if c in ['0'..'8'] then
begin
Inc(c);
end else if c = '9' then
begin
c := '0';
Result := True;
end else
begin
c := '0'
end;
end;
stAlpha:
begin
if c in ['0'..'8','A'..'Y','a'..'y'] then
begin
Inc(c);
end else if c = '9' then
begin
c := 'A';
end else if c = 'Z' then
begin
c := 'a';
end else if c = 'z' then
begin
c := '0';
Result := True;
end else
begin
c := '0';
end;
end;
st7bit:
begin
if c in [#$20..#$7d] then
begin
Inc(c);
if c in ['&','<','>'] then
Inc(c);
end else if c = #$7e then
begin
c := #$20;
Result := True;
end else
begin
c := #$20;
end;
end;
stAll:
begin
if c = High(Char) then
Result := True;
Inc(c);
end;
end;
end;
function PreviousChar(var c: Char; sType: TSearchType): Boolean;
begin
Result := False;
case sType of
stNums:
begin
if c in ['1'..'9'] then
begin
Dec(c);
end else if c = '0' then
begin
c := '9';
Result := True;
end else
begin
c := '9'
end;
end;
stAlpha:
begin
if c in ['1'..'9','B'..'Z','b'..'z'] then
begin
Dec(c);
end else if c = 'A' then
begin
c := '9';
end else if c = 'a' then
begin
c := 'Z';
end else if c = '0' then
begin
c := 'z';
Result := True;
end else
begin
c := 'z';
end;
end;
st7bit:
begin
if c in [#$21..#$7e] then
begin
Dec(c);
if c in ['&','<','>'] then
Dec(c);
end else if c = #$20 then
begin
c := #$7e;
Result := True;
end else
begin
c := #$7e;
end;
end;
stAll:
begin
if c = Low(Char) then
Result := True;
Dec(c);
end;
end;
end;
constructor TTripList.Create;
begin
inherited;
FReadBlock := 1;
FWriteBlock := 0;
end;
function TTripList.IsEmpty: Boolean;
var
tmpNowRead: Integer;
tmpReadBlock: Integer;
begin
tmpNowRead := FWriteBlock;
tmpReadBlock := FReadBlock;
if (tmpNowRead = tmpReadBlock-1) or
((tmpNowRead = TripBufMax) and (tmpReadBlock = 0)) then
begin
Result := True;
end else
begin
Result := False;
end;
end;
function TTripList.ReadNext(out Trips: TKeyRecord): Boolean;
var
tmpNowRead: Integer;
tmpReadBlock: Integer;
begin
Result := False;
tmpNowRead := FWriteBlock;
tmpReadBlock := FReadBlock;
if (tmpNowRead = tmpReadBlock-1) or
((tmpNowRead = TripBufMax) and (tmpReadBlock = 0)) then
begin
Exit;
end;
if tmpNowRead = TripBufMax then
tmpNowRead := 0
else
Inc(tmpNowRead);
Trips := FTrips[tmpNowRead];
FWriteBlock := tmpNowRead;
Result := True;
end;
function TTripList.WriteNext(const Trips: TKeyRecord): Boolean;
var
tmpNowWrite: Integer;
begin
Result := False;
tmpNowWrite := FReadBlock;
if tmpNowWrite = FWriteBlock then
begin
Exit;
end;
FTrips[tmpNowWrite] := Trips;
if tmpNowWrite = TripBufMax then
tmpNowWrite := 0
else
Inc(tmpNowWrite);
FReadBlock := tmpNowWrite;
Result := True;
end;
constructor TKeyGenerater.Create;
begin
inherited Create(True);
FreeOnTerminate := False;
Priority := TThreadPriority(Form1.RadioGroupPriority.ItemIndex);
end;
function TKeyGenerater.GetNextKey: String;
type
TFunctionNext = function(var c: Char; sType: TSearchType): Boolean;
var
tmpVar: String;
len: Integer;
c: Char;
i: integer;
carry: Boolean;
funcNext: TFunctionNext;
begin
Result := FpreFixed + FvarString + FpostFixed;
tmpVar := FvarString;
len := length(tmpVar);
carry := True;
i := 1;
if FSearchForward then
funcNext := NextChar
else
funcNext := PreviousChar;
while((i <= len) and carry) do
begin
c := tmpVar[i];
carry := funcNext(c,FSearchType);
tmpVar[i] := c;
Inc(i);
end;
if carry then
begin
c := #0;
funcNext(c,FSearchType);
tmpVar := tmpVar + c;
end;
FvarString := tmpVar;
end;
procedure TKeyGenerater.SetPreFixed(s: String);
begin
if Suspended then
FpreFixed := s;
end;
procedure TKeyGenerater.SetPostFixed(s: String);
begin
if Suspended then
FpostFixed := s;
end;
procedure TKeyGenerater.SetVarString(s: String);
begin
if Suspended then
FvarString := s;
end;
procedure TKeyGenerater.SetSearchType(s: TSearchType);
begin
if Suspended then
FSearchType := s;
end;
procedure TKeyGenerater.SetSearchDirection(sForward: Boolean);
begin
if Suspended then
FSearchForward := sForward;
end;
procedure TKeyGenerater.Execute;
var
tmpTrip: TKeyRecord;
tTripKey: String;
tPubKey: String;
tSecKey: String;
tTripStr: String;
begin
while not Terminated do
begin
tTripKey := GetNextKey;
RSAkeycreate512(tPubKey,tSecKey,tTripKey);
tTripStr := triphash(tPubKey);
with tmpTrip do
begin
TripKey := tTripKey;
pubKey := tPubKey;
secKey := tSecKey;
TripStr := tTripStr;
end;
while (not TripList.WriteNext(tmpTrip)) and (not Terminated) do
begin
Sleep(1000);
end;
end;
end;
end.