7146-1 (588359), страница 4
Текст из файла (страница 4)
{Получить текущую позицию процесса}
NowPos := 100*Position/DirInfo.Size;
inc(Position, 2);
if NowPos > 100 then NowPos := 100;
Str(Round(NowPos):3, Pos);
if OptInd = 0 then
begin
GoToXY(77, 1);
Write(Pos + '%');
end;
{Шифровать с помощью ПСЧ}
Code:=Mas[i];
T[i] := (A * T[i-1] + C) mod M;
Code:=T[i] xor Code;
Mas[i] := Code;
end;
for i:=1 to 8 do { Конечная перестановка }
for j:=1 to 8 do
case i of
1: MasEnd[8*(j-1)+i] := Mas[41-j];
2: MasEnd[8*(j-1)+i] := Mas[09-j];
3: MasEnd[8*(j-1)+i] := Mas[49-j];
4: MasEnd[8*(j-1)+i] := Mas[17-j];
5: MasEnd[8*(j-1)+i] := Mas[57-j];
6: MasEnd[8*(j-1)+i] := Mas[25-j];
7: MasEnd[8*(j-1)+i] := Mas[65-j];
8: MasEnd[8*(j-1)+i] := Mas[33-j]
end;
for i:= 1 to 64 do Write(OutF, MasEnd[i]);
end;
until eof(InpF);
MyMessageBox('Файл '+ InputFileName + ' зашифрован с именем ' +
OutputFileName, nil, mfInformation+mfOkButton);
Close(InpF);
if OptFile = 1 then Erase(InpF);
Close(OutF);
end
else MyMessageBox('Файл '+ InputFileName + ' не существует!',
nil, mfInformation+mfOkButton);
end
else MyMessageBox(' Ошибка ввода пароля!!!', nil,
mfError+mfOkButton);
end
else MyMessageBox(' Файл не выбран!!!', nil, mfError+mfOkButton);
end;
procedure DeShifr(InputFileName: String);
const
A = 5;
C = 27;
M = 65536;
var
InpF, OutF : file of word;
Password, OutputFileName : string;
Password1 : string;
Exten : string[3];
SCode, Temp, Ext, TByte, Code: word;
I, J, K : byte;
Position : LongInt;
NowPos : real;
TPassword : array [1..255] of word;
MasByte, Mas, MasEnd, PS : array [1..64] of word;
T : array [0..64] of word;
DirInfo : SearchRec;
begin
if (length(InputFileName) > 3) and
(copy(InputFileName, length(InputFileName)-2, 3) = 'M&A') then
begin
Password := '';
Password1 := '';
InputBox('П А Р О Л Ь', ' Введите пароль:', Password, 255);
InputBox('П А Р О Л Ь', 'Введите пароль еще раз:', Password1, 255);
if (Password = Password1) and (length(Password)<>0) then
begin
FindFirst(InputFileName, AnyFile, DirInfo);
if DOSError = 0 then
begin
Assign(InpF, InputFileName);
Reset(InpF);
Position := 0;
Exten := '';
for i:= 1 to 3 do
begin
Read(InpF, Temp);
Exten := Exten + chr(Temp);
end;
for i := length(InputFileName) downto 1 do
if InputFileName[i] = '.' then
begin
OutputFileName := copy(InputFileName, 1, i) + Exten;
break;
end;
Assign(OutF, OutputFileName);
Rewrite(OutF);
for i := 1 to length(Password) do TPassword[i]:=ord(Password[i]);
k := 1;
repeat
begin
for i:=1 to 64 do Read(InpF, MasByte[i]);
for i:=1 to 8 do { начальная перестановка }
for j:=1 to 8 do
case i of
1: Mas[8*(i-1)+j]:=MasByte[66-8*j];
2: Mas[8*(i-1)+j]:=MasByte[68-8*j];
3: Mas[8*(i-1)+j]:=MasByte[70-8*j];
4: Mas[8*(i-1)+j]:=MasByte[72-8*j];
5: Mas[8*(i-1)+j]:=MasByte[65-8*j];
6: Mas[8*(i-1)+j]:=MasByte[67-8*j];
7: Mas[8*(i-1)+j]:=MasByte[69-8*j];
8: Mas[8*(i-1)+j]:=MasByte[71-8*j]
end;
T[0] := ord(Password[k]);
if k < length(Password) then inc(k) else k := 1;
for i:= 1 to 64 do
begin
NowPos := 100*Position/DirInfo.Size;
inc(Position, 2);
If NowPos > 100 then NowPos := 100;
Str(Round(NowPos):3, Pos);
if OptInd = 0 then
begin
GoToXY(77, 1);
Write(Pos + '%');
end;
T[i] := (A * T[i-1] + C) mod M;
Code:=Mas[i];
Code:=T[i] xor Code;
Mas[i] := Code;
end;
MasEnd := Mas;
for i := 1 to 64 do Write(OutF, MasEnd[i]);
end;
until eof(InpF);
GotoXY(77, 1);
write('100%');
MyMessageBox('Файл '+ InputFileName + ' расшифрован в ' +
OutputFileName, nil, mfInformation+mfOkButton);
Close(InpF);
if OptFile = 1 then Erase(InpF);
Close(OutF);
end
else MyMessageBox('Файл '+ InputFileName + ' не существует!',
nil, mfInformation+mfOkButton);
end
else MyMessageBox(' Ошибка ввода пароля!!!', nil,
mfError+mfOkButton);
end
else MyMessageBox(' Файл не выбран!!!', nil,
mfError+mfOkButton);
end;
{Опции криптографии}
constructor TOptions.Init;
var
R : TRect;
Q, Q1: PView;
Butt : TRadioButtons;
begin
R.Assign(0, 0, 60, 11);
inherited Init(R, 'Криптография');
Options := Options or ofCentered;
R.Assign(10, 8, 20, 10);
Insert(New(PButton, Init(R, '~А~га', cmOK, bfDefault)));
R.Assign(40, 8, 50, 10);
Insert(New(PButton, Init(R, '~Н~ека', cmCancel, bfNormal)));
R.Assign(2, 2, 25, 3);
Insert(New(PLabel, Init(R, 'Исходный файл:', Q)));
R.Assign(5, 4, 21, 6);
Q:=New(PRadioButtons, Init(R,
NewSItem('~Н~е удалять',
NewSItem('~У~далять', nil))));
Insert(Q);
R.Assign(27, 2, 45, 3);
Insert(New(PLabel, Init(R, 'Индикатор:', Q1)));
R.Assign(30, 4, 50, 6);
Q1:=New(PRadioButtons, Init(R,
NewSItem('~В~ысвечивать',
NewSItem('~Н~е высвечивать', nil))));
Insert(Q1);
end;
{Изменение пароля на вход в систему}
procedure Passwords;
var
Ps, Ps1: string;
I : byte;
tmp : char;
begin
Ps := '';
Ps1 := '';
InputBox('П А Р О Л Ь', 'Введите пароль:', Ps, 255);
for i:= 1 to length(Ps) do Ps[i] :=chr(ord(Ps[i]) xor 27);
if Ps <> Pass then
begin
MyMessageBox(' Неверный пароль!!!', nil, mfError+mfOkButton);
ClrScr;
writeln('Несанкционированный доступ!');
Halt;
end;
InputBox('И З М Е Н Е Н И Е П А Р О Л Я',
'Введите новый пароль:', Ps, 255);
InputBox('И З М Е Н Е Н И Е П А Р О Л Я',
' Повторите ввод:', Ps1, 255);
if (Ps = Ps1) and (Ps <> '') then
begin
Assign(FilePass, 'system.res');
Rewrite(FilePass);
for i := 1 to length(PS) do
begin
tmp := chr(ord(Ps[i]) xor 27);
Write(FilePass, tmp);
end;
Close(FilePass);
end
else MyMessageBox(' Ошибка ввода пароля!!!', nil, mfError+mfOkButton);
end;
{Обработка ошибок}
procedure CheckExec;
var
St: string;
begin
Str(DOSError, St);
case DOSError of
2: MyMessageBox(' Ошибка DOS № ' +
St + ' "Файл не найден"',
nil, mfError + mfOkButton);
3: MyMessageBox(' Ошибка DOS № ' +
St + ' "Путь не найден"',
nil, mfError + mfOkButton);
5: MyMessageBox(' Ошибка DOS № ' +
St + '"Неверный код доступа к файлу"',
nil, mfError + mfOkButton);
6: MyMessageBox(' Ошибка DOS № ' +
St + '"Неверный код системного обработчика файла"',
nil, mfError + mfOkButton);
8: MyMessageBox(' Ошибка DOS № ' +
St + ' "Недостаточно памяти"',
nil, mfError + mfOkButton);
10: MyMessageBox(' Ошибка DOS № ' +
St + ' "Неверная среда"',
nil, mfError + mfOkButton);
11: MyMessageBox(' Ошибка DOS № ' +
St + ' "Неправильный формат"',
nil, mfError + mfOkButton);
18: MyMessageBox(' Ошибка DOS № ' +
St + '"Нет свободных обработчиков для файлов"',
nil, mfError + mfOkButton);
end;
end;
procedure MakeComFile(k: byte);
const
S : array [1..4] of string = ('c:\sub_rosa\plus.', 'c:\sub_rosa\passw.',
'c:\sub_rosa\block.', 'c:\sub_rosa\keydisk.');
Size : array [1..4] of word = (1068, 204, 617, 2118);
Inden: array [1..4, 1..3] of byte = ((ord('ы'), 26 , ord('Р')),
(ord('ы'), 39 , ord('Р')),
(ord('щ'), ord('Й'), ord('_')),
(ord('щ'), ord('А'), ord('_')));
var
I, Tmp : byte;
F : array [1..4, 1..2] of file ;
M : array [1..2200] of byte ;
NumRead, NumWritten: Word;
begin
assign(F[k, 1], S[k]); reset(F[k, 1], 1);
assign(F[k, 2], S[k]+'com'); rewrite(F[k, 2], 1);
for i := 1 to 3 do
begin
BlockRead(F[k, 1], tmp, 1, NumRead);
BlockWrite(F[k, 2], Inden[k, i], 1, NumWritten);
end;
BlockRead(F[k, 1], M, Size[k]-3, NumRead);
BlockWrite(F[k, 2], M, Size[k]-3, NumWritten);
close(F[k, 1]); close(F[k, 2]);
end;
procedure DelComFile(k: byte);
const
{ S: array [1..4] of string =
('plus.com', 'passw.com', 'block.com', 'keydisk.com');}
S : array [1..4] of string = ('c:\sub_rosa\plus.com',
'c:\sub_rosa\passw.com',
'c:\sub_rosa\block.com',
'c:\sub_rosa\keydisk.com');
var
F: array [1..4] of file;
begin
Assign(F[k], S[k]);
Erase(F[k]);
end;
{****************************************************************************}
{*----------=========== Д О П И С А Т Ь К Ф А Й Л У ==========----------*}
{****************************************************************************}
procedure Plus(WhatDo: string);
var
FileStr, Err: string;
CmdLine : string;
I : byte;
FileName : FNameStr;
Regs : Registers;
begin
{Проверка условий}
if Length(FName) > 3 then
begin
if (copy(FName, length(FName)-2, 3) = 'EXE') or
(copy(FName, length(FName)-2, 3) = 'COM')
then
begin
{Преобразование имени файла}
for i:= length(fname) downto 1 do
if fname[i] = '\' then
begin
CmdLine := copy(FName, i+1, length(FName) - i);
break;
end;
for i := 1 to length(CmdLine) do
if CmdLine[i] in ['A'..'Z'] then
CmdLine[i] := chr(ord(CmdLine[i]) + 32);
for i := 1 to length(MainDir) do
if MainDir[i] in ['A'..'Z'] then
MainDir[i] := chr(ord(MainDir[i]) + 32);
MakeComFile(1);
If WhatDo = SetPass then MakeComFile(2);
If WhatDo = KeyDisk then MakeComFile(4);
{Выполнить дописывание}
SwapVectors;
Exec( MainDir + 'plus.com ', CmdLine + ' ' + MainDir + WhatDo);
SwapVectors;
DelComFile(1);
If WhatDo = SetPass then DelComFile(2);
If WhatDo = KeyDisk then DelComFile(4);
{Обработчик ошибок}
if DosError <> 0 then
CheckExec
else
begin
regs.ah := $4D;
with regs do
msdos(regs);
case Regs.AH of
0 : MyMessageBox(' Файл ' + FName + ' защищен.',
nil, mfInformation + mfOkButton);
1 : MyMessageBox(' Ctrl-C или Ctrl-Break.',
nil, mfError + mfOkButton);
2 : MyMessageBox(' Критическая ошибка устройства.',
nil, mfError + mfOkButton);
3 : MyMessageBox(' TSR - программа.',
nil, mfError + mfOkButton);
end;
end;
end
else MyMessageBox(' Ошибка выбора файла !!! ',
nil, mfError + mfOkButton);
end
else MyMessageBox(' Файл не выбран!!! ',
nil, mfError + mfOkButton);
end;
{****************************************************************************}
{*----------===== Б Л О К И Р О В К А В И Н Ч Е С Т Е Р А ======----------*}
{****************************************************************************}
procedure LockDisk;
label
end_;
var
Regs: registers;
Err : string;
Inst: byte;
begin
{Проверка наличи программы в памяти}
asm
push ax
push dx
mov Inst, 0
mov ax,1059h
mov dx,2517h
int 13h
cmp ax,2517h
jne End_
cmp dx,1059h
jne End_
mov Inst, 1
End_: pop dx
pop ax
end;
if Inst = 0 then
begin
MakeComFile(3);
{Установить защиту}
SwapVectors;
SetIntVec($09, Int09_Save);