implementation
uses
unit2,unit3;
{$R *.dfm}
procedure
TForm1
.
FormActivate(Sender: TObject);
begin
tabcontrol1
.
Visible:=
false
;
cod:=
2
;
t:=
0
;
end
;
procedure
TForm1
.
N4Click(Sender: TObject);
begin
label1
.
Caption:=
'Файл для шифровки'
;
label2
.
Caption:=
'Файл для выхода'
;
tabcontrol1
.
Visible:=
true
;
label1
.
Visible:=
true
;
edit1
.
Visible:=
true
;
edit1
.
Text:=
''
;
button1
.
Visible:=
true
;
label2
.
Visible:=
true
;
edit2
.
Visible:=
true
;
edit2
.
Text:=
''
;
button2
.
Visible:=
true
;
t:=
1
;
combobox1
.
Visible:=
false
;
button3
.
Caption:=
'Выполнить'
;
button3
.
Visible:=
true
;
button5
.
Visible:=
false
;
combobox2
.
Visible:=
false
;
combobox2
.
ItemIndex:=
0
;
label3
.
Visible:=
false
;
label3
.
Caption:=
'Размер файла'
;
end
;
procedure
TForm1
.
N5Click(Sender: TObject);
begin
label1
.
Caption:=
'Файл для дешифровки'
;
label2
.
Caption:=
'Файл для выхода'
;
tabcontrol1
.
Visible:=
true
;
label1
.
Visible:=
true
;
edit1
.
Visible:=
true
;
edit1
.
Text:=
''
;
button1
.
Visible:=
true
;
label2
.
Visible:=
true
;
edit2
.
Visible:=
true
;
edit2
.
Text:=
''
;
button2
.
Visible:=
true
;
t:=
2
;
combobox1
.
Visible:=
false
;
button3
.
Caption:=
'Выполнить'
;
button3
.
Visible:=
true
;
button5
.
Visible:=
false
;
combobox2
.
Visible:=
false
;
label3
.
Visible:=
false
;
end
;
procedure
TForm1
.
N2Click(Sender: TObject);
begin
tabcontrol1
.
Visible:=
true
;
label1
.
Visible:=
true
;
label1
.
Caption:=
'Типа параметры'
;
edit1
.
Visible:=
false
;
edit1
.
Text:=
''
;
button1
.
Visible:=
false
;
label2
.
Visible:=
false
;
edit2
.
Visible:=
false
;
edit2
.
Text:=
''
;
button2
.
Visible:=
false
;
combobox1
.
Visible:=
true
;
button3
.
Caption:=
'Сохранить'
;
button3
.
Visible:=
true
;
t:=
0
;
button5
.
Visible:=
false
;
combobox2
.
Visible:=
false
;
label3
.
Visible:=
false
;
end
;
procedure
TForm1
.
N3Click(Sender: TObject);
begin
close
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
var
f1:
file
;u:
char
;
begin
If
OpenDialog1
.
Execute
then
begin
if
Length(Opendialog1
.
Files[
0
])<>
0
then
edit1
.
Text:=opendialog1
.
FileName;
if
t=
2
then
begin
assignfile(f1,edit1
.
Text);
reset(f1,
1
);
blockread(f1,u,sizeof(u));
blockread(f1,u,sizeof(u));
label3
.
Caption:=
'Кол-во частей: '
+u;
label3
.
Visible:=
true
;
end
;
end
;
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
begin
If
OpenDialog2
.
Execute
then
begin
if
Length(Opendialog2
.
Files[
0
])<>
0
then
edit2
.
Text:=opendialog2
.
FileName;
end
;
end
;
procedure
TForm1
.
Button3Click(Sender: TObject);
var
k:
string
;f1,f2:
file
;c:
array
[
1..1024
]
of
char
;u:
char
;
i,j,b,r,NumWritten,NumRead:
Integer
;
label
ex;
begin
if
t<>
0
then
begin
if
((length(edit1
.
Text)=
0
)
and
(t=
1
))
then
begin
showmessage(
'Не выбран файл для шифрования!'
);
exit;
end
;
if
((length(edit1
.
Text)=
0
)
and
(t=
2
))
then
begin
showmessage(
'Не выбран файл для дешифрования!'
);
exit;
end
;
if
length(edit2
.
Text)=
0
then
begin
showmessage(
'Не выбран выходной файл!'
);
exit;
end
;
assignfile(f1,edit1
.
text);
{
$I
-}
reset(f1,
1
);
{
$I
+}
if
ioresult<>
0
then
begin
showmessage(
'Ошибка чтения файла!'
);
exit;
end
;
if
t=
2
then
begin
blockread(f1,u,sizeof(u));
case
strtoint(u)
of
1
:cod:=
2
;
2
:cod:=
4
;
3
:cod:=
8
;
4
:cod:=
16
;
5
:cod:=
32
;
6
:cod:=
64
;
7
:cod:=
128
;
8
:cod:=
246
;
end
;
blockread(f1,u,sizeof(u));
closefile(f1);
end
else
begin
assignfile(f2,edit2
.
text);
{
$I
-}
rewrite(f2,
1
);
{
$I
+}
if
ioresult<>
0
then
begin
showmessage(
'Ошибка записи файла!'
);
exit;
end
;
case
cod
of
2
:u:=
'1'
;
4
:u:=
'2'
;
8
:u:=
'3'
;
16
:u:=
'4'
;
32
:u:=
'5'
;
64
:u:=
'6'
;
128
:u:=
'7'
;
256
:u:=
'8'
;
end
;
BlockWrite(f2, u, sizeof(u));
BlockWrite(f2, u, sizeof(u));
closefile(f2);
end
;
m:=
1
;
b:=
1
;
if
t=
1
then
begin
fis:=edit2
.
Text;
repeat
BlockRead(f1, c, SizeOf(c), NumRead);
k:=hextostr(strtohex(c,t));
r:=GetFileSize(fis);
for
j:=
1
to
length(k)
do
c[j]:=k[j];
reset(f2,
1
);
seek (f2, FileSize(f2));
BlockWrite(f2, c,numread, numwritten);
closefile(f2);
until
(numread=
0
)
or
(NumWritten <> NumRead);
closefile(f1);
end
else
begin
fis:=edit1
.
Text;
assignfile(f2,edit2
.
Text);
{
$I
-}
rewrite(f2,
1
);
{
$I
+}
if
ioresult <>
0
then
begin
showmessage(
''
);
exit;
end
;
for
i:=
1
to
strtoint(u)
do
begin
assignfile(f1,fis);
{
$I
-}
reset(f1,
1
);
{
$I
+}
if
ioresult<>
0
then
begin
form3
.
ShowModal;
if
e=
1
then
goto
ex
else
begin
assignfile(f1,fis);
reset(f1,
1
);
end
;
end
;
if
i=
1
then
seek(f1,
2
);
repeat
BlockRead(f1, c, SizeOf(c), NumRead);
k:=hextostr(strtohex(c,t));
for
j:=
1
to
length(k)
do
c[j]:=k[j];
reset(f2,
1
);
seek (f2, FileSize(f2));
BlockWrite(f2, c,numread, numwritten);
closefile(f2);
until
(numread=
0
)
or
(NumWritten <> NumRead);
closefile(f1);
fis:=ExtractFilePath(edit1
.
Text)+ExtractFileName(edit1
.
Text)+
' '
+inttostr(i);
end
;
end
;
showmessage(
'Выполнено!!!'
);
tabcontrol1
.
Visible:=
false
;
end
else
begin
ex: tabcontrol1
.
Visible:=
false
;
t:=
0
;
cod:=strtoint(combobox1
.
Text);
end
;
end
;
procedure
TForm1
.
Button4Click(Sender: TObject);
begin
tabcontrol1
.
Visible:=
false
;
t:=
0
;
end
;
function
TForm1
.
StrToHex(source:
string
; t:
integer
):
string
;
var
e,o,s:
string
; c:
Char
;i:
integer
;
begin
s :=
''
;
for
i:=
1
to
Length(source)
do
begin
c:=source[i];
e:=IntToHex(
Integer
(c),
2
);
if
m
mod
cod =
0
then
begin
o:=e;
case
e[
1
]
of
'F'
: e[
1
]:=
'0'
;
'E'
: e[
1
]:=
'1'
;
'D'
: e[
1
]:=
'2'
;
'C'
: e[
1
]:=
'3'
;
'B'
: e[
1
]:=
'4'
;
'A'
: e[
1
]:=
'5'
;
'9'
: e[
1
]:=
'6'
;
'8'
: e[
1
]:=
'7'
;
'7'
: e[
1
]:=
'8'
;
'6'
: e[
1
]:=
'9'
;
'5'
: e[
1
]:=
'A'
;
'4'
: e[
1
]:=
'B'
;
'3'
: e[
1
]:=
'C'
;
'2'
: e[
1
]:=
'D'
;
'1'
: e[
1
]:=
'E'
;
'0'
: e[
1
]:=
'F'
;
end
;
case
e[
2
]
of
'F'
: e[
2
]:=
'0'
;
'E'
: e[
2
]:=
'1'
;
'D'
: e[
2
]:=
'2'
;
'C'
: e[
2
]:=
'3'
;
'B'
: e[
2
]:=
'4'
;
'A'
: e[
2
]:=
'5'
;
'9'
: e[
2
]:=
'6'
;
'8'
: e[
2
]:=
'7'
;
'7'
: e[
2
]:=
'8'
;
'6'
: e[
2
]:=
'9'
;
'5'
: e[
2
]:=
'A'
;
'4'
: e[
2
]:=
'B'
;
'3'
: e[
2
]:=
'C'
;
'2'
: e[
2
]:=
'D'
;
'1'
: e[
2
]:=
'E'
;
'0'
: e[
2
]:=
'F'
;
end
;
end
;
s:=s+e; m:=m+
1
;
end
;
result:=s;
end
;
function
TForm1
.
HexToStr(hex:
string
):
string
;
var
i:
integer
;
begin
s:=
''
;
for
i:=
1
to
Length(hex)
div
2
do
begin
s:=s +
Char
(StrToInt(
'$'
+ Copy(hex, (i-
1
) *
2
+
1
,
2
)));
end
;
result:=s;
end
;
procedure
TForm1
.
Button5Click(Sender: TObject);
var
c,d,cd:
string
; f1,f2,f3:textfile;
begin
if
length(edit1
.
Text)=
0
then
begin
showmessage(
'Выберите файл1!'
);
exit;
end
;
assignfile(f1,edit1
.
Text);
{
$I
-}
reset(f1);
{
$I
+}
if
ioresult<>
0
then
begin
showmessage(
'Ошибка чтения файла1!'
);
exit;
end
;
if
length(edit2
.
Text)=
0
then
begin
showmessage(
'Выберите файл2!'
);
exit;
end
;
assignfile(f2,edit2
.
Text);
{
$I
-}
reset(f2);
{
$I
+}
if
ioresult<>
0
then
begin
showmessage(
'Ошибка чтения файла2!'
);
exit;
end
;
assignfile(f3,
'raznita.txt'
);
{
$I
-}
rewrite(f3);
{
$I
+}
if
ioresult<>
0
then
begin
showmessage(
'Ошибка записи результата!'
);
exit;
end
;
while
not
eof(f1)
do
begin
readln(f1,c);
readln(f2,d);
if
c<>d
then
writeln
(f3,c+
' '
+d);
end
;
cd:=getcurrentdir();
showmessage(
'Результат записан в '
+cd+
'\разница.txt'
);
closefile(f1);
closefile(f2);
closefile(f3);
end
;
procedure
TForm1
.
N6Click(Sender: TObject);
begin
label1
.
Caption:=
'Файл 1:'
;
label2
.
Caption:=
'Файл 2:'
;
tabcontrol1
.
Visible:=
true
;
label1
.
Visible:=
true
;
edit1
.
Visible:=
true
;
edit1
.
Text:=
''
;
button1
.
Visible:=
true
;
label2
.
Visible:=
true
;
edit2
.
Visible:=
true
;
edit2
.
Text:=
''
;
button2
.
Visible:=
true
;
combobox1
.
Visible:=
false
;
button3
.
Visible:=
false
;
button5
.
Visible:=
true
;
combobox2
.
Visible:=
false
;
label3
.
Visible:=
false
;
end
;