--------------------------------------------------------------------------- -- Mod f(x) division. Modified Euclidean Algorithm --------------------------------------------------------------------------- with Gnat.Io; use Gnat.Io; with Galois; use Galois; procedure algorithm7 is F, G, H, A, B, C, D, Shifted_B, B_By_Q, Shifted_D, D_By_Q, R, Next_D, Z, Y: Polynomial; Q_Dif: Natural_Mod_P; S, T, Dif: Natural; begin for I in 0 .. M loop G(I) := 0; H(I) := 0; F(I) := 0; end loop; --F(0) := 237; F(17) := 1; --f(0) := 1; f(17) := 1; --G(0) := 1; --h(3) := 120; --F(0) := 237; F(7) := 29; F(14) := 42; F(17) := 1; --H(0) := 1; H(1) := 237; H(5) := 15; H(6) := 150; H(11) := 49; H(14) := 200; H(16) := 129; F(5) := 1; F(4) := 2; F(3) := 2; F(2) := 4; F(1) := 6; F(0) := 2; G(0) := 0; G(1) := 1; G(2) := 2; G(3) := 3; G(4) := 4; for I4 in 0 .. 6 loop for I3 in 0 .. 6 loop for I2 in 0 .. 6 loop for I1 in 0 .. 6 loop for I0 in 0 .. 6 loop H(4) := I4; H(3) := I3; H(2) := I2; H(1) := I1; H(0) := I0; if H = (0,0,0,0,0,0) then exit; end if; ---------------------------------------------------------------------------- A := F; B := H; for I in 0 .. M loop C(I) := 0; end loop; D := G; S := Degree(A); T := Degree(B); while T > 0 loop Dif := S-T; Q_Dif := (A(S)*Invert(B(T))) mod P; Shifted_B := Shift(B, Dif); B_By_Q := Product(Shifted_B, Q_Dif); R := Subtract(A, B_By_Q); Shifted_D := Shift(D, F, Dif); D_By_Q := Product(Shifted_D, Q_Dif); Next_D := Subtract(C, D_By_Q); A := B; B := R; C := D; D := Next_D; S := T; T := Degree(B); if S < T then Swap(A, B); Swap(C, D); Swap(S, T); end if; end loop; Z := Product(D, Invert(B(0))); ----------------------------------------------------------------------------- Y := Product_Mod_F(Z, H, F); Put("z = "); for I in 0 .. M loop Put(Z(I)); Put(" "); end loop; New_Line; Put("z.h = "); for I in 0 .. M loop Put(Y(I)); Put(" "); end loop; New_Line; if Y /=(0,1,2,3,4,0) then Put("ERROR"); end if; New_Line; end loop; end loop; end loop; end loop; end loop; end algorithm7;