Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.84 KB | None | 0 0
  1. with Ada.Text_IO; use Ada.Text_IO;
  2. with Ada.Containers.Vectors; use Ada.Containers;
  3. package body GF2n is
  4.     function "+"(X: Element_Type; Y: Element_Type) return Element_Type is
  5.     begin
  6.         return X xor Y;
  7.     end "+";
  8.  
  9.     function "-"(X: Element_Type; Y: Element_Type) return Element_Type is
  10.     begin
  11.         return X xor Y;
  12.     end "-";
  13.  
  14.     function "*"(X: Element_Type; Y: Element_Type) return Element_Type is
  15.         Y_In_Bits : Bit_Array;
  16.         Tmp_Element_Type : Element_Type;
  17.         Tmp : Element_Type := 0;
  18.     begin
  19.         Y_In_Bits := Get_Binary(Y);
  20.         for i in Y_In_Bits'Range loop
  21.             if Y_In_Bits(i) = 1 then
  22.                 Tmp_Element_Type := Shift_Left(X, i);
  23.                 Tmp := Tmp xor Tmp_Element_Type;
  24.             end if;
  25.         end loop;
  26.         return Tmp;
  27.     end "*";
  28.  
  29.     function "/"(X: Element_Type; Y: Element_Type) return Element_Type is
  30.     begin
  31.         return Shift_Left(X, 1);
  32.     end "/";
  33.  
  34.     function Find_Inverse(X: Element_Type) return Element_Type is
  35.     begin
  36.         return 1;
  37.     end Find_Inverse;
  38.  
  39.     function GCD(X: Element_Type; Y: Element_Type) return Element_Type is
  40.     begin
  41.         return 1;
  42.     end GCD;
  43.  
  44.     function Is_Primitive(X: Element_Type) return Boolean is
  45.     begin
  46.         return True;
  47.     end Is_Primitive;
  48.  
  49.     function Get_Binary(X: Element_Type) return Bit_Array is
  50.         Bits : Bit_Array := (others => 0);
  51.         Number : Integer := Integer(X);
  52.         Quotient : Integer;
  53.         Bit : Integer;
  54.         Counter : Integer := 0;
  55.     begin
  56.         while Number > 0  loop
  57.             Bit := Number mod 2 ;
  58.             Quotient := Integer(Number / 2);
  59.             Bits(Counter) := Bit;
  60.             Number := Quotient ;
  61.             Counter := Counter + 1;
  62.         end loop;
  63.         return Bits;
  64.     end Get_Binary;
  65. end GF2n;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement