Skip to main content

A Python implementation of the Learning With Errors cryptography scheme

Project description

LWE-Python

What is this library's purpose?

This is a Python implementation of the Learning With Errors crypto algorithim. The LWE is a quantum-resistant algorithim based on matrices. Encoded information is in the form of a vector.

To read more about LWE, you can refer to this Medium article or the original paper published in 2005.

Who should use this library?

If you are interested in securing information outside of the usual methods presented, i.e. RSA, PGP, etc.

How to use

from lwe_python import PublicKey, PrivateKey, encrypt_string, decrypt_data
import math
import random
# set up an arry of error values; this MUST match the
# number_of_equations parameter in the PublicKey constructor

error_vectors = []
number_of_equations = 10
mod_number = 97
for x in range(0, number_of_equations):
  error_vectors.append(math.floor(random.random() * 4))

# you must keep this value and the error array secret. If an attacker were to get their
# hands on both, then they could reverse engineer any message. 
secret_value = 200

pub_key = PublicKey(mod_number=mod_number, error_vectors=error_vectors, number_of_equations=number_of_equations)

priv_key = PrivateKey(secret_value, mod_number)

# you must call this function to generate "B" values; there are values that take 
# into account the values from the error array and the secret
pub_key.generate_key_values(secretValue)

# encrypt a string
encrypted_data = encrypt_string("hello world", pub_key)

# decrypt a string
message = decrypt_data(encryted_data, priv_key)

# s_aves a pub.lwe.key file to the current directory 
pub_key.save_to_keyfile()

# saves a sec.lwe.key file to the current direcotry
priv_key.save_to_keyfile()


# create a PublicKey instance from a pub.lwe.key file
PublicKey.load_keyfile("pub.lwe.key")

# create a PrivatecKey instance from a pub.lwe.key file
PrivateKey.load_keyfile("sec.lwe.key")

# load a PublicKey from JSON data 
PublicKey.loadJSON(keydata)

# export PublicKey data as a JSON Object
keydata = pubKey.to_json()

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

lwe_python-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

lwe_python-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file lwe_python-0.1.2.tar.gz.

File metadata

  • Download URL: lwe_python-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for lwe_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 81e32965f202dbc5cc89bc9ec910bda7d43049917b0d40d335fad949a6b0e294
MD5 ce3e78cd1a498feb73e27f0b019e8dd1
BLAKE2b-256 1d9d05551e223462ecee63fb4a42849d0aa8cbdc8a8a62d9bdf85701288c70c7

See more details on using hashes here.

File details

Details for the file lwe_python-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lwe_python-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for lwe_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dcb6b583e9c2a384798d96749b52c8a75537169b82ed2eadfddac928d5038614
MD5 873e5ed38a5e2c227bbeb81d10e2c057
BLAKE2b-256 c85a5c157c699fb222d6585822402bbf87b2a9291e4eacf45f524c8b0bad1fe6

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