---------------------------------------------------------------- -- LSB first squaring, second version (LSBfirst_squarer_v2.adb) -- -- -- ---------------------------------------------------------------- with Gnat.Io; use Gnat.Io; with GF2m; use GF2m; with finite_fields_GF2m; use finite_fields_GF2m; procedure LSBfirst_squarer_v2 is A,W,B,Faux, Baux: poly_vector; F: poly_vector; begin -- for i in 0 .. m-1 loop Put("A(");Put(i);Put(") = "); Get(x); A(i) := x; end loop; New_Line; -- for i in 0 .. m-1 loop Put("F(");Put(i);Put(") = "); Get(F(i)); end loop; New_Line; A := (0,1,0,1,0,0,1,0); F := (1,1,0,0,0,0,1,1); -- F(x) = x^8 + x^7 + x^6 + x + 1 for i in 0 .. m-1 loop W(i) := 0; Baux(i) := 0; end loop; for i in 0 .. (m-1)/2 loop W(2*i) := A(i); end loop; if (m rem 2) = 0 then -- even m B := F; else -- odd m B := Product_alpha(F); end if; Faux := Product_alpha(F); for k in 1 .. (m/2)-1 loop for i in 2 .. m-1 loop Baux(i) := m2xor(B(i-2),m2xor(m2and(B(m-1),Faux(i)),m2and(B(m-2),F(i)))); end loop; Baux(1) := m2xor(m2and(B(m-1),Faux(1)),m2and(B(m-2),F(1))); Baux(0) := m2xor(m2and(B(m-1),Faux(0)),m2and(B(m-2),F(0))); W := m2xvv(W,m2abv(A(((m+1)/2)+k-1),B)); B := Baux; end loop; W := m2xvv(W,m2abv(A(m-1),B)); ----------------------------------------------------- -- Put("W = "); -- for i in 0 .. m-1 loop -- if W(i) = 1 then Put(i); Put("-"); end if; -- end loop; Put("W = "); for i in 0 .. m-1 loop Put(W(i)); end loop; New_Line; end LSBfirst_squarer_v2;