alphabet1:="abcdefghiklmnopqrstuvwxyz"; cryptalphabet:="adfgx"; makesquareadfgx:=function(permlist) local a,b,i,pos; pos:=[]; for i in [1..Length(alphabet1)] do a:= ((i-1) mod 5) +1; b:= (i-a)/5; pos[permlist[i]]:=[cryptalphabet[b+1],cryptalphabet[a]]; od; return pos; end; adfgx:=function(text,square,key) local l,cryptocols,i,textnew,perm,numkey; textnew:=Flat(List(text,x->square[Position(alphabet1,x)])); l:=Length(key); cryptocols:=[]; for i in [1..l] do cryptocols[i]:=[]; od; for i in [1..Length(textnew)] do Add(cryptocols[((i-1) mod l) +1],textnew[i]); od; numkey:=List(key,x->Position(alphabet1,x)); perm:=Sortex(numkey); return Flat(Permuted(cryptocols,perm)); end;