MultiBlock Posted November 25, 2006 Report Share Posted November 25, 2006 Вот написал 2 программы: кодирование и декодирование текстовой информации методом Гронсфельда. Нужна помощь! Нужно их объеденить. Пытался сам, как ни странно не вышло. Переставало работать. И еще вопрос: когда програма записывает в файл результаты кодирования или декодирования она еще почему приписывает к каждой строчке путь до этого файла. Почему? И если можно, сделать какую нибудь меню для выбора: кодирование или декодирования можно было выбирать. Не судите строго, я только начал изучать Pascal, а программа идет как курсовик. Очень нужно. Помогите! Программа кодирования: {CodingProgram reads a file S and writes down result in S1}function getnum(c: char): integer;var n: integer;begin case c of'0': n := 0;'1': n := 1;'2': n := 2;'3': n := 3;'4': n := 4;'5': n := 5;'6': n := 6;'7': n := 7;'8': n := 8;'9': n := 9; elsen := -1; end; getnum := n;end;const N1 = 5; { The maximum quantity of lines in a file } N2 = 3; { Quantity of alphabets }var f,f1: text; s,n,s1: string; i,j,k,l,m: integer; c: integer; { The counter of a position in a line of a code } w : array [1..N1] of string; { Lines } w1 : array [1..N1] of string; { Lines } abc : array [1..N2] of string; { Alphabets }begin abc[1] := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; abc[2] := 'abcdefghijklmnopqrstuvwxyz'; abc[3] := '0123456789'; writeln('*** Coding of the text information by method Gronsfelds ***'); write('Enter a full way to a file from which it is readable: '); readln(s); write('Enter a full way to a file in which we write: '); readln(s1); write('Enter a digital key (4 figures or less): '); readln(n);{} assign(f,s); assign(f1,s1); reset(f); rewrite(f1); i := 1; { Reads a file } while not EOF(f) and (i<=N1) do beginreadln(f,w[i]); w1[i]:=w[i];inc(i); end; { We code }{ 1-st cycle - in the lines from a file }{ 2-nd cycle - on elements in line from a file }{ 3-rd cycle - under alphabets }{ 4-th cycle - on elements of the alphabet } c := 1; for i := 1 to N1 do if ord(w[i][0])<>0 then for j := 1 to (ord(w[i][0])+1) do for k := 1 to N2 do for l := 1 to (ord(abc[k][0])+1) do beginif abc[k][l]=w[i][j] then begin m := l+getnum(n[c]); inc©; if c>ord(n[0]) then c := 1; if m>ord(abc[k][0]) then m := m-ord(abc[k][0]); w1[i][j] := abc[k][m];end; end; for i:=1 to N1 do beginwriteln(w[i]);writeln(w1[i]); end; for i := 1 to N1 do beginfor j := 1 to ord(w1[i][0]) do write(f1,w1[i][j]);writeln(f1,s1,''); end; writeln('Press Enter for an output'); read(s);end. Программа декодирования {DecodingProgram reads a file S and writes down result in S1}function getnum(c: char): integer;var n: integer;begin case c of'0': n := 0;'1': n := 1;'2': n := 2;'3': n := 3;'4': n := 4;'5': n := 5;'6': n := 6;'7': n := 7;'8': n := 8;'9': n := 9; elsen := -1; end; getnum := n;end;const N1 = 5; { The maximum quantity of lines in a file } N2 = 3; { Quantity of alphabets }var f,f1: text; s,n,s1: string; i,j,k,l,m: integer; c: integer; { The counter of a position in a line of a code } w : array [1..N1] of string; { Lines } w1 : array [1..N1] of string; { Lines } abc : array [1..N2] of string; { Alphabets }begin abc[1] := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; abc[2] := 'abcdefghijklmnopqrstuvwxyz'; abc[3] := '0123456789'; writeln('*** Decoding of the text information by method Gronsfelds ***'); write('Enter a full way to a file from which it is readable: '); readln(s); write('Enter a full way to a file in which we write: '); readln(s1); write('Enter a digital key (4 figures or less): '); readln(n);{} assign(f,s); assign(f1,s1); reset(f); rewrite(f1); i := 1; { Reads a file } while not EOF(f) and (i<=N1) do beginreadln(f,w[i]); w1[i]:=w[i];inc(i); end; { We code }{ 1-st cycle - in the lines from a file }{ 2-nd cycle - on elements in line from a file }{ 3-rd cycle - under alphabets }{ 4-th cycle - on elements of the alphabet } c := 1; for i := 1 to N1 do if ord(w[i][0])<>0 then for j := 1 to (ord(w[i][0])+1) do for k := 1 to N2 do for l := 1 to (ord(abc[k][0])+1) do beginif abc[k][l]=w[i][j] then begin m := l-getnum(n[c]); inc©; if c>ord(n[0]) then c := 1; if m<1 then m := m+ord(abc[k][0]); w1[i][j] := abc[k][m];end; end; for i:=1 to N1 do beginwriteln(w[i]);writeln(w1[i]); end; for i := 1 to N1 do beginfor j := 1 to ord(w[i][0]) do write(f1,w1[i][j]);writeln(f1,s1,''); end; writeln('Press Enter for an output'); read(s);end. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.