An encryption algorithm based on a random tree of nodes. A standard symmetric encryption algorithm which converts a string into a set of directions.
.
”.|
” is used to represent whitespace. |
”.Command Name | Terminal |
---|---|
Help | python -m treecrypt -h |
Version | python -m treecrypt -v |
Key Generation | python -m treecrypt keygen {args} |
Encryption | python -m treecrypt encrypt {args} |
Decryption | python -m treecrypt decrypt {args} |
Argument Name | Terminal | Type | Value | Required |
---|---|---|---|---|
Key | -k | String | File Path to output the encryption key | True |
Dictionary | -d | String | File Path to output the encryption dictionary | True |
Depth | --depth | Integer | Key Generator depth | True |
Min | --min | Integer | Minimum distance between connected nodes | False |
Max | --max | Integer | Maximum distance between connected nodes | False |
Charset | -c | String | File path to a python list of the charset | False |
Live Print | -l | Flag | no_Value, Prints the number of nodes generated live | False |
Argument Name | Terminal | Type | Value | Required |
---|---|---|---|---|
Key | -k | String | File Path to the encryption key | True |
Dictionary | -d | String | File Path to the encryption dictionary | True |
Input | -i | String | Input plain text to encrypt/decrypt | -i or -f |
File | -f | String | File path to plain text file to encrypt/decrypt | -i or -f |
Output | -o | String | File path to store results | False |
Install it by simply running
pip install treecrypt
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
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.
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.
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()))
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)
The Archives of M. Umar Shahbaz
© 2025 MUS. All rights reserved.