Spatial Hasher
A Rust library for deterministic encryption and decryption using 3D spatial parameters.
Table of Contents
- Overview
- Features
- Installation
- Usage
- Example
- Testing
- Dependencies
- Security Considerations
- Disclaimer
- Contributing
- License
Overview
spatial_hasher
provides a way to encrypt and decrypt data using a deterministic algorithm based on 3D spatial transformations. It utilizes a combination of a 3D point, a rotation axis, the number of iterations, and a strength parameter to seed a pseudo-random number generator (PRNG). This ensures that the same input parameters will always produce the same encrypted output.
Features
- Deterministic Encryption and Decryption: Ensures consistent results with the same parameters.
- Customizable Parameters: Adjust the starting point, rotation axis, iterations, and strength to modify the encryption.
- Simple API: Easy to integrate into other Rust projects.
- Serialization Support: Structures can be serialized and deserialized using
serde
. - Unit Tests Included: Verify the functionality with built-in tests.
Installation
Add spatial_hasher
to your Cargo.toml
dependencies:
[]
= "0.1.0"
Usage
First, import the necessary structs:
use ;
Creating a spatial_hasher Instance
Create a spatial_hasher instance by specifying the starting point, rotation axis, number of iterations, and strength:
let point = Point3D ;
let rotation_axis = RotationAxis ;
let iterations = 10;
let strength = 0.1;
let hasher = new;
Encrypting Data
Encrypt data by passing a byte slice to the encrypt method:
let data = b"Secret Message";
let encrypted_data = hasher.encrypt;
Decrypting Data
Decrypt data by passing the encrypted byte slice to the decrypt method:
let decrypted_data = hasher.decrypt;
assert_eq!;
Example
Below is a complete example demonstrating how to use spatial_hasher:
use ;
Output:
Original Data: "Hello, World!"
Encrypted Data:
Decrypted Data: "Hello, World!"
Testing
Run the unit tests included with spatial_hasher using:
Dependencies
spatial_hasher
relies on the following crates:
rand
for random number generation.rand_xoshiro
for the Xoshiro256++ PRNG.serde
for serialization and deserialization.sha2
for SHA-256 hashing.
Security Considerations
spatial_hasher
uses XOR encryption with a pseudo-random number generator (PRNG) sequence derived from a seed generated via SHA-256 hashing of the input parameters. The PRNG used is Xoshiro256++
, which is not cryptographically secure.
As a result, spatial_hasher
should not be used for encrypting sensitive or confidential data. The encryption provided is suitable for obfuscation or simple data hiding in contexts where strong security is not required.
For applications requiring robust, secure encryption, please use established cryptographic libraries such as the RustCrypto collection of crates.
Disclaimer
spatial_hasher
is intended for educational and demonstrational purposes. It should not be used in production systems where data security is a concern. The authors and contributors are not responsible for any misuse of this software.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Write tests for any new functionality.
- Submit a pull request with a detailed description of your changes.
License
This project is licensed under the MIT License. See the LICENSE file for details.