/* -------------------------------------------------------------
Encryption Process of the SimpleMatrix Encryption Scheme
loads public key from public_key.txt and encrypts a random message with message[1] = 1
ciphertext is stored in ciphertext.txt
---------------------------------------------------------------*/
clear;

printf "*************************************************** \n";
printf "*** SimpleMatrix Encryption Scheme - Encryption *** \n";
printf "*************************************************** \n \n";

timet:= Cputime();
load "public_key.txt"; // read in the public key

Vn:=VectorSpace(GF,n);
Vm:=VectorSpace(GF,m);

message:=Random(Vn);

message:=message/message[1];

ciphertext:=[];

for i:=1 to m do
	for j:=1 to n do
		Pk[i]:=Evaluate(Pk[i],x[j],message[j]);
	end for;
	ciphertext[i]:=MonomialCoefficient(Pk[i],1);
end for;

ciphertext:=Vm!ciphertext;
printf "time for encryption: %o\n\n",Cputime(timet);
printf "message: %o \n \n", message;
printf "ciphertext: %o  \n \n", ciphertext;

printf"Write ciphertext.txt \n \n";
SetOutputFile("ciphertext.txt":Overwrite:=true);
printf "Vm:=VectorSpace(GF,m); \n \n";
printf "ciphertext:= Vm!(%o) ; \n \n", Eltseq(ciphertext);
UnsetOutputFile();
