/* ==========================================================================
Encryption Process of Perturbed Matsumoto Imai (Plus)
The program loads the public key from the file public_key.txt 
and encrypts a randomly generated message
the ciphertext is stored in ciphertext.txt
===============================================================================*/
load "public_key.txt";

Vn:=VectorSpace(F,n);
Vns:=VectorSpace(F,n+s);

message:=Random(Vn); // random message
printf "message:= %o \n \n ",message;

for loop:=1 to n+s do
	for i:=1 to n do
		Pk[loop]:=Evaluate(Pk[loop],x[i],message[i]);
	end for;
end for;

ciphertext:=Vns!(Pk);
printf "ciphertext:= %o \n \n", ciphertext;

printf"Write ciphertext.txt \n \n";
SetOutputFile("ciphertext.txt":Overwrite:=true);
printf "Vn:=VectorSpace(F,n); \n \n";
printf "Vns:=VectorSpace(F,n+s); \n \n";
printf "message:= Vn!(%o); \n \n", Eltseq(message);
printf "ciphertext:= Vns!(%o); \n \n", Eltseq(ciphertext);
UnsetOutputFile();
