F4
Library for Gröebner basis computations over finite fields.
 All Classes Namespaces Files Functions Variables Friends Pages
check-cyclic6-gf2-extension-16bits.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Antoine Joux, Vanessa Vitse and Titouan Coladon
3  *
4  * This file is part of F4.
5  *
6  * F4 is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * F4 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with F4. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
28 #include <iostream>
29 #include <string>
30 #include <vector>
31 #include <libf4.h>
32 
33 using namespace std;
34 
35 int main (int argc, char **argv)
36 {
37  cout << "#########################################################" << endl;
38  cout << "# CHECK CYCLIC6 16 BITS ON GF(2^n) #" << endl;
39  cout << "#########################################################" << endl << endl;
40 
41  // Create polynomial array
42  vector<string> polynomialArray;
43 
44  // Create variable name array
45  vector<string> variableName;
46  for(int i = 0; i < 6; i++)
47  {
48  variableName.push_back('x'+to_string(i));
49  }
50 
51  // Fill the polynomial array
52  polynomialArray.emplace_back("(t+t^3)*x0+(t+t^3)*x1+(t+t^3)*x2+(t+t^3)*x3+(t+t^3)*x4+(t+t^3)*x5");
53  polynomialArray.emplace_back("(t+t^3)*x0*x1+(t+t^3)*x1*x2+(t+t^3)*x2*x3+(t+t^3)*x3*x4+(t+t^3)*x0*x5+(t+t^3)*x4*x5");
54  polynomialArray.emplace_back("(t+t^3)*x0*x1*x2+(t+t^3)*x1*x2*x3+(t+t^3)*x2*x3*x4+(t+t^3)*x0*x1*x5+(t+t^3)*x0*x4*x5+(t+t^3)*x3*x4*x5");
55  polynomialArray.emplace_back("(t+t^3)*x0*x1*x2*x3+(t+t^3)*x1*x2*x3*x4+(t+t^3)*x0*x1*x2*x5+(t+t^3)*x0*x1*x4*x5+(t+t^3)*x0*x3*x4*x5+(t+t^3)*x2*x3*x4*x5");
56  polynomialArray.emplace_back("(t+t^3)*x0*x1*x2*x3*x4+(t+t^3)*x0*x1*x2*x3*x5+(t+t^3)*x0*x1*x2*x4*x5+(t+t^3)*x0*x1*x3*x4*x5+(t+t^3)*x0*x2*x3*x4*x5+(t+t^3)*x1*x2*x3*x4*x5");
57  polynomialArray.emplace_back("(t+t^3)*x0*x1*x2*x3*x4*x5-1");
58 
59  // Compute a reduce groebner basis
60  vector<string> basisShort = groebnerBasisGF2ExtensionF4("t^15 + t^13 + t^8 + t^5 + t^2 + t + 1", 6, variableName, "t", polynomialArray, 1, 0);
61 
62  // Fill reference vectors
63  vector<string> groebnerBasisCyclic6Short;
64 
65  //for(size_t i = 0; i < basisShort.size(); i++)
66  //{
67  //cout << "groebnerBasisCyclic6Short.push_back(\"" << basisShort[i] << "\");" << endl;
68  //}
69 
70  groebnerBasisCyclic6Short.push_back("((+1)*x0^1) + ((+1)*x1^1) + ((+1)*x2^1) + ((+1)*x3^1) + ((+1)*x4^1) + ((+1)*x5^1)");
71  groebnerBasisCyclic6Short.push_back("((+1)*x1^2) + ((+1)*x1^1*x3^1) + ((+1)*x2^1*x3^1) + ((+1)*x1^1*x4^1) + ((+1)*x3^1*x4^1) + ((+1)*x2^1*x5^1) + ((+1)*x3^1*x5^1) + ((+1)*x5^2)");
72  groebnerBasisCyclic6Short.push_back("((+1)*x2^1*x3^3*x5^4) + ((+1)*x2^1*x3^2*x5^5) + ((+1)*x3^3*x5^5) + ((+1)*x3^2*x5^6) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x5^2)");
73  groebnerBasisCyclic6Short.push_back("((+1)*x1^1*x2^1) + ((+1)*x2^2) + ((+1)*x1^1*x3^1) + ((+1)*x2^1*x3^1) + ((+1)*x1^1*x4^1) + ((+1)*x2^1*x4^1) + ((+1)*x3^1*x4^1) + ((+1)*x4^2) + ((+1)*x1^1*x5^1) + ((+1)*x2^1*x5^1) + ((+1)*x3^1*x5^1) + ((+1)*x4^1*x5^1)");
74  groebnerBasisCyclic6Short.push_back("((+1)*x2^3) + ((+1)*x2^2*x5^1) + ((+1)*x2^1*x5^2) + ((+1)*x5^3)");
75  groebnerBasisCyclic6Short.push_back("((+1)*x2^2*x3^1) + ((+1)*x2^1*x3^1*x4^1) + ((+1)*x2^2*x5^1) + ((+1)*x2^1*x3^1*x5^1) + ((+1)*x2^1*x4^1*x5^1) + ((+1)*x3^1*x4^1*x5^1) + ((+1)*x2^1*x5^2) + ((+1)*x4^1*x5^2)");
76  groebnerBasisCyclic6Short.push_back("((+1)*x1^1*x3^3) + ((+1)*x2^1*x3^3) + ((+1)*x3^3*x4^1) + ((+1)*x1^1*x4^3) + ((+1)*x4^4) + ((+1)*x1^1*x3^2*x5^1) + ((+1)*x2^1*x3^2*x5^1) + ((+1)*x3^3*x5^1) + ((+1)*x3^2*x4^1*x5^1) + ((+1)*x1^1*x4^2*x5^1) + ((+1)*x4^3*x5^1) + ((+1)*x1^1*x3^1*x5^2) + ((+1)*x2^1*x3^1*x5^2) + ((+1)*x3^2*x5^2) + ((+1)*x1^1*x4^1*x5^2) + ((+1)*x3^1*x4^1*x5^2) + ((+1)*x4^2*x5^2) + ((+1)*x2^1*x5^3) + ((+1)*x3^1*x5^3) + ((+1)*x5^4)");
77  groebnerBasisCyclic6Short.push_back("((+1)*x1^1*x3^2*x5^4) + ((+1)*x2^2*x4^1*x5^4) + ((+1)*x2^1*x3^1*x4^1*x5^4) + ((+1)*x3^2*x4^1*x5^4) + ((+1)*x1^1*x4^2*x5^4) + ((+1)*x2^1*x4^2*x5^4) + ((+1)*x4^3*x5^4) + ((+1)*x2^2*x5^5) + ((+1)*x2^1*x3^1*x5^5) + ((+1)*x2^1*x4^1*x5^5) + ((+1)*x3^1*x4^1*x5^5) + ((+1)*x4^2*x5^5) + ((+1)*x2^1*x5^6) + ((+1)*x3^1*x5^6) + ((t^12+t^5+t^3+t^2+t+1)*x2^1) + ((t^12+t^5+t^3+t^2+t+1)*x5^1)");
78  groebnerBasisCyclic6Short.push_back("((+1)*x2^1*x4^3*x5^4) + ((+1)*x2^1*x4^2*x5^5) + ((+1)*x4^3*x5^5) + ((+1)*x4^2*x5^6) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x4^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x5^2)");
79  groebnerBasisCyclic6Short.push_back("((+1)*x2^1*x3^2*x5^6) + ((+1)*x2^1*x4^2*x5^6) + ((+1)*x3^2*x5^7) + ((+1)*x4^2*x5^7) + ((+1)*x2^1*x5^8) + ((+1)*x5^9) + ((t^12+t^5+t^3+t^2+t+1)*x1^1*x3^2) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^2) + ((t^12+t^5+t^3+t^2+t+1)*x2^2*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^1*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^2*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x1^1*x4^2) + ((t^12+t^5+t^3+t^2+t+1)*x4^3) + ((t^12+t^5+t^3+t^2+t+1)*x2^2*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^2*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x4^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x4^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x5^2) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x5^2)");
80  groebnerBasisCyclic6Short.push_back("((+1)*x1^1*x3^1*x4^1) + ((+1)*x1^1*x4^2) + ((+1)*x3^1*x4^2) + ((+1)*x4^3) + ((+1)*x1^1*x3^1*x5^1) + ((+1)*x1^1*x4^1*x5^1) + ((+1)*x3^1*x4^1*x5^1) + ((+1)*x4^2*x5^1)");
81  groebnerBasisCyclic6Short.push_back("((+1)*x2^1*x3^2*x4^1) + ((+1)*x2^1*x3^2*x5^1) + ((+1)*x3^2*x4^1*x5^1) + ((+1)*x3^2*x5^2) + ((+1)*x2^1*x4^1*x5^2) + ((+1)*x2^1*x5^3) + ((+1)*x4^1*x5^3) + ((+1)*x5^4)");
82  groebnerBasisCyclic6Short.push_back("((+1)*x2^2*x4^2) + ((+1)*x2^2*x5^2) + ((+1)*x4^2*x5^2) + ((+1)*x5^4)");
83  groebnerBasisCyclic6Short.push_back("((+1)*x2^1*x3^1*x4^2) + ((+1)*x2^1*x4^2*x5^1) + ((+1)*x3^1*x4^2*x5^1) + ((+1)*x2^1*x3^1*x5^2) + ((+1)*x4^2*x5^2) + ((+1)*x2^1*x5^3) + ((+1)*x3^1*x5^3) + ((+1)*x5^4)");
84  groebnerBasisCyclic6Short.push_back("((+1)*x3^2*x4^2*x5^2) + ((+1)*x1^1*x3^1*x5^4) + ((+1)*x2^1*x3^1*x5^4) + ((+1)*x1^1*x4^1*x5^4) + ((+1)*x3^1*x4^1*x5^4) + ((+1)*x4^2*x5^4) + ((+1)*x2^1*x5^5) + ((+1)*x3^1*x5^5) + ((+1)*x5^6) + ((t^12+t^5+t^3+t^2+t+1)*1)");
85  groebnerBasisCyclic6Short.push_back("((+1)*x1^1*x4^4*x5^2) + ((+1)*x4^5*x5^2) + ((+1)*x2^2*x4^1*x5^4) + ((+1)*x2^1*x3^1*x4^1*x5^4) + ((+1)*x2^1*x4^2*x5^4) + ((+1)*x2^2*x5^5) + ((+1)*x2^1*x3^1*x5^5) + ((+1)*x2^1*x4^1*x5^5) + ((+1)*x3^1*x4^1*x5^5) + ((+1)*x4^2*x5^5) + ((+1)*x2^1*x5^6) + ((+1)*x3^1*x5^6) + ((t^12+t^5+t^3+t^2+t+1)*x1^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1) + ((t^12+t^5+t^3+t^2+t+1)*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x5^1)");
86  groebnerBasisCyclic6Short.push_back("((+1)*x2^2*x5^6) + ((+1)*x5^8) + ((t^12+t^5+t^3+t^2+t+1)*x2^2) + ((t^12+t^5+t^3+t^2+t+1)*x5^2)");
87  groebnerBasisCyclic6Short.push_back("((+1)*x1^1*x3^1*x5^6) + ((+1)*x2^1*x3^1*x5^6) + ((+1)*x1^1*x4^1*x5^6) + ((+1)*x3^1*x4^1*x5^6) + ((+1)*x4^2*x5^6) + ((+1)*x2^1*x5^7) + ((+1)*x3^1*x5^7) + ((+1)*x5^8) + ((t^12+t^5+t^3+t^2+t+1)*x1^1*x3^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^1) + ((t^12+t^5+t^3+t^2+t+1)*x1^1*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x4^2) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x5^2)");
88  groebnerBasisCyclic6Short.push_back("((+1)*x2^1*x3^1*x4^1*x5^6) + ((+1)*x2^1*x3^1*x5^7) + ((+1)*x2^1*x4^1*x5^7) + ((+1)*x3^1*x4^1*x5^7) + ((+1)*x2^1*x5^8) + ((+1)*x3^1*x5^8) + ((+1)*x4^1*x5^8) + ((+1)*x5^9) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^1*x4^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x3^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x4^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x4^1*x5^1) + ((t^12+t^5+t^3+t^2+t+1)*x2^1*x5^2) + ((t^12+t^5+t^3+t^2+t+1)*x3^1*x5^2) + ((t^12+t^5+t^3+t^2+t+1)*x4^1*x5^2) + ((t^12+t^5+t^3+t^2+t+1)*x5^3)");
89 
90  /* 16 bits */
91  bool testCyclic6 = true;
92  size_t i = 0;
93  while(i < basisShort.size() && testCyclic6 == true )
94  {
95  testCyclic6 = testCyclic6 && (groebnerBasisCyclic6Short[i].compare(basisShort[i])==0);
96  i++;
97  }
98  if(testCyclic6==true)
99  {
100  cout << "Test cyclic6 GF(2^15) on 16 bits pass" << endl;
101  return 0;
102  }
103  else
104  {
105  cout << "Test cyclic6 GF(2^15) on 16 bits failed" << endl;
106  return -1;
107  }
108 }
109 
110 
Declaration of library methods.
std::vector< std::string > groebnerBasisGF2ExtensionF4(std::string modulo, int nbVariable, std::vector< std::string > variableName, std::string polyVarName, std::vector< std::string > polynomialList, int nbThread, int verbose)
Compute a reduced groebner basis of the ideal defined by the list of polynomials polynomialList.