Guest User

Untitled

a guest
Oct 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. function expmod( b : std_logic_vector; e : std_logic_vector; m : std_logic_vector ) return std_logic_vector is
  2. variable result: unsigned( b'REVERSE_RANGE );
  3. variable exponent: unsigned( b'REVERSE_RANGE );
  4. variable basee: unsigned( b'REVERSE_RANGE );
  5. variable zero: unsigned( b'REVERSE_RANGE );
  6. begin
  7. zero := ( others => '0' );
  8. result := (0=> '1', others => '0');
  9. exponent := unsigned(e);
  10. basee := unsigned(b);
  11.  
  12. for i in exponent'RANGE loop
  13. if ( exponent /= zero ) then
  14. if ( exponent(0) = '1' ) then
  15. result := result * basee mod unsigned(m);
  16. end if;
  17.  
  18. exponent := unsigned(shr(std_logic_vector(exponent), "01"));
  19. basee := basee * basee mod unsigned(m);
  20. end if;
  21. end loop;
  22.  
  23. return std_logic_vector(result);
  24.  
  25. end expmod;
Add Comment
Please, Sign In to add comment