[go: up one dir, main page]

Menu

[r19]: / source / qonguard1.pas  Maximize  Restore  History

Download this file

249 lines (214 with data), 6.9 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
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower OnGuard
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1996-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Andrew Haines andrew@haines.name {AH.01}
* conversion to CLX {AH.01}
* December 30, 2003 {AH.01}
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* ONGUARD1.PAS 1.13 *}
{* Copyright (c) 1996-02 TurboPower Software Co *}
{* All rights reserved. *}
{*********************************************************}
{$I onguard.inc}
{$B-} {Complete Boolean Evaluation}
{$I+} {Input/Output-Checking}
{$P+} {Open Parameters}
{$T-} {Typed @ Operator}
{$W-} {Windows Stack Frame}
{$X+} {Extended Syntax}
{$IFNDEF Win32}
{$G+} {286 Instructions}
{$N+} {Numeric Coprocessor}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{$ENDIF}
unit qonguard1;
{-Key generation dialog}
interface
uses
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs,
QStdCtrls, QButtons, QExtCtrls,
ogutil, onguard;
type
TKeyGenerateFrm = class(TForm)
OKBtn: TBitBtn;
CancelBtn: TBitBtn;
Panel1: TPanel;
Label4: TLabel;
Label2: TLabel;
Label3: TLabel;
GenerateBtn: TButton;
KeyTypeCb: TComboBox;
KeyStringMe: TMemo;
CopyBlockSb: TSpeedButton;
CopyByteKeySb: TSpeedButton;
BlockKeyEd: TEdit;
ByteKeyEd: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure KeyTypeCbChange(Sender: TObject);
procedure KeyStringMeChange(Sender: TObject);
procedure BlockKeyEdChange(Sender: TObject);
procedure ByteKeyEdChange(Sender: TObject);
procedure CopyBlockSbClick(Sender: TObject);
procedure CopyByteKeySbClick(Sender: TObject);
procedure GenerateBtnClick(Sender: TObject);
private
{ Private declarations }
FKey : TKey;
FKeyType : TKeyType;
procedure SetKeyType(Value : TKeyType);
public
{ Public declarations }
procedure SetKey(Value : TKey); {!!.08}
procedure GetKey(var Value : TKey); {!!.08}
property KeyType : TKeyType
read FKeyType
write SetKeyType;
end;
var
KeyGenerateFrm: TKeyGenerateFrm;
implementation
{$R *.xfm}
procedure TKeyGenerateFrm.FormCreate(Sender: TObject);
begin
KeyTypeCb.ItemIndex := Ord(FKeyType);
{set state of memo and generate button}
KeyStringMe.Enabled := (KeyTypeCb.ItemIndex <> 0);
case KeyStringMe.Enabled of
True : KeyStringMe.Color := clWindow;
False : KeyStringMe.Color := clBtnFace;
end;
GenerateBtn.Enabled := (KeyTypeCb.ItemIndex = 0) or
(KeyStringMe.Lines.Count > 0);
end;
procedure TKeyGenerateFrm.FormShow(Sender: TObject);
begin
KeyTypeCbChange(Sender);
end;
procedure TKeyGenerateFrm.KeyTypeCbChange(Sender: TObject);
begin
BlockKeyEd.Text := '';
ByteKeyEd.Text := '';
{set state of memo and generate button}
KeyStringMe.Enabled := (KeyTypeCb.ItemIndex <> 0);
case KeyStringMe.Enabled of
True : KeyStringMe.Color := clWindow;
False : KeyStringMe.Color := clBtnFace;
end;
GenerateBtn.Enabled := (KeyTypeCb.ItemIndex = 0) or
(KeyStringMe.Lines.Count > 0);
if KeyTypeCb.ItemIndex > -1 then
FKeyType := TKeyType(KeyTypeCb.ItemIndex);
end;
procedure TKeyGenerateFrm.KeyStringMeChange(Sender: TObject);
begin
BlockKeyEd.Text := '';
ByteKeyEd.Text := '';
{set state of generate button}
GenerateBtn.Enabled := (KeyTypeCb.ItemIndex = 0) or
(KeyStringMe.Lines.Count > 0);
end;
procedure TKeyGenerateFrm.BlockKeyEdChange(Sender: TObject);
begin
CopyBlockSb.Enabled := (BlockKeyEd.Text <> '');
end;
procedure TKeyGenerateFrm.ByteKeyEdChange(Sender: TObject);
begin
CopyByteKeySb.Enabled := (ByteKeyEd.Text <> '');
end;
procedure TKeyGenerateFrm.CopyBlockSbClick(Sender: TObject);
var
OldSelStart: Integer;
begin
if (BlockKeyEd.SelLength > 0) then
BlockKeyEd.CopyToClipboard
else begin
OldSelStart := BlockKeyEd.SelStart;
BlockKeyEd.SelStart := 0;
BlockKeyEd.SelLength := MaxInt;
BlockKeyEd.CopyToClipboard;
BlockKeyEd.SelStart := OldSelStart;
BlockKeyEd.SelLength := 0;
end;
end;
procedure TKeyGenerateFrm.CopyByteKeySbClick(Sender: TObject);
var
OldSelStart: Integer;
begin
if (ByteKeyEd.SelLength > 0) then
ByteKeyEd.CopyToClipboard
else begin
OldSelStart := ByteKeyEd.SelStart;
ByteKeyEd.SelStart := 0;
ByteKeyEd.SelLength := MaxInt;
ByteKeyEd.CopyToClipboard;
ByteKeyEd.SelStart := OldSelStart;
ByteKeyEd.SelLength := 0;
end;
end;
procedure TKeyGenerateFrm.GenerateBtnClick(Sender: TObject);
begin
case KeyTypeCb.ItemIndex of
0:
begin
Screen.Cursor := crHourGlass;
try
GenerateRandomKeyPrim(FKey, SizeOf(FKey));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
ByteKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
finally
Screen.Cursor := crDefault;
end;
end;
1:
begin
GenerateTMDKeyPrim(FKey, SizeOf(FKey), AnsiUpperCase(KeyStringMe.Text));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
ByteKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
end;
2:
begin
GenerateTMDKeyPrim(FKey, SizeOf(FKey), KeyStringMe.Text);
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
ByteKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
end;
end;
end;
procedure TKeyGenerateFrm.SetKeyType(Value : TKeyType);
begin
if Value <> FKeyType then begin
FKeyType := Value;
KeyTypeCb.ItemIndex := Ord(FKeyType);
end;
end;
procedure TKeyGenerateFrm.GetKey(var Value : TKey);
begin
Value := FKey;
end;
procedure TKeyGenerateFrm.SetKey(Value : TKey);
begin
FKey := Value;
end;
end.