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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file Fermat@FasterCoding-1.0.1.tar.gz.

File metadata

  • Download URL: Fermat@FasterCoding-1.0.1.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for Fermat@FasterCoding-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c988af85d6c9c6bfc2bd9574f6e3484296e3244e43ebf5e9ba69e468f9232226
MD5 6110029036db80774d9b290daf08b261
BLAKE2b-256 59c1fb4bf66c47328bf43c1de6c3dda11958cc45faa2d967894adfdb29a1b31d

See more details on using hashes here.

File details

Details for the file Fermat_FasterCoding-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: Fermat_FasterCoding-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for Fermat_FasterCoding-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce08df88310cbb4877338e60137310646963dcf459e1758caaa5ee7bfc5d9d13
MD5 6100a5c7217fdeb7db85d3b0bae655b8
BLAKE2b-256 0e11700e23c08201fe4ec29bffee007212ba1455ce23dea694679dbfcf564749

See more details on using hashes here.

Supported by

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