PASCAL 一个简单的编码、解码程序

来源:百度知道 编辑:UC知道 时间:2024/05/21 14:00:39
编码过程如下
例:原码 ON A CLEAR DAY,YOU AN SEE FOREVER.
先输入一个正整数你(1<=n<=6),它与某个英文大写字母相对应,比如n=9对应字母I。这个字母诀订了对原句中英文字母的转换,如原码是ABCDEFGHIJKLMNOPQRSTUVWXYZ,转换码是IJKLMNOPQRSTUVWXYZABCDEFGH,而其他字符则不变。因此原句转换诚WV I K TMIZ LIG,GWC AMM KIV NMZMDMZ,为了使得较难于破译,特将上述转换后的信息再自左至右两两字符交换,若最后仅剩下单个字符则不换,即得VWI K MTZIL GIG,CWA MMK VINZWDMZM。然后,将一开始表示转换关系的字母置于前面,便产生了最后的编码:IVWI K MTZIL GIG,GWK MMK VIN ZWDMZM 解码过程则是上述编码过程之逆。经解码后应获得原句。
我自己的程序 看1楼的 但是 有点错误 给我一个新的程序或修改我的程序

program y5_12;
var one:string;
i,what,n,temp,s:integer;temp1:char;
begin
writeln('input your choice:');
writeln('1.bian ma');
writeln('2.jie ma');
readln(what);
writeln('input a string:');
readln(one);
if what=1 then begin
readln(n);
n:=n-1;
for i:=1 to length(one) do begin
if ord(one[i]) in [65..90] then begin
temp:=ord(one[i])+n;
if temp>90 then temp:=temp-90+64;
one[i]:=chr(temp);
end;

end;
s:=ord(one[0]);
if odd(s) then dec(s);
i:=1;
repeat
temp1:=one[i];
one[i]:=one[i+1];
one[i+1]:=temp1;
i:=i+2;
until i>=s;
write(chr(ord(n+1+64)));
write(one);
end;
if what=2 then begin
n:=ord(upcase