Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Fermat@FasterCoding-1.0.1.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

Fermat_FasterCoding-1.0.1-py3-none-any.whl (2.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page