unit Unit5 interface uses Windows Messages SysUtils Variants Classes G

 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
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tfirst = '1' .. '8';
Tsecond = '1' .. '8';
const
TPolibius: array[Tfirst, Tsecond] of char = (
('_', 'А', 'Б', 'В', 'Г','Д', 'Е', 'Ё'),
('Ж', 'З', 'И','Й','К', 'Л','М', 'Н'),
('О','П', 'Р', 'С', 'Т', 'У','Ф', 'Х'),
('Ц','Ч', 'Ш', 'Щ','Ъ', 'Ы','Ь','Э'),
('Ю', 'Я', '0', '1','2', '3', '4','5'),
('6', '7', '8', '9', '(',')', '[', ']'),
('{', '}', '.', ',', ':',';', '?', '!'),
('-', '"', '+', '=', '№','%', '*', '/')
);
function PolibiusEncipher(toCode: string): string;
var
i: integer;
ix: Tfirst; jx: Tsecond;
s: string;
begin
s := '';
for i := 1 to length(toCode) do begin
for ix := Low(Tfirst) to High(Tfirst) do
for jx := Low(Tsecond) to High(Tsecond) do
if TPolibius[ix, jx] = toCode[ i ] then begin
s := s + ix + jx; break;
end;
end;
PolibiusEncipher := s
end;
function PolibiusDecipher(toDecode: string): string;
var
i: integer;
s: string;
begin
s := '';
i := 1;
while i <= length(toDecode) do begin
s := s + TPolibius[toDecode[ i ], toDecode[succ(i)]];
inc(i, 2);
end;
PolibiusDecipher := s
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
s := PolibiusEncipher('POLIBIUS');
// writeln(s);
Memo1.lines.add(s);
Memo1.lines.add('s = '+ PolibiusDecipher(s));
end;
end.