Курсовая работа: Программа для шифрования данных с помощью шифра Тритемиуса
writeln;
writeln('Press
<m> for enter text manually or <f> for encrypt fron the file');
repeat
{предлагаем
работу с файлом или вручную}
z:=readkey;
until(z='f')or(z='m')or(z=#27);
if
(z<>#27) then begin
if
z='m' then begin
Writeln('Please
enter the text to encrypt(min length-1 symbols,max length-230)');
Repeat
{если
выбран режим ввода вручную,запрашиваем текст для шифрования}
l:=0;j:=0;text:='';h:=true;enter:=true;probel:=true;
c:=readkey;write(c);l:=1;
if
ord(c)<>27 then
if
ord(c)=13 then begin enter:=false;writeln('Text is not entered.Please
enter');end else
begin
text:=text+c;h:=proverka1(c);
repeat
c:=readkey;if
(proverka(c)=true) then begin
if
c=#8 then backspace(text) else write(c);
if
((c<>#8) and (c<>' ') and (ord(c)<>13) and
(ord(c)<>27)) then
begin
text:=text+c;
l:=l+1;
end;
end;
until
(ord(c)=13) or (ord(c)=27) or (l=231);
if
ord(c)<>27 then begin
if
(text=' ') then begin probel:=false;writeln('Text is not entered.Please
enter');end;
if
(h=false) then
begin
write('You
enter invalid text with numeral.Press <Enter> and try again');
readln;
end;
if
(l=231) then
begin
write('Exceeded
the maximum length of string.Press <Enter>');
repeat
c:=readkey;
until
(c=#13);
end;
end;
end;
until((probel)and(h)and(enter))
or (c=#27); {проверки аналогичные
проверкам
ключевого
слова}
if
(probel)and(h)and(enter)and(text<>'')and(keyword<>'')and(c<>#27)
then
begin
for
i:= 1 to length(keyword) do
keyword1[i]:=copy(keyword,i,1);
for
i:= 1 to
length(text)
do {переводим
ключевое слово и текст в массивы}
text1[i]:=copy(text,i,1);
q:=1;
for
i:=1 to length(text) do
begin
m:=(((shifr(text1[i]))+(shifr(keyword1[q])))mod
31);
kk:=deshifr(m);
otvet:=otvet+kk;
q:=q+1;
if
q=(length(keyword)+1) then q:=1;
end;
{шифруем
текст}
writeln;
writeln('Encrypted
text:',otvet);
write('Save
encrypted text in fail?(y-yes,n-now)'); {предлагаем
сохранить
шифрованный
текст
в
файл}
repeat
z:=readkey;
until(z='y')or(z='Y')or(z='n')or(z='N');
if
(z='y')or(z='Y') then begin
writeln('Enter
the name of the file'); {если нажато
<Да>
просим
ввести
имя
файла}
repeat
l:=0;j:=0;imyafaila:='';h:=true;enter:=true;probel:=true;result:=true;
c1:=readkey;write(c1);l:=1;
if
ord(c1)<>27 then
if
ord(c1)=13 then begin enter:=false;writeln('Filename is not entered.Please
enter');end else
begin
imyafaila:=imyafaila+c1;h:=proverka1(c1);
repeat
c1:=readkey;if
(proverka(c1)=true) then begin
if
c1=#8 then backspace(imyafaila) else write(c1);
if
((c1<>#8) and (c1<>' ') and (ord(c1)<>13) and
(ord(c1)<>27)) then
begin
imyafaila:=imyafaila+c1;
l:=l+1;
end;
end;
until
(ord(c1)=13) or (ord(c1)=27) or (l=50);
if
ord(c1)<>27 then begin
if
(imyafaila=' ') then begin probel:=false;writeln('Filename is not entered.Please
enter');end;
if
(h=false) then
begin
write('You
enter invalid filename with numeral.Press <Enter> and try again');
readln;
end;
if
(l=50) then
begin
write('Exceeded
the maximum length of string.Press <Enter>');
repeat
c1:=readkey;
until
(c1=#13);
end;
end;
end;
until
((probel)and(h)and(enter)and(result)) or (c1=#27);
assign(f,imyafaila);
{$I-}
reset(f);
{$I+}
result:=IOResult=0;
if
not result then rewrite(f) else begin reset(f);if filesize(f)<>0 then
repeat read(f,c);until(EOF(f));end; {если
файл
существует
перемещаем
курсор
в
конец
файла,либо
создаем
новый
файл}
for
i:=1 to length(otvet) do
write(f,otvet[i]);
{записываем данные}
close(f);
end;
writeln;
writeln('Press
<Enter> for continue encryption or <Esc> for exit');{предлагаем
продолжить
шифрование}
repeat
c:=readkey;
until
(c=#13)or (c=#27);
end;
end;
if
(z='f')
then {если
выбрана работа с файлами вручную предлагается ввести имя файла; ввод
продолжается до тех пор, пока не будет найден файл с правильным именем}
begin
repeat
clrscr;
probel1(10);Writeln('Encryption
text (for return in maimmenu press <Esc>)');
writeln('Enter
the name of the file');
repeat
l:=0;j:=0;imyafaila:='';h:=true;enter:=true;probel:=true;result:=true;
c1:=readkey;write(c1);l:=1;
if
ord(c1)<>27 then
if
ord(c1)=13 then begin enter:=false;writeln('Filename is not entered.Please
enter');end else
begin
imyafaila:=imyafaila+c1;h:=proverka1(c1);
repeat
c1:=readkey;if
(proverka(c1)=true) then begin
if
c1=#8 then backspace(imyafaila) else write(c1);
if
((c1<>#8) and (c1<>' ') and (ord(c1)<>13) and
(ord(c1)<>27)) then
begin
imyafaila:=imyafaila+c1;
l:=l+1;
end;
end;
until
(ord(c1)=13) or (ord(c1)=27) or (l=50);
if
ord(c1)<>27 then begin
if
(imyafaila=' ') then begin probel:=false;writeln('Filename is not
entered.Please enter');end;
if
(h=false) then
begin
write('You
enter invalid filename with numeral.Press <Enter> and try again');
readln;
end;
if
(l=50) then
begin
write('Exceeded
the maximum length of string.Press <Enter>');
repeat
c1:=readkey;
until
(c1=#13);
end;
assign(f,imyafaila);
{$I-}
reset(f);
{$I+}
result:=IOResult=0;
if
not result then begin writeln('File not found.Try again');result:=false;end
else
close(f);
end;
end;
until
((probel)and(h)and(enter)and(result)) or (c1=#27);
if
(result) and (c1<>#27) then
begin
for
i:= 1 to length(keyword) do
keyword1[i]:=copy(keyword,i,1);
assign(f2,'laba2.txt');
rewrite(f2);
reset(f);
repeat
read(f,c1);
if
((ord(c1)>=65)and(ord(c1)<=90)or(ord(c1)>=97)and(ord(c1)<=122))
then
write(f2,c1);
{проверяем данные из файла, считываем только кириллицу,заносим во второй файл }
until
EOF(f);
close(f);
close(f2);
reset(f2);
assign(f3,'laba3.txt');
rewrite(f3);
q:=1;
repeat
read(f2,c1);
m:=(((shifr(c1))+(shifr(keyword1[q])))mod
31);
kk:=deshifr(m);
write(f3,kk);
q:=q+1;
if
q=(length(keyword)+1) then q:=1;
until(EOF(f2));
{шифруем и заносим данные в третий файл}
close(f2);
close(f3);
reset(f2);
reset(f3);
write('Text
for encrypt:');
repeat
read(f2,c1);write(c1) until(EOF(f2));
writeln;
write('Encrypted
text:');
repeat
read(f3,c1);write(c1) until(EOF(f3));
writeln;
write('Press
<Enter> for continue encryption or <Esc> for exit');
repeat
c1:=readkey;
{предлагается продолжить шифрование}
until(c1=#13)or(c1=#27);
end;
until(c1=#27);
end;
end;
end;
until
(c=#27);
end;
if
(a='2') then
begin {действия
второго подменю аналогичны действиям первого подменю}
clrscr;
repeat
if
c=#13 then clrscr;
textattr:=7;
probel1(10);Writeln('Decryption
text (for return in maimmenu press <Esc>)');
repeat
Writeln('Please
enter keyword for decryption(min length-1 symbol,max length-15)');
l:=0;j:=0;keyword:='';h:=true;enter:=true;probel:=true;
c:=readkey;write(c);l:=1;otvet:='';
if
ord(c)<>27 then
if
ord(c)=13 then begin enter:=false;writeln('Keyword is not entered.Please
enter');end else
begin
keyword:=keyword+c;h:=proverka1(c);
repeat
c:=readkey;if
(proverka(c)=true) then begin
if
c=#8 then backspace(keyword) else write(c);
if
((c<>#8) and (c<>' ') and (ord(c)<>13) and
(ord(c)<>27)) then
begin
keyword:=keyword+c;
l:=l+1;
end;
end;
until
(ord(c)=13) or (ord(c)=27) or (l=16);
if
ord(c)<>27 then begin
if
(keyword=' ') then begin probel:=false;writeln('Keyword is not entered.Please
enter');end;
if
(h=false) then
begin
write('You
enter invalid keyword with numeral.Press <Enter> and try again');
readln;
end;
if
(l=16) then
begin
write('Exceeded
the maximum length of string.Press <Enter>');
repeat
c:=readkey;
until
(c=#13);
end;
end;
end;
until
((probel)and(h)and(enter)) or (c=#27);
if
(probel)and(h)and(enter) and (c<>#27) then begin
writeln;
writeln('Press
<m> for enter text manually or <f> for encrypt fron the file');
repeat
z:=readkey;
until(z='f')or(z='m')or(z=#27);
if
(z<>#27) then begin
if
z='m' then begin
Writeln('Please
enter the text to decrypt(min length-1 symbols,max length-230)');
repeat
l:=0;j:=0;text:='';h:=true;enter:=true;probel:=true;
c:=readkey;write(c);l:=1;
if
ord(c)<>27 then
if
ord(c)=13 then begin enter:=false;writeln('Text is not entered.Please
enter');end else
Страницы: 1, 2, 3 |