Skip to content

ENCRYPT

Overview

ENCRYPT is the encryption library for secure user-to-user messaging. It uses the SHIO reaction mechanism to perform stream cipher encryption, allowing users to send encrypted data that only the intended recipient can decrypt.

  • Inherits: DYSNOMIA
  • License: Sharia
  • Solidity: ^0.8.21

What This Means For Players

Plain English Summary: ENCRYPT enables secret messaging - send private messages that only the recipient can read. It uses your SHIO's cryptographic properties to scramble messages so that only someone with the right key and SHIO ownership can unscramble them.

Real-World Analogy: Think of ENCRYPT like a sealed letter system where only you and the recipient have the key to open the envelope. You write a message, seal it with your key, and only the person with the matching key can read it. Messages even expire after 10 days to keep the system clean.

How It Affects Your Gameplay: - Private messages - Send encrypted data to specific players using their Soul ID - Key-based security - You choose a password/key, and only someone with that key can decrypt - Temporary storage - Encrypted messages expire after 10 days - SHIO authorization - Only SHIO owners can encrypt/decrypt their messages

State Variables

Variable Type Visibility Description
Type string public constant "LibEncrypt"
Zheng ZHENG public Reference to installation manager
Void VOID public Reference to session manager
_encryptions mapping(uint64 => Encryption) private Stored encrypted data
_indexes uint64[] private List of encryption indexes

Structs

Encryption

struct Encryption {
    bytes Data;       // Encrypted data
    uint256 Expiry;   // Expiration timestamp
}

Read Functions

hashKey

function hashKey(bytes memory Key) public returns (uint64 result)
- Access: public - Parameters: - Key (bytes): Key bytes to hash - Returns: - result (uint64): Hash value = keccak256(Key) % MotzkinPrime - Description: Computes a cryptographic hash of the key for use in encryption operations. - Computation Details: - result = uint256(keccak256(Key)) % 953467954114363 (MotzkinPrime) - In Plain English: Convert your password into a cryptographic number. This scrambled version of your key is used internally for the stream cipher encryption.

Write Functions

Encrypt (string version)

function Encrypt(uint64 From, uint64 to, string memory Key, string memory Data) public returns (uint64 index)
- Access: public - Parameters: - From (uint64): Sender's Soul ID - to (uint64): Recipient's Soul ID - Key (string): Encryption key/password - Data (string): Data to encrypt - Returns: - index (uint64): Storage index for later decryption retrieval - Description: String wrapper that converts to bytes and calls core Encrypt. - In Plain English: Send an encrypted secret message to another player. Returns an index number to find the message later.

Encrypt (bytes version)

function Encrypt(uint64 From, uint64 to, bytes memory Key, bytes memory Data) public returns (uint64 index)
- Access: public - Parameters: - From (uint64): Sender's Soul ID - to (uint64): Recipient's Soul ID - Key (bytes): Encryption key bytes - Data (bytes): Data bytes to encrypt - Returns: - index (uint64): Unique storage index for retrieval - Description: Core encryption function that verifies sender ownership and stores encrypted data. - Logic Flow: 1. Get Bao structs: _from = Void.GetRodByIdx(From), _to = Void.GetRodByIdx(to) 2. Verify sender ownership: if(!_from.Shio.owner(msg.sender)) revert NotParty 3. Call internal Crypt: (index, encrypted) = Crypt(_from, _to, Key, Data) 4. Store with expiry: _encryptions[index] = Encryption(encrypted, block.timestamp + 10 days) 5. Add to index tracking: _indexes.push(index) - Side Effects: Stores encrypted data; triggers SHIO reactions; adds to _indexes array - In Plain English: Encrypt and store data for another player. Verifies you own the sender's SHIO, runs the stream cipher, and stores the result with a 10-day expiry.

Decrypt (string version)

function Decrypt(uint64 From, uint64 to, uint64 Index, string memory Key) public returns (bytes memory)
- Access: public - Description: String wrapper that converts Key to bytes and calls core Decrypt. - In Plain English: Read an encrypted message using the password the sender shared with you.

Decrypt (bytes version)

function Decrypt(uint64 From, uint64 to, uint64 Index, bytes memory Key) public returns (bytes memory result)
- Access: public - Parameters: - From (uint64): Original sender's Soul ID - to (uint64): Recipient's Soul ID - Index (uint64): Storage index from Encrypt - Key (bytes): Decryption key bytes - Returns: - result (bytes): Decrypted data - Description: Retrieves encrypted data and decrypts using the stream cipher. - Logic Flow: 1. Get Bao structs from VOID 2. Verify recipient ownership: if(!_to.Shio.owner(msg.sender)) revert NotParty 3. Retrieve stored encryption: _encryptions[Index] 4. Call internal Crypt to decrypt: (_, result) = Crypt(_from, _to, Key, storedData) 5. Delete if expired: auto-cleanup of old entries - Side Effects: May delete expired entries; triggers SHIO reactions - In Plain English: Decrypt a message sent to you. Verifies you own the recipient's SHIO and runs the same cipher (XOR is its own inverse) to recover the original data.

Encapsulate

function Encapsulate(Bao memory From, uint64 Gamma, uint64 Rho, uint64 Upsilon, uint64 Ohm) public returns (uint64 Entropy, bytes memory Geng)
- Access: public - Parameters: - From (Bao): Sender's Bao operation context - Gamma (uint64): First value to encapsulate - Rho (uint64): Second value to encapsulate - Upsilon (uint64): Third value to encapsulate - Ohm (uint64): Fourth value (ignored in storage, used for entropy) - Returns: - Entropy (uint64): Resulting entropy from encryption - Geng (bytes): Encrypted 24-byte chromosome data - Description: Packages four uint64 values into an encrypted chromosome bundle. - Logic Flow: 1. Convert values to bytes and concatenate into 24-byte structure 2. Encrypt via Crypt using From's Bao 3. Return entropy and encrypted bytes - In Plain English: Package cryptographic state values into an encrypted "chromosome" bundle for secure transfer or storage.

Saat

function Saat(bytes memory Geng) public pure returns (uint64[3] memory Go)
- Access: public pure - Parameters: - Geng (bytes): Chromosome bytes (minimum 18 bytes required) - Returns: - Go (uint64[3]): Array of 3 extracted uint64 values - Description: Extracts Saat identity values from a chromosome byte array. - Logic Flow: 1. Validate: if(Geng.length < 18) revert ChromosomeLength 2. For each of 3 slots: accumulate 8 bytes into uint64 3. Return extracted values - Computation Details: - Go[0] = bytes 0-7, Go[1] = bytes 8-15, Go[2] = bytes 16-23 - Each byte shifted and accumulated into uint64 - In Plain English: Unpack a chromosome bundle back into three identity numbers. The reverse of Encapsulate.

Prune

function Prune() public
- Access: public - Description: Cleans up expired encryption entries from storage. - Logic Flow: 1. Iterate through _indexes array 2. For each expired entry (Expiry < block.timestamp): delete from _encryptions 3. Swap with last element and pop to maintain array - Side Effects: Deletes expired _encryptions entries; shrinks _indexes array - In Plain English: Clean up old expired messages. Encrypted messages expire after 10 days - this function deletes them to save storage and gas.

Errors

Error Parameters Description
NotParty from, to, party Caller not authorized
TooManyCrypts max, count Index limit reached
ChromosomeLength minimum, length Chromosome too short

Contract Interactions

Depends On

  • DYSNOMIA - Base token functionality
  • VOID - Session management
  • ZHENG - Installation access
  • SHIO - Reaction mechanism
  • SHA - React function

Registered In

  • VOID library registry as "encrypt"

Special Mechanisms

Stream Cipher

The Crypt function implements a stream cipher: 1. React with hashed key to get initial (Eta, Kappa) 2. For each 8-byte block: - React on recipient's Cone to get new state - XOR data with Kappa bytes - React on sender's Rod for next iteration

for(uint256 i = 0; i < Data.length; ) {
    (_b, _m) = to.Shio.Rho().Cone.React(_e, to.Shio.Rho().Rod.View().Channel);
    for(uint256 j = 0; j < 8 && i < Data.length; j++) {
        result[i] = bytes8(_m)[j] ^ Data[i];
        i++;
    }
    (_e, _m) = From.Shio.Rho().Rod.React(_b, From.Shio.Rho().Cone.View().Channel);
}

Authorization Check

Only the sender can encrypt, only the recipient can decrypt:

// Encrypt
if(!_from.Shio.owner(msg.sender)) revert NotParty(...);

// Decrypt
if(!_to.Shio.owner(msg.sender)) revert NotParty(...);

Expiration System

Encrypted data expires after 10 days:

_encryptions[index].Expiry = block.timestamp + (10 days);

Auto-Cleanup

The Prune function removes expired entries, and decryption auto-cleans expired data.

Usage Pattern

// Sender encrypts
uint64 index = encrypt.Encrypt(mySoul, recipientSoul, "password", "secret message");

// Recipient decrypts
bytes memory message = encrypt.Decrypt(senderSoul, mySoul, index, "password");

// Clean up old data
encrypt.Prune();

Security Considerations

  • Key is hashed before use (keccak256)
  • Encryption depends on SHIO state
  • Only SHIO owners can encrypt/decrypt
  • Data expires to limit storage
  • Index limit prevents DoS

Contract Verification

Property Value
Keccak256 Hash 0xccf31161b82a33b8f516eaa7a49cb1b9095759dfdd0bce5c777ec20f7ce12fb3
Source URL https://raw.githubusercontent.com/busytoby/atropa_pulsechain/main/solidity/dysnomia/lib/encrypt.sol
Hash Generated 2026-02-08T00:29:08Z