unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TForm1 =
class
(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
N9: TMenuItem;
OpenDialog2: TOpenDialog;
Button1: TButton;
procedure
N6Click(Sender: TObject);
procedure
FormClose(Sender: TObject;
var
Action: TCloseAction);
procedure
N3Click(Sender: TObject);
procedure
N4Click(Sender: TObject);
procedure
N9Click(Sender: TObject);
procedure
N7Click(Sender: TObject);
procedure
N8Click(Sender: TObject);
procedure
Button1Click(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
fMess,fEncrypt,fKey:
File
;
X :
array
[
0..7
]
of
Cardinal
;
EnCrypt:
boolean
;
implementation
{$R *.dfm}
procedure
TForm1
.
N6Click(Sender: TObject);
begin
close;
end
;
procedure
TForm1
.
FormClose(Sender: TObject;
var
Action: TCloseAction);
begin
Release;
end
;
procedure
TForm1
.
N3Click(Sender: TObject);
begin
if
OpenDialog1
.
Execute
then
begin
AssignFile(fMess,OpenDialog1
.
FileName);
end
;
end
;
procedure
TForm1
.
N4Click(Sender: TObject);
begin
if
SaveDialog1
.
Execute
then
begin
AssignFile(fEncrypt,SaveDialog1
.
FileName);
end
;
end
;
procedure
TForm1
.
N9Click(Sender: TObject);
var
v32b:
cardinal
;
myKey:
byte
;
i,j:
byte
;
begin
if
OpenDialog2
.
Execute
then
begin
AssignFile(fKey,OpenDialog2
.
FileName);
Reset(fKey,
1
);
for
i:=
7
downto
0
do
begin
X[i]:=
0
;
for
j:=
7
downto
0
do
begin
v32b:=
0
;
myKey:=
0
;
BlockRead(fKey,myKey,
1
);
if
(
$30
<=myKey)
and
(myKey<=
$39
)
then
X[i]:=X[i]
or
((v32b
or
(myKey-
$30
))
shl
(j*
4
))
else
X[i]:=X[i]
or
((v32b
or
(myKey-
$37
))
shl
(j*
4
));
end
;
end
;
end
;
end
;
procedure
TForm1
.
N7Click(Sender: TObject);
begin
EnCrypt:=
true
;
end
;
procedure
TForm1
.
N8Click(Sender: TObject);
begin
EnCrypt:=
false
;
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
var
N1,N2,N12,SM1,reserv,shablon,v32b,ost:
Cardinal
;
RoundNumber,j,l,n,Limit:
byte
;
K:
array
[
0..7
]
of
byte
;
const
Kltab:
array
[
0..7
,
0..15
]
of
byte
= (
(
$4
,
$A
,
$9
,
$2
,
$D
,
$8
,
$0
,
$E
,
$6
,
$B
,
$1
,
$C
,
$7
,
$F
,
$5
,
$3
),
(
$E
,
$B
,
$4
,
$C
,
$6
,
$D
,
$F
,
$A
,
$2
,
$3
,
$8
,
$1
,
$0
,
$7
,
$5
,
$9
),
(
$5
,
$8
,
$1
,
$D
,
$A
,
$3
,
$4
,
$2
,
$E
,
$F
,
$C
,
$7
,
$6
,
$0
,
$9
,
$B
),
(
$7
,
$D
,
$A
,
$1
,
$0
,
$8
,
$9
,
$F
,
$E
,
$4
,
$6
,
$C
,
$B
,
$2
,
$5
,
$3
),
(
$6
,
$C
,
$7
,
$1
,
$5
,
$F
,
$D
,
$8
,
$4
,
$A
,
$9
,
$E
,
$0
,
$3
,
$B
,
$2
),
(
$4
,
$B
,
$A
,
$0
,
$7
,
$2
,
$1
,
$D
,
$3
,
$6
,
$8
,
$5
,
$9
,
$C
,
$F
,
$E
),
(
$D
,
$B
,
$4
,
$1
,
$3
,
$F
,
$5
,
$9
,
$0
,
$A
,
$E
,
$7
,
$6
,
$8
,
$2
,
$C
),
(
$1
,
$F
,
$D
,
$0
,
$5
,
$7
,
$A
,
$4
,
$9
,
$2
,
$3
,
$E
,
$6
,
$B
,
$8
,
$C
));
begin
Reset(fMess,
1
);
Rewrite(fEncrypt,
1
);
while
not
EOF(fMess)
do
Begin
N1:=
0
;
N2:=
0
;
try
BlockRead(fMess,N1,
4
,ost);
try
BlockRead(fMess,N2,
4
);
except
on
EInOutError
do
end
;
except
on
EInOutError
do
n2 :=
0
;
end
;
RoundNumber:=
0
;
if
EnCrypt
then
begin
Limit:=
24
;
n:=
7
;
end
else
begin
Limit:=
8
;
n:=
7
;
end
;
while
RoundNumber <
32
do
Begin
if
RoundNumber < Limit
then
reserv:=X[RoundNumber
mod
8
]
else
begin
reserv:=X[n];
if
n=
0
then
n:=
8
;
dec(n);
end
;
asm
mov eax, reserv;
add eax, N1;
mov SM1, eax;
end
;
l:=
7
;
shablon:=
0
;
for
j:=
0
to
7
do
begin
reserv:=SM1;
K[j]:=(reserv
shl
(l*
4
))
shr
28
;
K[j]:=Kltab[j,K[j]];
v32b:=
0
;
shablon:=shablon
or
((v32b
or
K[j])
shl
(j*
4
));
dec(l);
end
;
asm
rol shablon,
11
;
end
;
if
RoundNumber=
31
then
begin
N2:=shablon
xor
N2;
BREAK;
end
;
N12:=shablon
xor
N2;
N2:=N1;
N1:=N12;
inc(RoundNumber);
End
;
BlockWrite(fEncrypt,N1,
4
);
BlockWrite(fEncrypt,N2,
4
);
End
;
CloseFile(fMess);
CloseFile(fEncrypt);
Application
.
MessageBox(
'exelent!'
,
'crypto'
);
end
;
end
.