-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit1.pas
135 lines (111 loc) · 2.7 KB
/
unit1.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
{ KOL MCK } // Do not remove this line!
{$DEFINE KOL_MCK}
{$ifdef FPC} {$mode delphi} {$codepage utf8} {$endif}
unit Unit1;
interface
uses Windows, Messages, KOL {place your units here->}
{$IFDEF LAZIDE_MCK}, Forms, mirror, Classes, Controls, mckCtrls, mckObjs, Graphics;
{$ELSE} ; {$ENDIF}
type
{ TForm1 }
{$I MCKfakeClasses.inc}
{$IFDEF KOLCLASSES} TForm1 = class; PForm1 = TForm1; {$ELSE OBJECTS} PForm1 = ^TForm1; {$ENDIF CLASSES/OBJECTS}
TForm1 = {$IFDEF LAZIDE_MCK}class(TForm{$ELSE}{$IFDEF KOLCLASSES}class{$ELSE}object{$ENDIF}(TObj{$ENDIF})
ButtonDecrypt: TKOLButton;
MyDropDown: TKOLComboBox;
Form: PControl;
ButtonEncrypt: TKOLButton;
KOLForm1: TKOLForm;
KOLProject: TKOLProject;
MyMemo: TKOLMemo;
procedure ButtonDecryptClick(Sender: PObj);
procedure ButtonEncryptClick(Sender: PObj);
procedure FormCreate(Sender: TObject);
procedure KOLForm1FormCreate(Sender: PObj);
procedure MyDropDownClick(Sender: PObj);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1 {$IFDEF KOL_MCK} : PForm1 {$ELSE} : TForm1 {$ENDIF} ;
{$IFDEF KOL_MCK}
procedure NewForm1( var Result: PForm1; AParent: PControl );
{$ENDIF}
implementation
{$IFNDEF KOL_MCK} {$R *.lfm} {$ENDIF}
{ TForm1 }
{$IFNDEF LAZIDE_MCK}
{$IFDEF KOL_MCK}
{$I unit1_1.inc}
{$ENDIF}
{$ENDIF}
function StrToInt(src: String): Integer;
var
int: Integer;
code: Integer;
begin
Val(src, int, code);
Result := int;
end;
function indexOf(src: String; dst: String): Integer;
var
idx: Integer;
l: String;
begin
idx := 0;
for l in src do
begin
idx := idx + 1;
if (l = dst) then
begin
Result := idx;
end;
end;
end;
function crypt(plaintext: String; shift: Integer): String;
var
ciphertext: String;
alphabet: String;
pt: String;
ct: String;
idx: Integer;
begin
alphabet := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
ciphertext := '';
idx := 0;
for pt in plaintext do
begin
if (pt = ' ') then
ciphertext := ciphertext + ' '
else begin
idx := (indexOf(alphabet, pt) + shift) mod 26;
while (idx <= 0) do idx := idx + 26;
if (idx > 0) then
begin
ct := alphabet[idx];
ciphertext := ciphertext + ct;
end;
end
end;
Result := ciphertext;
end;
procedure TForm1.ButtonEncryptClick(Sender: PObj);
begin
MyMemo.Text := crypt(MyMemo.Text, StrToInt(MyDropdown.Caption));
end;
procedure TForm1.ButtonDecryptClick(Sender: PObj);
begin
MyMemo.Text := crypt(MyMemo.Text, -StrToInt(MyDropdown.Caption));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
procedure TForm1.KOLForm1FormCreate(Sender: PObj);
begin
end;
procedure TForm1.MyDropDownClick(Sender: PObj);
begin
end;
end.