An experimental, high-performance cryptographic library using a dynamic network architecture as the key.
Project description
ACN: Artificial Cryptographic Network
ACN is an experimental, high-performance cryptographic library that introduces a novel approach to symmetric-key encryption, inspired by the architectural principles of neural networks. Instead of using a traditional fixed-length bit string as a key, ACN utilizes the entire architecture of a dynamic network as the secret key itself.
This library is designed for performance, leveraging GPU acceleration via CuPy for massively parallel processing, making it suitable for encrypting large volumes of data at high speeds.
Disclaimer: This is an experimental cryptographic library. While it is built on strong cryptographic principles, it has not undergone formal, public cryptographic analysis. Use in production for critical data is not recommended until it has been peer-reviewed by security experts.
Key Concepts
The security of ACN is rooted in a unique blend of modern cryptographic primitives and a dynamic, key-defined structure.
1. Key-as-Architecture
The core innovation of ACN is its keying mechanism. The "key" is not a simple password or a file of bits; it is a comprehensive blueprint that defines a unique cryptographic network. This blueprint specifies:
- The size of the data blocks to be processed.
- The internal width of the core processing function.
- The number of processing rounds (equivalent to layers of security).
- The unique sequence of mathematical operations within each of the network's "cryptographic neurons."
This results in an astronomical key space, where the secret is the entire algorithm's structure, making brute-force attacks on the key itself practically impossible.
2. Feistel Network Structure
At its highest level, ACN employs a Feistel network, a well-established cryptographic structure used in many proven ciphers (like DES). This structure processes data in rounds, repeatedly applying a non-reversible "F-function" to parts of the data. The Feistel design guarantees that the entire process is fully reversible for decryption, even if the core function is not.
3. The "F-Function" as a Cryptographic Network
The heart of each Feistel round is the F-function. In ACN, this function is a single-layer, parallel cryptographic network. It takes a block of data and processes each part simultaneously through its "cryptographic neurons." Each neuron is a unique sequence of strong cryptographic operations, including:
- Non-linear Substitution: Using a highly non-linear S-Box (from the AES standard) to create confusion.
- Bitwise Rotations: To shuffle bit patterns.
- Modular Arithmetic: To combine bitwise and arithmetic operations, adding complexity.
- XOR Operations: For fast, secure mixing of data.
4. Key Scheduling
To prevent attacks that exploit repetition across rounds, ACN uses a key scheduling algorithm. It takes a 256-bit master key (stored in the key file) and derives unique subkeys for every operation in every neuron in every round. This ensures that the cryptographic transformation is different at each stage of the process.
5. CTR (Counter) Mode of Operation
To securely encrypt data of any length and enable high-speed parallel processing, ACN uses the Counter (CTR) mode.
- A random, single-use number (a "nonce") is generated.
- A series of "counter blocks" is created from this nonce.
- These counter blocks are encrypted by the Feistel network to produce a high-security keystream.
- The plaintext data is simply XORed with this keystream to produce the ciphertext.
This mode is highly secure, prevents patterns in the plaintext from appearing in the ciphertext, and is perfectly suited for GPU acceleration.
Installation
pip install acn-crypto
Note: This library requires an NVIDIA GPU and a working installation of the CUDA Toolkit and CuPy.
Quickstart
import os
from acn import ACN, save_key, load_key
# --- 1. Define Architecture and Key Management ---
# The architecture defines the structure of our cryptographic network.
# Format: [Block_Size, F_Function_Width, Num_Rounds]
# Block_Size must be an even number.
# F_Function_Width must be exactly half of Block_Size.
# Num_Rounds determines the depth of security.
architecture = [32, 16, 24] # A strong, recommended configuration
KEY_FILE = "my_super_secret.key"
# --- 2. Initialize the ACN Cipher ---
# This step generates a new, unique cryptographic network based on the
# specified architecture. The internal structure, including the master key
# and the sequence of operations in each neuron, is created randomly.
try:
print("Initializing a new ACN cipher...")
encryptor_cipher = ACN(architecture=architecture)
except Exception as e:
print(f"Error during initialization: {e}")
exit()
# --- 3. Save the Key ---
# The generated key (the entire network blueprint) is saved to a file.
# This file is essential for decryption. Protect it like any other secret key.
print(f"Saving the generated key to '{KEY_FILE}'...")
save_key(encryptor_cipher.key, KEY_FILE)
# --- 4. Encrypt Data ---
# ACN can encrypt strings or raw bytes automatically.
message_to_encrypt = "ACN combines cryptographic principles with neural network architecture."
print(f"\nOriginal message: '{message_to_encrypt}'")
print("Encrypting...")
encrypted_data = encryptor_cipher.encrypt(message_to_encrypt)
print(f"Encrypted data (first 32 bytes in hex): {encrypted_data[:32].hex()}...")
# --- 5. Decrypt Data with a New ACN Instance ---
# To simulate a real-world scenario, we create a completely new ACN instance,
# loading its structure from the saved key file.
print("\nLoading the key for decryption...")
try:
decryptor_cipher = ACN.from_key_file(KEY_FILE)
except Exception as e:
print(f"Error loading key for decryption: {e}")
exit()
print("Decrypting...")
# The decrypt method automatically handles decoding to a string by default.
decrypted_message = decryptor_cipher.decrypt(encrypted_data)
print(f"Decrypted message: '{decrypted_message}'")
# --- 6. Verification ---
print("\nVerifying the integrity of the data...")
if message_to_encrypt == decrypted_message:
print("✅ SUCCESS: The decrypted message perfectly matches the original.")
else:
print("❌ FAILURE: The data is corrupted or the key is incorrect.")
# --- Cleanup ---
# In a real application, you would keep the key file.
# For this demo, we'll remove it.
os.remove(KEY_FILE)
print(f"\nCleaned up the demo key file: '{KEY_FILE}'")
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file acn_crypto-1.1.1.tar.gz.
File metadata
- Download URL: acn_crypto-1.1.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b7a84ebea08532f18892378f57b1ec7e03b9bf52c2c41137739a7fa00e96354
|
|
| MD5 |
aab08e7100981578947bbe0a88f97ee8
|
|
| BLAKE2b-256 |
f376c7b9ccf15e4b068d8ede638de5e0b4c4be76f7429cadcf54b354bcd0a552
|
File details
Details for the file acn_crypto-1.1.1-py3-none-any.whl.
File metadata
- Download URL: acn_crypto-1.1.1-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e55ce67c20474985c0fb5e007dd609d4743909364b934be49beba68bd896b3a
|
|
| MD5 |
56f9805bde2ec691027ac489f22e7f22
|
|
| BLAKE2b-256 |
c308abaa1e5ccd5c8ba82acc17136d3a5510fb1aa6f97081b6a1447601dec77b
|