Skip to main content

A node-tree based encryption algorithm.

Reason this release was yanked:

Accidental upload

Project description

TreeCrypt

  • Creates a random structure of nodes pointing to one another and converts them into an array.
  • Maps each letter into a set of directions to a node which contains the equivalent letter inside it.
  • During decryption, the directions can be used to find a node and extract the letter inside it.

Requirements

  • Runs on Python 3.10+

Detailed Working

  • A tree of nodes is generated based on a set of rules.
  • The process starts with a default root node.
  • Nodes are recursively and randomly attached to existing nodes, beginning from the root.
  • Each node attempts to connect to up to three other nodes, making several attempts to find valid positions.
  • Node and edge placement avoids any intersections with other nodes or edges. If a suitable position can't be found after several tries, the process skips that attempt and continues elsewhere, increasing randomness.
  • The final structure is a non-intersecting tree where each node contains a randomly selected character from a predefined character set.
  • A dictionary is built, mapping each character in the character set to a list of pointers referencing all nodes containing that character.
  • To encode a message:
    • The algorithm uses the dictionary to randomly select a node corresponding to each character.
    • From each selected node, it backtracks to the root to generate a path (a sequence of directions).
    • Each character in the input is replaced by its corresponding path, with paths separated by dots ".".
  • The special character "|" is used to represent whitespace.
    • Regardless of the number of spaces in the input, all contiguous whitespace is encoded as a single "|".

How to use

0. Install

Install it by simply running

pip install treecrypt

1. Import

Inside your python code add the line

from treecrypt import KeyMaker, Crypter

This will import the key generator and the crypt-maker as classes and these can be used to do the encryption

2. Create a key

If you already have the key and dictionary, then skip to step 4

First of all you need a charset.

The charset used must be a list of characters which are exactly one letter and are eligible to be a python dictionary's key

customCharset = ['A' , 'B', 'C', ....]
myKeyMaker = KeyMaker(customCharset)

If you don't give any parameters then the following is used:

DefaultCharset = [
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '|', ':', ';', '"', "'", ',', '.', '?', '/'
]

Then generate the key using

myKeyMaker.GenerateKey(20, 10, 5)

# Note the format of the parameters
def GenerateKey(self, Depth, MaxDistance, MinDistance = 0):

# You can ignore the last parameter since it has a default value

The parameters are the depth of the tree and the maximum & minimum distance between connected nodes.

3. Export the key

Now you can export the key as a .txt file

myKeyMaker.Export("KEY1.txt", "DICT1.txt")

# Note the format of the parameters
def Export(self, keyFile="key.txt", dictFile="dict.txt"):
# You can ignore the parameters as they have defaults

You can also get them directly inside the code using

Key = myKeyMaker.GetKey()
Dictionary = myKeyMaker.Dictionary()

The parameters are the filenames of the exported key and dictionary.

4. Create a crypter and Import the key

Using the Crypter class, create an object that will encrypt and decrypt text using the previously exported key. If you already have a key then you can skip to over here.

Remember that a text can only be decrypted using the same key with which it was encrypted.

myCrypter = Crypter()
myCrypter.Import("KEY1.txt", "DICT1.txt")

# Make sure that you are using the correct file names for import

def Import(self, keyFile="key.txt", dictFile="dict.txt"):
# Import uses same format as Export of KeyMaker
# You can ignore the parameters if the inputs have the default file names

Additionally, if you only have the key and no dictionary then just do:

import ast
with open('KEY1.txt') as f:
  # Use ast literal eval
  myCrypter.SetKey(ast.literal_eval(f.readline()))

5. Start Crypting!!

Now you can encrypt and decrypt as you wish. However make sure the input doesn't contain anything outside of the custom charset used by the KeyMaker

cipher = myCrypter.Encrypt("TreeCrypt is AMAZING")
doubleCheck = myCrypter.Decrypt(cipher)

print(cipher)
print(doubleCheck)

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

treecrypt-1.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

treecrypt-1.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file treecrypt-1.1.1.tar.gz.

File metadata

  • Download URL: treecrypt-1.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for treecrypt-1.1.1.tar.gz
Algorithm Hash digest
SHA256 daf132c523504b8dfe9293a588e6fc5e3516099c5bf31526fa390fbd4f5e7d3f
MD5 6ae628ca3cf60da06a3be7a1c448fc26
BLAKE2b-256 33b96c7874b0cee58943fe45d6623a6bfdf1edbc90114357876a878e4ad8e896

See more details on using hashes here.

Provenance

The following attestation bundles were made for treecrypt-1.1.1.tar.gz:

Publisher: publish.yml on MUmarShahbaz/TreeCrypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file treecrypt-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: treecrypt-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for treecrypt-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9512591c60c10560227ed22b6bdd979d8cadfc5b9e6cebc3ef804e638a5b6867
MD5 1e6e9892652d3e871dc959a29ed1bb57
BLAKE2b-256 af6d78c36cb43daa7c053c6b810267a14cf5e352afbfbde1147d5e196b6d90c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for treecrypt-1.1.1-py3-none-any.whl:

Publisher: publish.yml on MUmarShahbaz/TreeCrypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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