API Reference

Base classes

class TextVault.Encryptor
abstract newkey() Key | tuple[Key, Key]
abstract encrypt(text: str, key: Key) str
abstract decrypt(text: str, key: Key) str
class TextVault.Key(value)
__init__(value)
__repr__()

return f"Key({self.value})"


Knapsack Encryption Module

Usage

class TextVault.KnapsackEncryptor

Encryptor class which implements Merkle-Hellman knapsack cryptosystem.

newkey() tuple[KnapsackKey, KnapsackKey]

Return a new (public key, private key) tuple for knapsack-cryptosystem.

Returns:

new (public key, private key) tuple

Return type:

tuple[KnapsackKey, KnapsackKey]

encrypt(text: str, key: KnapsackKey) str

Encrypt text with public key and return result.

Parameters:
Returns:

encrypted text.

Return type:

str

decrypt(text: str, key: KnapsackKey) str

Decrypt text with private key and return result.

Parameters:
Returns:

decrypted text.

Return type:

str

class TextVault.KnapsackKey(value: str)

Key class for TextVault.KnapsackEncryptor.

export_txt(file_name: str)

Export key to text file.

classmethod import_txt(file_name: str) Self

Import key from text file.

Example

# After installing TextVault

from TextVault import KnapsackEncryptor, KnapsackKey
txt = "Hello, World! 😀"
enc = KnapsackEncryptor()

pub, priv = enc.newkey()
encrypted = enc.encrypt(txt, pub)
decrypted = enc.decrypt(encrypted, priv)

print("Public key:", pub)
print("Private key:", priv)
print()

print("Original:", txt)
print("Encrypted:", encrypted)
print("Decrypted:", decrypted)
print()

pub.export_txt("knap_public_key.txt")
pub_2 = KnapsackKey.import_txt("knap_public_key.txt")

print("Original Key:", pub)
print("After Save & Load:", pub_2)

RSA Encryption Module

class TextVault.RsaEncryptor

Encryptor class which implements RSA algorithm.

generate_prime()
is_prime(n)

Function to check if a number is prime.

modular_inverse(e, phi)

Function to find modular inverse–> formula: (e x d) mod phi(n) = 1

base36_encode(num)
base36_decode(encoded_str)
newkey() tuple[tuple[int, int], tuple[int, int]]

RSA key generation

encrypt(plaintext: str, public_key: tuple[int, int]) str

Encrypt plaintext with public key and return result.

Parameters:
Returns:

encrypted text.

Return type:

str

decrypt(ciphertext: str, private_key: tuple[int, int]) str

Decrypt ciphertext with private key and return result.

Parameters:
Returns:

decrypted text.

Return type:

str

save_keys(public_key, private_key)

Function to save keys to text files

load_key(file_path)

Function to load keys from text files


Vigenère Encryption Module

class TextVault.VigenereEncryptor

A class that implements Vigenère cipher encryption and decryption using a symmetric key.

newkey() tuple[str, ...]

Generates a new random symmetric key for the Vigenère cipher.

encrypt(text: str, key: tuple[str, ...]) str

Encrypts a given text using the provided Vigenère key.

decrypt(text: str, key: tuple[str, ...]) str

Decrypts an encrypted text back to its original form using the provided key.


JMatrix Encryption Module

class TextVault.JMatrixEncryptor(matrix_size=3)
newkey() tuple[JMatrixKey, JMatrixKey]

Generates a pair of public and private keys

encrypt(text: str, key: JMatrixKey) str

Encrypts a plaintext string using the public key

decrypt(text: str, key: JMatrixKey) str

Decrypts an encrypted string using the private key

class TextVault.JMatrixKey(value, is_private=False)

HillCipherWithNumbers Module

class TextVault.Hillcipherwithnumbers(key_matrix=None, size=2)
newkey(size: int)
encrypt(plaintext: str) list[int]
decrypt(encrypted_nums: list[int]) str
generate_random_password() str

Generates a random password of length between 8 and 16 characters consisting of alphabets and numbers.