intrinsic MessageToCode(s :: MonStgElt, l :: RngIntElt, B :: RngIntElt) -> SeqEnum
{}
   if (#s mod l) ne 0 then
       t :="";
       for i:= (#s mod l) to l-1 do 
           t := t cat "*"; 
       end for;
       s := s cat t;
   end if;

   c := [];
   for i:=0 to Integers()!(#s/l - 1) do
       x := 0;
       for j:=1 to l do
           x := x + StringToCode(s[i*l+j]) * B^(l-j);
       end for;
       Append(~c, x);
   end for;
   return c;
end intrinsic;


intrinsic CodeToMessage(c :: SeqEnum, l :: RngIntElt, B :: RngIntElt) -> MonStgElt
{}
    s := "";
    for w in c do
        t := "";
	y := w;
	for i:=0 to l-1 do
	    x := y mod B;
            if x eq 0 then 
                 print "Kein Codewort !";
                 return "ERROR";
            end if;
	    t := t cat CodeToString(x);
	    y := Integers() ! ( (y-x)/B );
	end for;
	s := s cat Reverse(t);
    end for;
    return s;
end intrinsic;


intrinsic RSA(c :: SeqEnum, e :: RngIntElt, N :: RngIntElt) -> SeqEnum
{}
    R, f := quo< Integers() | N >;
    return [Integers() ! (f(w)^e) : w in c];
end intrinsic;

intrinsic Knacken(c :: SeqEnum, e :: RngIntElt, N :: RngIntElt) -> SeqEnum
{}
    fac := Factorization(N);
    p := fac[1,1];
    q := fac[2,1];
    M := (p-1)*(q-1);
    g,a,d := XGCD(M, e);
    R, f := quo< Integers() | N >;
    return [Integers() ! (f(w)^d) : w in c];
end intrinsic;

