Tutorial#
This tutorial will guide you through using ENcrypt for secure message encryption.
Understanding the Basics#
ENcrypt uses a unique approach to encryption based on:
Matrix operations
Periodic decimal expansions
Custom alphabets
High-precision arithmetic
The Mathematics Behind ENcrypt#
Key Generation#
The encryption key is derived from a number ending in 9:
The input value must end with 9 (e.g., 59, 119, 229)
A high-precision division (1/value) creates a decimal expansion
Specific digits from this expansion form the key matrix
Matrix Operations#
The encryption process involves:
Converting text to numbers using the alphabet
Creating a message matrix
Multiplying with the key matrix
Applying periodic offsets
Step-by-Step Guide#
1. Installation#
First, install ENcrypt:
$ pip install encryptlib
2. Basic Setup#
Import and create an encryptor:
from encryptlib import ENcrypt
# Create an encryptor with key 59
encryptor = ENcrypt(59)
3. Encrypting Messages#
Simple message encryption:
# Prepare your message
message = "HELLO WORLD"
# Encrypt it
encrypted = encryptor.encrypt(message)
print(f"Encrypted matrix:\n{encrypted}")
4. Decrypting Messages#
Decrypt the encrypted matrix:
# Decrypt the message
decrypted = encryptor.decrypt(encrypted)
print(f"Decrypted message: {decrypted}")
Advanced Features#
Custom Alphabets#
Use different character sets:
# Define a custom alphabet
custom_alphabet = "abcdefghijklmnopqrstuvwxyz0123456789 "
# Create encryptor with custom alphabet
custom_encryptor = ENcrypt(59, alphabet=custom_alphabet)
Error Handling#
Proper error handling in your applications:
from encryptlib import ENcrypt, EncryptionError
try:
encryptor = ENcrypt(59)
encrypted = encryptor.encrypt("Hello World")
decrypted = encryptor.decrypt(encrypted)
except EncryptionError as e:
print(f"Encryption error: {e}")
Key Management#
Best practices for key selection:
def is_valid_key(key: int) -> bool:
return str(key).endswith('9') and key > 0
# Example usage
key = 59
if is_valid_key(key):
encryptor = ENcrypt(key)
else:
print("Invalid key")
Next Steps#
After mastering these basics, you can:
Explore the Examples page for more use cases
Check the api documentation for detailed reference
Learn about security considerations in Security Considerations
Contribute to the project following our contributing guide
Tips and Tricks#
1. Performance Optimization#
Reuse encryptor instances when possible
Consider message size and matrix operations
Use appropriate key sizes for your needs
2. Security Considerations#
Choose appropriate key sizes
Secure key storage
Understand the encryption limitations
3. Debugging#
Enable logging for better debugging:
import logging
logging.basicConfig(level=logging.DEBUG)
Common Issues#
1. Invalid Keys#
Keys must end in 9
Keys must be positive integers
2. Character Set Issues#
Messages must use characters from the alphabet
Case sensitivity considerations
Handling special characters
3. Matrix Operations#
Understanding matrix invertibility
Handling numerical precision
Performance with large messages
Getting Help#
If you need assistance:
Check the documentation
Look through the examples
Open an issue on GitHub
Join our community discussions
Remember to consult the api reference for detailed information about specific functions and classes.