Skip to main content

openMTPK Python API

Project description

img

Version Codacy Badge license Codacy Badge clones

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. Some of the implementations seen in the package were first prototypes in Wolfram Mathetmatica, then translated to C++ for the package. Look in the samples folder for examples on using these tools in your own project.

API Bindings

As development progresses language bindings will be polished. More languages such as Julia and MATLAB will be explored in the future.

Language Status
C++17/g++12(core) cppbuild
Python v3.x Py
OCaml v4.13.1 OCaml
Fortran 2018 Fortran
R v4.2.2 R
Julia v1.8.3 Julia

Modules

  1. Arithmetic
  2. Calculus
    • Differential
    • Integral
  3. Linear Algebra
    • Vector Operations
    • Matrix Operations
  4. Machine/Deep Learning
    • Regression
    • Cross-Validation
    • K-Nearest Neighbors
    • Neural Networks
      • Naive
      • Multi-layer Perceptron
      • Bayes
      • Kohonen (Self-Organizing Map)
    • Bayes Classifier
  5. Number Theory
    • Primes
    • Cryptography
  6. Topology/Complex
    • Dynamical Systems
    • Topology
    • Spline

For more details view the project documentation.

Examples

All examples are in the samples folder

# 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.C_cipher(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.KC_encode(shift_key_2);
    // call the cipher function
    std::string hashtext_2 = cc.KC_cipher(text2 , encoded_text);
    
    std::cout << "Hashtext2 = " << hashtext_2 << std::endl;

    return 0;
}

A Python example showing the same functionalities.

#!/usr/bin/python3.10
from openMTPK import Cipher

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

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

text = "Password"
shift = "Computer"
encoded_text = c.KC_encode(shift);
hashtext = c.KC_cipher(text, encoded_text);
print(hashtext)

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
  • Swig (for bindings)
  • g++
# clone repo
$ git clone git@github.com:akielaries/openMTPK.git
$ cd oepnMTPK
# 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 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
...

Build Bindings

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

# install Python binding for openMTPK
$ pip install openmtpk

Bindings are currently supported for Python, 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.

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

openmtpk-0.0.10.tar.gz (209.5 kB view hashes)

Uploaded Source

Built Distribution

openmtpk-0.0.10-py3-none-any.whl (204.2 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