Skip to main content

openMTPK Python API

Project description

Version Codacy Badge license Codacy Badge clones PyPi

Overview

openMTPK is an open-source (intended) mathematics package written in C++ with a primary focus on Numbery Theory and Cryptographic algorithms, Linear Algebra, and Machine/Deep learning concepts as well as a range of language API's for integration with pre-existing projects. openMTPK is originally inspired from undergraduate coursework and work done on vpaSTRM. The project welcomes contributors and is in need of mathematics focused/interested programmers comfortable in C and C++. If interested see here!

The goal is to make a reusable mathematics library allowing users to call within their own projects. A few of the implementations seen in the package were first prototypes in Wolfram Mathetmatica, then translated to C then C++ for the package. Look in the samples folder for examples on how to use some of openMTPK's functionalities.

APIs

As development progresses language bindings will be polished. More languages will be explored in the future. The primary goal of creating bindings for other languages is to provide some level of abstraction from the source C++ code. However, it also serves to integrate this package into pre-existing projects in perhaps different target languages. The focus on APIs early on was to start the process while the codebase was of manageable size allowing for modularity with new developments and injecting into the language binding simultaneously.

Language Status Darwin Linux RPi
C++20(core) cppbuild osx linux rpi
Python v3.x Py osx linux rpi
R v4.2.2 R N/A N/A N/A
Julia v1.8.3 Julia N/A N/A N/A
Go v1.19.4 Go N/A N/A N/A
OCaml v4.13.1 OCaml N/A N/A N/A
Fortran 2018 Fortran N/A N/A N/A

Modules

During early stages, modules will be developed in breadth while focusing on depth in later stages of the PRE-V1.0.0 phase. The modules below are all in progress.

  1. Arithmetic
  2. Calculus
    • Differential
  3. Linear Algebra
    • Vector Operations
    • Matrix Operations
  4. Machine/Deep Learning
    • Regression
    • Cross-Validation
    • K-Nearest Neighbors
    • Neural Networks
    • Classifiers
  5. Number Theory
    • Primes
    • Cryptography
  6. Topology/Complex
    • Dynamical Systems
    • Topology
    • Spline

For more details view the project documentation.

Installation

Requirements are loose and mostly tied to what openMTPK was tested and used on. The current installation does not allow for the building of the packages language bindings, limiting use to the core c++ lib. See below on how to build the bindings from source if interested.

Requirements

  • Linux/OSX
  • CMake
  • C++20
  • g++12
# clone repo
$ git clone git@github.com:akielaries/openMTPK.git
$ cd openMTPK
# create build dir
$ mkdir build && cd build
# create necessary objects and static library
$ cmake -S ..
$ make
# install necessary headers and library in correct directories
$ sudo make install

Note Keep the build directory for easy uninstallation. This process asumes your STDLIB path is /usr/local/lib, where most 3rd-party libs are located if not, run the following:

$ LD_LIBRARY_PATH=/usr/local/lib

To test the installation build some of the example drivers in the projects samples directory.

# compile yourself
$ cd samples
$ g++ cipher.cpp -lopenMTPK -o cipher
$ g++ arith.cpp -lopenMTPK -o arith
# script to test all modules and their drivers
# using the projects root makefile
$ make arith
$ make num-theory
...

Uninstall

To uninstall files related to openMTPK, simply run the following:

# enter the build dir from installation
$ cd build
$ sudo make uninstall

Python

For the Python API of openMTPK simply install with pip.

$ pip install openmtpk

Run an example in the samples/python to verify installation.

$ python3 arithmetic.py

Bindings (BETA)

Note These instructions are specific for the OCaml, R, and Fortran.

The binding process leverages the use of Swig, specifically the fork authored by sethrj that makes use of the Fortran binding process. See here. Each API comes with a custom Makefile for compiling a wrapper for the respective language, but does not take care of storing files in necessary filepaths needed by the compiler/interpreter.

Install Swig

# clone the fork of Swig
$ git clone git@github.com:swig-fortran/swig.git
$ cd swig/
# run autotools
$ ./autogen.sh
# install
$ make
$ make check
$ make install

Install Bindings

Bindings are currently being tested for OCaml, R, and Fortran. Simply enter any of the languages lib directories and run the following

$ cd <API_NAME>/lib
$ make run-swig

If you wish to use the generated bindings globally, move the necessary files to the path needed by the compiler/interpreter.

Examples

View the simple examples on how to use some of the modules in different languages here.

# clone the repo and enter
$ git clone git@github.com:akielaries/openMTPK.git 
$ cd openMTPK

# to run all examples 
$ ./all.sh

# to remove the generated binaries
$ make clean-mods

# run unit tests and other checking methods
$ make run-tests

# clean up generated test files
$ make clean-tests

Example C++ driver file for running Caesar Cipher & Mono-Alphabetic Substitution Keyword cipher:

#include <iostream>
#include <string>
#include <openMTPK/number_theory.hpp>

int main() {
    // declare CIPHER class obj
    mtpk::Cipher cc;

    /* CAESAR CIPHER */
    std::string text0 = "Plaintext";
    int shift_key_0 = 5;
    std::string hashtext_0 = cc.caesar(text0, shift_key_0);
    std::cout << "Hashtext0 = " << hashtext_0 << std::endl;

    /* TESTING MONOALPHABETIC SUBSTITUION KEYWORD CIPHER */
    std::string shift_key_2 = "Computer";
    std::string text2 = "Password";
    // encode the plaintext
    std::string encoded_text = cc.keyword_encode(shift_key_2);
    // call the cipher function
    std::string hashtext_2 = cc.keyword(text2 , encoded_text);

    std::cout << "Hashtext2 = " << hashtext_2 << std::endl;

    return 0;
}

A Python example showing the same functionalities.

#!/usr/bin/python3
from openmtpk import Cipher

c = Cipher()
ciphertext_0 = c.caesar('Plaintext', 5)
print(ciphertext_0)

ciphertext_1 = c.caesar('ATTACKATONCE', 4)
print(ciphertext_1)

text = "Password"
shift = "Computer"
encoded_text = c.keyword_encode(shift);
hashtext = c.keyword(text, encoded_text);
print(hashtext)

Download files

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

Source Distribution

openmtpk-0.6.12.tar.gz (49.5 kB view hashes)

Uploaded Source

Built Distributions

openmtpk-0.6.12-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (227.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp37-cp37m-macosx_10_9_x86_64.whl (205.1 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

openmtpk-0.6.12-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

openmtpk-0.6.12-cp36-cp36m-macosx_10_9_x86_64.whl (197.1 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

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