Skip to main content

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

Metadata

Release files for lwe-python 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lwe-python 0.1.4
File Size Uploaded
lwe_python-0.1.4.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lwe-python 0.1.4
File Interpreter ABI Platform
lwe_python-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / lwe_python-0.1.4.tar.gz

Download URL lwe_python-0.1.4.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c0a5ab191141dd3406fed57e1b5d13af170972574f59797b8b6c5095a3c4fecd
BLAKE2b-256 checksum
How to use checksums
37107c72373478f8f52f8d6e35d9780fc8757e7a239806e8a432e7739c0e7b0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.12

Release files / lwe_python-0.1.4-py3-none-any.whl

Download URL lwe_python-0.1.4-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
023b60e51d8045620480ce11c824a3be509bb55f00340372a3e2490c46f33256
BLAKE2b-256 checksum
How to use checksums
9a1077284741715c0b3d738d3d72da4fffc428e426f4a74784eeb4b3840dba51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.12

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page