
// Input : the filename of the challenge
// Output : the MQ system of the challenge	
ReadSystem := function(filename)

	inputF := Open(filename, "r");

	line := Gets(inputF); 
	if Index(line, "GF(31)") gt 0 then 
		Fq := GF(31);
	elif Index(line, "GF(2)[x]") gt 0 then 
		Fq := ExtensionField<GF(2), x | x^8 + x^4 + x^3 + x^2 + 1>;
	else
		Fq := GF(2);  
	end if;

	line := Gets(inputF);
	arr := Split(line, ":");
	n := StringToInteger(arr[2]); 

	line := Gets(inputF);
        arr := Split(line, ":");
        m := StringToInteger(arr[2]);

	while true do
		line := Gets(inputF);
		if Index(line, "********") gt 0 then 
			break;
		end if; 
	end while; 

	P := PolynomialRing(Fq, n, "grevlex");
	Mono := MonomialsOfDegree(P, 2) join MonomialsOfDegree(P, 1) join {1};
	Mono := Reverse(Sort(Setseq(Mono)));

	MQ := [P!0 : i in [1..m]];
	for i in [1..m] do
		line := Gets(inputF);
		arr := Split(line, " ");
		for j in [1..#Mono] do
			if #Fq eq 256 then
				ele := Intseq(StringToInteger(arr[j], 16),2);
				MQ[i] := MQ[i] + Fq!ele*Mono[j];
			else
				MQ[i] := MQ[i] + StringToInteger(arr[j])*Mono[j];
			end if;
		end for;
	end for;

	delete inputF;
	return MQ;

end function;
