Encodes everything correctly, but does not take into account gaps. For example, words: abv abv Key: 7654321 Result: vbavba and should be: wba.

function encode(st,k:string):string; var i,j:byte; buf:string; res:string; begin res:=''; while Length(k)<=Length(st) do begin buf:=Copy(st,1,Length(k)); delete(st,1,Length(k)); for I := 1 to length(k) do res:=res+buf[strtoint(k[i])]; end; if trim(st)<>'' then begin while length(st)<Length(k) do st:=st+' '; for I := 1 to length(k) do res:=res+buf[strtoint(k[i])]; end; while pos(' ',res)<>0 do delete(res,pos(' ',res),1); result:=res; end; procedure TForm2.Button1Click(Sender: TObject); var key:string; s :string; begin s:=memo1.text; key:=edit2.text; memo2.text:=encode(s,key); end; 

    1 answer 1

    Doesn't this line at the end of the encode function bother you?

     while pos(' ',res)<>0 do delete(res,pos(' ',res),1); 

    And you should pay a little more to formatting the code. Code in such a way as your function encode to put it mildly "unreadable".

    • does it need to be removed? - LLIAKAJI
    • many thanks helped) - LLIAKAJI