Tell me please. I hung on some strange situation. The program for encoding and decoding wrote. It works - everything is ok. The text is encoded, but with the decoding of something extremely strange and I can not understand how this is possible.

Firstly: the file is decoded completely except for the last 3.5 lines. How so? Secondly: all the files that I launch are encoded, but not all are decoded, only selectively - something is yes, something is not. If the file is not decoded, the program creates it but leaves it blank. Why?

I also take into account the fact that I encode and decode the same file. In the sense that at first bora is ready - I encode it in a new - empty, I decode it in the third - a new empty. Then I compare the values ​​and - on you!

const Ckey=3; function shifr(i:char):char; begin ord(I):=ord(i)+Ckey; if ord(i)>255 then ord(i):=ord(i)-255+32; shifr:=i; end; function deshifr(i:char):char; begin ord(I):=ord(I)-Ckey; if ord(i)<32 then ord(i):=ord(i)+255-32; deshifr:=i; end; procedure strshifr(var a1,b1:text); var x:integer; s:string; begin reset(a1); rewrite(b1); while (not EOF(a1)) do begin readln(a1,s); for x:=1 to length(s) do s[x]:=shifr(s[x]); writeln(b1,s); end; close(b1); end; procedure strdeshifr(var b2,c2:text); var x:integer; s:string; begin reset(b2); rewrite(c2); while (not EOF(b2)) do begin readln(b2,s); For x:=1 to length(s) do s[x]:=deshifr(s[x]); writeln(c2,s); end; end; var a,b,c:text; x:integer; q:string; begin assign(a,'P_24_1.pas'); assign(b,'P_26_3.pas'); assign(c,'P_26_4.pas'); writeln('Введите номер действия:1-шифровать, 2-дешифровать'); readln(x); case x of 1:q:='Программа шифрования запущена'; 2:q:='Программа дешифрования запущена' else q:='неверный номер действия'; end; writeln(q); if x=1 then strshifr(a,b); if x=2 then strdeshifr(b,c); close(a); close(b); close(c); readln; end. 
  • @lioppo, all psychics are on vacation, and mere mortal visitors of this forum cannot debug a photo. Give the code of your program. - fori1ton
  • code in the next question. Look here please. there is not enough space here - lioppo
  • @lioppo young lady, you are hurt by Bormann. Sorry, from Borland. To make such a kidnapping out of a nice educational language of pascal ... Probable mistake - stumbles on the second close (): the first is close in the procedure, the second - from the third line from the bottom. And as a result, it is covered without writing the file tail to the disk. Still. Construction ord (I): = ord (i) + Ckey; erroneous. Translator (who is your delphi?) It eats, but the program will not be able to write code more than 255 in one character anyway. Or less than 0. Get whole variables and practice arithmetic with them already. And at the end - chr (this_variable). - alexlz
  • @lioppo rather not even the second closing, but closing the unopened file a when you start the decoding program. - alexlz
  • @lioppo, Please arrange questions according to the rules of the community, otherwise they will be deleted. - Nicolas Chabanovsky

0