uses
crt,
dos;
var
key:string;
{ decode file ---------------------------------------------------------------}
{your code here}
procedure decode(infname:pathstr);
var
infile,outfile:file;
fdir:dirstr; fname:namestr; fext:extstr;
dbuf,sbuf:pointer;
idx,i,j,srcseg,srcofs,dstseg,dstofs,start,csize:word;
src,rep:byte;
begin
if maxavail<2*65500 then Begin
Writeln(#13#10,''No Memory'');
halt;
End;
getmem(dbuf,65500);
getmem(sbuf,65500);
srcseg:=seg(sbuf^); srcofs:=ofs(sbuf^);
dstseg:=seg(dbuf^); dstofs:=ofs(dbuf^); start:=dstofs;
assign(infile,infname);
{$i-} reset(infile,1); {$i+}
if ioresult<>0 then Begin
Writeln(#13#10''File I/O!'');
halt;
End;
if filesize(infile)>65500 then halt;
blockread(infile,sbuf^,filesize(infile));
csize:=filesize(infile);
close(infile);
randseed:=ord(key[length(key)]); j:=0;
for i:=0 to csize do begin
mem[srcseg:srcofs+i]:=mem[srcseg:srcofs+i] xor
(ord(key[j])+random(ord(key[j])));
j:=1+j mod 8;
end;
idx:=0;
while idx
0 then Begin
Writeln(#13#10''Output Error!'');
halt(4);
End;
blockwrite(outfile,key,length(key)); {so I know which key did it!}
blockwrite(outfile,dbuf^,csize); {un encoded}
close(outfile);
freemem(sbuf,65500);
freemem(dbuf,65500);
end;
{ main ----------------------------------------------------------------------}
Procedure ShowFile(FName:String); {just a test not used in live version!}
Var
T:Text;
S:String;
Begin
Assign(T,FName);
ReSet(T);
While not eof(t) do begin
{$I-} Readln(t,s); {$I+}
Writeln(s);
End;
Close(T);
End;
Var
Cnt1:Integer; {character 1}
Cnt2:Integer; {2}
Cnt3:Integer; {3}
Cnt4:Integer; {4}
Cnt5:Integer; {5}
Cnt6:Integer; {6}
Cnt7:Integer; {7}
Cnt8:Integer; {8}
Ch:Char; &nbs