Example code for the Fermats-Little-Theorem modular inverse algorithm
Project description
Fermats Little Theorem
This repository contains an example of the Fermats Little Theorem algorithm for C++ and one for Python3.
C++
To run the example for C++
change into the c++
folder
and run the following bash script in Linux.
mkdir build && \
cd build && \
cmake .. -G "Unix Makefiles" && \
make
The program should be build and
you can see an executable called modinverse
.
You can test it with ./modinverse arg1 arg2
.
For example:
./modinverse 3 5
modular inverse of 3 mod 5 is 2
./modinverse 2 4
There is no modular inverse!
./modinverse 2
Not enough input arguments!
Python3
You can run this example from source or install it with pip and include it in your project.
Source
Requirement
- virtualenv
To run this example from source, run the following bash script in Linux.
python3 -m virtualenv . && \
source ./bin/activate && \
pip3 install -r requirements.txt
This will generate a virual environment and install the requirement.
After that you can run the programm with
python3 Fermat/fermat.py arg1 arg2
For example:
python3 Fermat/fermat.py 2 5
The mod inverse of 2 mod 5 is 3
python3 Fermat/fermat.py 2 4
There is no modular inverse!
python3 Fermat/fermat.py 2
Not enough input arguments!
Pip
To install this example with pip, simply run:
pip3 install Fermat-FasterCoding
Then you can use it as import like this:
import Fermat.fermat as fermat
inverse = fermat.modInverse(3, 5) # This will return 2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Fermat@FasterCoding-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c988af85d6c9c6bfc2bd9574f6e3484296e3244e43ebf5e9ba69e468f9232226 |
|
MD5 | 6110029036db80774d9b290daf08b261 |
|
BLAKE2b-256 | 59c1fb4bf66c47328bf43c1de6c3dda11958cc45faa2d967894adfdb29a1b31d |
Hashes for Fermat_FasterCoding-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce08df88310cbb4877338e60137310646963dcf459e1758caaa5ee7bfc5d9d13 |
|
MD5 | 6100a5c7217fdeb7db85d3b0bae655b8 |
|
BLAKE2b-256 | 0e11700e23c08201fe4ec29bffee007212ba1455ce23dea694679dbfcf564749 |