Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function expmod( b : std_logic_vector; e : std_logic_vector; m : std_logic_vector ) return std_logic_vector is
- variable result: unsigned( b'REVERSE_RANGE );
- variable exponent: unsigned( b'REVERSE_RANGE );
- variable basee: unsigned( b'REVERSE_RANGE );
- variable zero: unsigned( b'REVERSE_RANGE );
- begin
- zero := ( others => '0' );
- result := (0=> '1', others => '0');
- exponent := unsigned(e);
- basee := unsigned(b);
- for i in exponent'RANGE loop
- if ( exponent /= zero ) then
- if ( exponent(0) = '1' ) then
- result := result * basee mod unsigned(m);
- end if;
- exponent := unsigned(shr(std_logic_vector(exponent), "01"));
- basee := basee * basee mod unsigned(m);
- end if;
- end loop;
- return std_logic_vector(result);
- end expmod;
Add Comment
Please, Sign In to add comment