Программа для шифрования данных с помощью шифра Тритемиуса

Программа для шифрования данных с помощью шифра Тритемиуса

Программа для шифрования данных с помощью шифра Тритемиуса

Федеральное агентство по образованию Российской Федерации
Государственное образовательное учреждение высшего профессионального образования
«Южно-Уральский государственный университет»
Факультет «Приборостроительный»
Кафедра «Электронные вычислительные машины»
ПОЯСНИТЕЛЬНАЯ ЗАПИСКА
К КУРСОВОЙ РАБОТЕ
«Программирование на языках высокого уровня»
Автор проекта
студент группы
Валимухамматов Рустам Римович
Челябинск 2010г.

Содержание
1. Описание применения
1.1 Описание задачи и метода ее решения
1.2 Входные и выходные данные
2. Описание программы
2.1 Структура программы
2.2 Структуры используемых данных
2.3 Схема алгоритма
2.4.Текст программы
2.5 Порядок ввода исходных данных и описание получаемых результатов
2.6 Описание тестовых заданий и анализ правильности функционирования
3. Литература

1. Описание применения
1.1 Описание задачи и метода ее решения
Составить программу на языке Turbo Pascal для шифрования данных с помощью шифра Тритемиуса(расширение кода Цезаря).Выглядит это так.
Буквы алфавита нумеруются. Затем ключевое слово циклически накладывается на кодируемый текст. Кодовая буква получается как остаток от деления суммы номера буквы кодируемого текста и ключевого слова на число 31 например (ключевое слово bc)
a b c d e f
k 00 01 02 03 04 05
b c b c b c
1 01 02 01 02 01 02
m 01 03 03 05 05 07
kk b d d f f h
Таким образом кодовая комбинация получается bddffh.
Ниже приведена таблица номеров букв
A – 00; N – 13;
B – 01; O – 14;
C – 02; P – 15;
D – 03; Q – 16;
E – 04; R – 17;
F – 05; S – 18;
G – 06; T – 19;
H – 07; U – 20;
I – 08; V – 21;
J – 09; W – 22;
K – 10; X – 23;
L – 11; Y – 24 ;
M – 12; Z – 25;
1.2 Входные и выходные данные
На вход программе подается ключевое слово. Затем задается текст для шифрования(дешифрования, в зависимости от выбранного меню) вручную, либо указанием имени файла с текстом. Минимальная длина текст и ключевого слово – 1 символ. Максимальная длина ключевого слово – 15 символов, максимальная длина текста, заданного вручную, – 230 символов(при чтении из файла ограничений нету).
На выход программа выдает шифрованный (дешифрованный) текст.

2. Описание программы
2.1 Структура программы
Программа организована цельным текстом, пошагово. Язык интерфейса – английский.
Программа выполняет следующие действия
-строит графическое оформление;
-предлагает меню из 3-х пунктов;
-после захода в подменю запрашивает ключевое слово(всегда, в независимости от выбранного меню);
-запрашивает текст для (де)шифрования (либо просит ввести имя файла, если чтение происходит оттуда);
-выдает (де)шифрованный текст(либо также исходный, если чтение из файла);
-предлагает продолжить (де)шифрование, либо вернуться в главное меню.
2.2 Структуры используемых данных
mas=array[1..15] of string — массив ,куда заносятся символы ключевого слова
mas1= array[1..230] of string — массив строкового типа для введенного текста
с,с1 — переменные символьного типа для считывания с клавиатуры символов(либо из файла);;
keyword,text,otvet, imyafaila – переменные строкового типа;в них заносится ключевое слово, текст для шифрования, получившийся (де)шифрованный текст, и имя файла для дальнейшей работы с ним;
h,probel,enter – переменные логического типа, используемые для различных проверок на вводе данных;
kk — переменная используется для построения (де)шифрованного текста
f,f2,f3 — файлы символьного типа для сохранения(считывания)данных
function proverka — функция для проверки вводимого текста. Становится равной true если вводимый символ буква;
function shifr — функция шифрования. В качестве аргумента выступает переменная строкового типа, но, так как, в программе заранее задается что эта переменная будет длиною в один символ, функция сначала переводит переменную в символьный тип, затем используется порядковый номер символа в таблице ASCII для шифрования;
function deshifr — функция дешифрования. Используется также порядковый номер символа в таблице ASCII;
backspace -функция корректировки вводимых данных, стирает последний вводимый символ.

2.3 Схема алгоритма

2.4 Текст программы
program kursach;
uses crt;
type mas=array[1..15] of string;
mas1=array[1..230] of string;
function proverka(q char) boolean;
begin
if ((ord(q)>=65) and (ord(q)<=90)) or ((ord(q)>=97)) and ((ord(q)<=122)) or (q=#8)
or (q=#27) or (q=#13) or(q=’.’) then proverka =true else proverka =false;
end;
function proverka1(q1 char) boolean;
begin
if ((ord(q1)<65) or (ord(q1)>90) and (ord(q1)<97) or (ord(q1)>122)) then proverka1 =false;
end;
function shifr(y1 string) integer;
var y2 array[1..2] of string;y char;
begin
y2[1] =y1;
y =y2[1][1];
if ((ord(y)>=65)and(ord(y)<=90))
then shifr =(ord(y)-65) else
if ((ord(y)>=97)and(ord(y)<=122))
then shifr =(ord(y)-97)
end;
function deshifr(z integer) char;
begin
deshifr =(chr(z+97));
end;
procedure backspace(var s21 string);
var i1 integer;s31 string;
begin
if length(s21)<>0 then begin
gotoXY(whereX-1,whereY);
write(‘ ‘);
gotoXY(whereX-1,whereY);
s31 =»;
for i1 =1 to (length(s21)-1) do s31 =s31+s21[i1];
s21 =s31;
end;
end;
procedure probel1(i2 integer);
var i3 integer;
begin
for i3 =1 to i2 do write(‘ ‘);
end;
var a,c,c1,z,vixod char;keyword1 mas;
text1 mas1;
s,keyword,text,otvet,imyafaila string;
i,k,l,o,j,d,sdvig,u integer;h,probel,enter,t,y,p,result boolean;
kk char;m,q integer;
f,f2,f3 file of char;
begin
clrscr;
textattr =116;
for i =1 to 80 do write(‘=’);
window (1,0,1,7);
for i =1 to 6 do writeln(‘*’);
window (1,8,80,9);
for i =1 to 80 do write(‘=’);
window (80,2,80,8);
for i =1 to 6 do write (‘*’);
textattr =3;
window (20,3,80,5);
write (‘Work for programming on high-level languages’);
window (25,5,80,6);
write (‘Encryption based on Tritemius code’);
textattr =6;
window (44,7,80,8);
write (‘Made by Valimyxammatov Rustam,PS-197’);
window (5,9,80,25);
sdvig =0;
textattr =7;
repeat
clrscr;
probel1(28);writeln(‘MainMenu.Press ‘);
probel1(5);writeln(‘1 — for encryption’);
probel1(5);writeln(‘2 — for decryption’);
probel1(5);write(‘0 — for exit’);
repeat
a =readkey; {запрашиваем выбор меню}
until (a=’0′) or (a=’1′) or (a=’2′) or (a=’3′);
if (a=’1′) then
begin
clrscr;
repeat
if c=#13 then clrscr;
textattr =7;
probel1(10);Writeln(‘Encryption text (for return in maimmenu press <Esc>)’);
repeat
Writeln(‘Please enter keyword for encryption(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 { если первый символ не клавиша Esc}
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); {продолжаем ввод пока не нажат Enter}
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 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
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 с.