на тему рефераты Информационно-образоательный портал
Рефераты, курсовые, дипломы, научные работы,
на тему рефераты
на тему рефераты
МЕНЮ|
на тему рефераты
поиск
Программа для шифрования данных с помощью шифра Тритемиуса
p align="left">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

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

if (((shifr(text1[i]))-(shifr(keyword1[q])))>=0) then

m:=(((shifr(text1[i]))-(shifr(keyword1[q])))mod 31)

else m:=(((shifr(text1[i]))-(shifr(keyword1[q])))+31);

kk:=deshifr(m);

otvet:=otvet+kk;

q:=q+1;

if q=(length(keyword)+1) then q:=1;

end;

writeln;

writeln('Decrypted text:',otvet);

writeln('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;

write('Press <Enter> for continue decryption 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('Decryption 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);

if (((shifr(c1))-(shifr(keyword1[q])))>=0) then

m:=(((shifr(c1))-(shifr(keyword1[q])))mod 31)

else m:=(((shifr(text1[i]))-(shifr(keyword1[q])))+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 decrypt:');

repeat read(f2,c1);write(c1) until(EOF(f2));

writeln;

write('Decrypted text:');

repeat read(f3,c1);write(c1) until(EOF(f3));

writeln;

write('Press <Enter> for continue decryption or <Esc> for exit');

repeat

c1:=readkey;

until(c1=#13)or(c1=#27);

end;

until(c1=#27);

end;

end;

end;

until (c=#27);

end;

until (a='0');

end.

2.5 Порядок ввода исходных данных и описание получаемых результатов

-программа выдает меню пользователю;

-после входа в меню шифровки(дешифровки) запрашивает ключевое слово для шифрования, длина которого не должна быть превышать 15 символов;

-если слово не введено - выдает соответствующее сообщение и просит ввести его;

-если длина ключевого слова не соответствует условию, программа выдает соответствующее сообщение и просит ввести заново;

-программа игнорирует ввод цифр, то есть цифры не отображаются и не заносятся в память, не давая пользователю тем самым ошибиться;

-программа пропускает пробелы до и после слова и не считывает их, ввод продолжается до нажатия <Enter> либо до отмены с помощью <Esc>;

-после программа просит выбрать режим работы с текстом - вручную или из файла;

-если выбран режим ввода вручную просит ввести текст, длина которого не должна превышать 230 символов;

-проверка ввода текста такая же, как у ключевого слова;

-если выбрана работа с файлами просит ввести имя файла;

-после в обоих случаях выдает шифрованный текст;

-для выхода в основное меню предлагается нажать <Esc>,для продолжения работы в подменю - <Enter>,для выхода из программы предлагается нажать <0>.

2.6 Описание тестовых заданий и анализ правильности функционирования

Рис.1 Начальное окно

Рис. 2 Подменю шифровки. После ввода ключевого слова предлагается два режима ввода текста - вручную либо из файла

Рис.2.1Пример шифрования вручную

Рис.2.2 Пример шифрования из файла( файл содержит комбинацию ab_c1d2ef)

Рис.3.1.Меню дешифровки. Пример ввода вручную. Из рис 2.1 следует что шифрование произведено правильно

Рис.3.2.Пример дешифрования из файла. (файл содержит комбинацию b_d1d2f3fh ) Из рис 2.2 следует что дешифрование произведено правильно

3. Литература

1 Прайс Д. Программирование на языке Паскаль: Практическое руководство. Перевод с англ.-М:.Мир,1987.-232с.;

2. Фаронов В.В. Ф24 Турбо Паскаль(в 3-х экземплярах).Кн.3.Практика программирования. Часть 1.-М.:Учебно-инженерный центр «МВТУ - ФЕС ТО ДИДАКТИК»,1993.-238с.

3. Перминов О.Н. Программирование на языке Паскаль. - М.:Радио и связь,1989.-224 с. 128 с.

4. Грогоно П. Программирование на языке Паскаль: Пер. с англ./Под ред. Д.Б. Подшивалова. - М.: Мир, 1985. - 392 с.

Страницы: 1, 2



© 2003-2013
Рефераты бесплатно, курсовые, рефераты биология, большая бибилиотека рефератов, дипломы, научные работы, рефераты право, рефераты, рефераты скачать, рефераты литература, курсовые работы, реферат, доклады, рефераты медицина, рефераты на тему, сочинения, реферат бесплатно, рефераты авиация, рефераты психология, рефераты математика, рефераты кулинария, рефераты логистика, рефераты анатомия, рефераты маркетинг, рефераты релиния, рефераты социология, рефераты менеджемент.