library STD;
use STD.TEXTIO.all;

entity RSA_ALG is
end entity RSA_ALG;

architecture ALG of RSA_ALG is
  type texttype is array (0 to 9) of integer;
  constant plaintext : texttype :=
  ( 0 =>  69,    -- E
    1 => 110,    -- n
    2 => 106,    -- j
    3 => 111,    -- o
    4 => 121,    -- y
    5 =>  32,    -- SP
    6 =>  72,    -- H
    7 =>  68,    -- D
    8 =>  76,    -- L
    9 =>  33);   -- !
  constant CE : integer := 101;
  constant CD : integer := 61;
  constant CM : integer := 253; 

  signal CPP, CEE, CDD, CMM, CCC, CPP2 : integer;

begin

 SIG_GEN:process begin
   for I in 0 to 9 loop
    CPP <= plaintext(I); 
    CEE <= CE;
    CDD <= CD;
    CMM <= CM;
    wait for 100 ns;
   end loop;
 end process SIG_GEN;

 RSA_ENC: process(CPP, CEE, CMM)
 variable TMP_v : integer;
 begin  
  TMP_v := 1; 
  for L in 1 to CEE loop
   TMP_v := (TMP_v * CPP) mod CMM; 
  end loop;
  CCC <= TMP_v;
 end process RSA_ENC;

 RSA_DEC: process(CCC, CDD, CMM)
 variable TMP2_v : integer;
 begin  
  TMP2_v := 1; 
  for M in 1 to CDD loop
   TMP2_v := (TMP2_v * CCC) mod CMM; 
  end loop;
  CPP2 <= TMP2_v;
 end process RSA_DEC;

end architecture ALG;

configuration CFG_RSA_ALG of RSA_ALG is
  for ALG
  end for;
end CFG_RSA_ALG;
