#################### Einige vorgegebene Dinge ########################### A1 := [ '1','2','3','4','5','6','7','8','9', '0','A', 'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',')' , '(' , ',' , '.', '=','!','?','a','b','c','d','e','f','g','h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ']; A2 := [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; A3 := ['0','1']; Z := Integers(); NumbersToText := function(L,alphabet) return(Apply(L, i-> alphabet[i+1])); end; TextToNumbers := function(text,alphabet) return(Apply(List(text), i-> (Position(alphabet,i)-1))); end; TextAnalysis := function(text,alphabet) return(Apply(alphabet, i-> [i,Length(Filtered(List(text), j-> j=i))])); end; AffinLinear := function(block, key,alphabet) # key = [A,b] local m,n,A,b,M,C; m := Length(alphabet); n := Length(block); A := key[1]; b := key[2]; if not( Type(A) = elt-alg^mat/ord^rat) or not( Type(b) = elt-mdl^mat/ord^rat) then Print(" Error in AffinLinear(Block, key, alphabet: key[1], key[2] have to be matrices or vectors...\n"); fi; M := Transpose(Matrix(Z,1,n,TextToNumbers(block,alphabet))); C := Apply(List(A*M + b), i-> i mod Length(alphabet)); return(NumbersToText( List(C), alphabet)); end; ########### So koennten zum Beispiel die Verschluesselung und Entschluesselung aussehen: E := function(key, M,alphabet) # key=Schluessel, n=Blocklaenge, M=Klartext local l,n; n := Length(List(key[2])); l := ListSplit(M,n); l := Apply(l, i-> Append(i, Apply([Length(i)+1..n], j-> alphabet[1]))); l := Apply(l, i-> AffinLinear(i, key, alphabet)); return(Concatenation(l)); end; D := function(key, C,alphabet) # key=Schluessel, n=Blocklaenge, C=Chiffretext local l,a,n; n := Length(List(key[2])); l := ListSplit(C,n); a := Apply(l, i-> Apply(List(key[1]^(-1)*(Transpose(Matrix(Z, 1,n,TextToNumbers(i,alphabet)))-key[2])), j-> j mod Length(alphabet))); return( Concatenation(Apply(a, i-> NumbersToText(i, alphabet)))); end; A := Matrix( Z, 2,2, [ 1,0,0, 1]); b := Transpose(Matrix( Z, 2, [1,2])); key := [A,b]; text := "DIESE NACHRICHT IST GEHEIM"; C := E(key, text, A1); M := D(key, C , A1);