unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class
(TForm)
Button1: TButton;
procedure
Button1Click(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
key:
array
[
0..9
]
of
byte
= (
123
,
60
,
48
,
50
,
89
,
33
,
145
,
97
,
56
,
29
);
implementation
{$R *.dfm}
procedure
TForm1
.
Button1Click(Sender: TObject);
var
nom, razmerhvosta, bs, bs1, s1:
byte
;
razmer, change, sxor, sizefile8:
int64
;
keyround:
array
[
0..31
]
of
int64
;
b8in, b8out:
array
[
0..7
,
0..10000
]
of
byte
;
openfl, closefl: TFileStream;
i, i1, i2, i4:
integer
;
const
sbox:
array
[
1..16
]
of
byte
= (
5
,
14
,
15
,
8
,
12
,
1
,
2
,
13
,
11
,
4
,
6
,
3
,
0
,
7
,
9
,
10
);
pbox:
array
[
1..64
]
of
byte
= (
0
,
4
,
8
,
12
,
16
,
20
,
24
,
28
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
60
,
1
,
5
,
9
,
13
,
17
,
21
,
25
,
29
,
33
,
37
,
41
,
45
,
49
,
53
,
57
,
61
,
2
,
6
,
10
,
14
,
18
,
22
,
26
,
30
,
34
,
38
,
42
,
46
,
5
,
54
,
58
,
62
,
3
,
7
,
11
,
15
,
19
,
23
,
27
,
31
,
35
,
39
,
43
,
47
,
51
,
55
,
59
,
63
);
begin
OpenFl:=TFileStream
.
Create(
'text.txt'
,fmOpenRead);
OpenFl
.
Position:=
0
;
CloseFl:=TFileStream
.
Create(
'crypted.bin'
,fmCreate);
CloseFl
.
Position:=
0
;
sizefile8:= OpenFl
.
Size
div
8
;
for
i:=
0
to
7
do
for
i1:=
0
to
sizefile8
do
OpenFl
.
Read(b8in[i, i1],
1
);
razmerhvosta:= OpenFl
.
Size - sizefile8 *
8
;
if
(razmerhvosta >
0
)
then
for
i2:= i1
to
razmerhvosta
do
OpenFl
.
Read(b8in[i+
1
, i2],
1
);
if
(razmerhvosta <
7
)
then
for
i2:=i2
to
7
do
OpenFl
.
Read(b8in[i+
1
,i2],
1
);
for
i:=
0
to
31
do
begin
for
nom:=
0
to
7
do
begin
change:= key[nom]
shl
(
8
* (
7
- nom));
Inc(keyround[i], change);
end
;
change:=keyround[i1];
razmer:= change
shr
60
;
razmer:=razmer
shl
60
;
change:=razmer + ((change
shl
4
)
shr
4
);
razmer:=(change
shl
44
)
shr
59
;
razmer:= razmer
xor
i;
razmer:=razmer
shl
15
;
change:=((change
shr
20
)
shl
20
) + ((change
shl
49
)
shl
49
) + razmer;
keyround[i]:=change;
end
;
for
i4:=
0
to
(sizefile8 +
1
)
do
for
i:=
0
to
30
do
begin
for
i1:=
0
to
7
do
sxor:=sxor + (b8in[i4,i1])
shl
(
7
- i1);
sxor:=sxor
xor
keyround[i];
for
i1:=
0
to
7
do
b8in[i4,i1]:=sxor
shr
(
7
-i1);
i1:=
0
;
for
i2:=
0
to
7
do
begin
Inc(i1);
nom:=sbox[i1]
div
2
;
if
(sbox[i1]
mod
2
=
0
)
then
begin
bs:=b8in[i4,nom]
shr
4
;
bs:=bs
shl
4
;
end
else
bs:= b8in[i4,nom]
shl
4
;
Inc(i1);
nom:=sbox[i1]
div
2
;
if
(sbox[i1]
mod
2
=
0
)
then
bs1:=b8in[i4,nom]
shr
4
else
begin
bs1:=b8in[i4,nom]
shl
4
;
bs1:=bs1
shr
4
;
end
;
b8out[i4,i2]:=bs+bs1;
b8in[i4,i2]:=b8out[i4, i2];
end
;
bs1:=
0
;
for
s1:=
0
to
63
do
begin
nom:=pbox[s1]
div
8
;
bs:=b8out[i4,nom];
bs:=bs
shl
(pbox[s1]
mod
8
);
bs:=bs
shr
7
;
bs:=bs
shl
(
7
- pbox[s1]);
bs1:=bs1+bs;
b8out[i4,s1
div
8
]:=b8out[i4,s1
div
8
]+bs1;
end
;
end
;
for
i:=
0
to
(sizefile8 +
1
)
do
for
i1:=
0
to
7
do
OpenFl
.
write
(b8out[i,i1],
1
);
OpenFl
.
Free;
CloseFl
.
Free;
end
;
end
.