procedure
TForm1
.
Button5Click(Sender: TObject);
var
nom:
byte
; razmer,change,sxor:
int64
;
keyround:
array
[
0..31
]
of
int64
;
b8in,b8out:
array
[
0..7
,
0..1000000
]
of
byte
;
razmerhvosta:
byte
;
bs,bs1,s1:
byte
;
sizefile8:
int64
;
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
OpenFile:=TFileStream
.
Create(Edit4
.
Text,fmOpenRead);
OpenFile
.
Position:=
0
;
CloseFile:=TFileStream
.
Create(
'crypted.bin'
,fmCreate);
CloseFile
.
Position:=
0
;
sizefile8:=OpenFile
.
Size;
sizefile8:=sizefile8
div
8
;
for
i:=
0
to
sizefile8
do
for
i1:=
0
to
7
do
OpenFile
.
Read(b8in[i,i1],
1
);
razmerhvosta:=OpenFile
.
Size - sizefile8*
8
;
if
(razmerhvosta >
0
)
then
for
i2:=i1
to
razmerhvosta
do
OpenFile
.
Read(b8in[i+
1
,i2],
1
);
if
(razmerhvosta <
7
)
then
for
i2:=i2
to
7
do
OpenFile
.
Read(b8in[i+
1
,i2],
1
);
for
i:=
0
to
31
do
begin
begin
for
nom:=
0
to
7
do
begin
change:=key[nom];
change:=change
shl
(
8
*(
7
-nom));
keyround[i]:=keyround[i] + change;
end
;
change:=keyround[i1];
razmer:=change
shr
60
;
razmer:=sbox[change];
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
;
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
i1:=i1+
1
;
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
;
i1:=i1+
1
;
nom:=sbox[i1]
div
2
;
if
(sbox[i1]
mod
2
=
0
)
then
bs1:=b8in[i4,nom]
shr
4
else
begin
bs1:=b8in[i,nom]
shl
4
;
bs1:=bs1
shr
4
;
end
;
b8out[i4,i2]:=bs+bs1;
b8in[i4,i2]:=b8out[i,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
OpenFile
.
write
(b8out[i,i1],
1
);
OpenFile
.
Free;
CloseFile
.
Free;
end
;