M-XXTEA Reference Implementation (Compliant with Ragab et al., 2021)

Modified XXTEA block cipher with chaotic key generation and AES S-Box substitution

1. Text Encryption / Decryption




2. File Encryption / Decryption

Works for any binary file (text, images, PDFs, etc.).


3. Compliance Summary (per Ragab et al., 2021)

Note:For reproducible tests, set a fixed nonce (e.g., 0). For security demonstrations, leave nonce blank to randomize each run. For production use, enable HMAC Integrity Check to protect against tampering and padding oracle attacks. When interoperating with other implementations, ensure the same S-Box (Table 5) and the same endian/packing conventions (little-endian 32-bit words) are used. File Support is optional, not described in the paper. Downloaded encrypted files will be of .enc extension


4. Usage Recommendations and Parameters

4.1 Block and Word Sizes

ParameterSymbolTypical ValueNotes
Word size32 bitsfixedAll operations use 32-bit unsigned words.
Minimum block size64 bits (2 words)requiredSmallest valid block for the Feistel network.
Typical block size128 bits (4 words)recommendedBest balance between speed and diffusion.
Maximum block sizen × 32 bitsarbitraryLimited only by memory; rounds scale with block length.

Note: Using fewer than four 32-bit words reduces diffusion; large blocks give higher security at modest cost.

4.2 Finite-Field Domain

All arithmetic occurs in the unsigned 32-bit integer field (mod 2³²). JavaScript’s >> 0 operator enforces wrap-around consistency with the paper’s equations in ℤ₂³².

4.3 Key and Nonce Guidance

Tip: In this implementation, the nonce is automatically stored in the first 4 bytes of each ciphertext or encrypted file.

4.4 Number of Rounds

Rounds follow the adaptive rule rounds = floor(6 + 52 / n), where n = number of 32-bit words in the block.

4.5 Substitution Layer

The AES S-Box (Table 5 in Ragab et al., 2021) introduces non-linearity and diffusion. It is applied before encryption and inverse-applied after decryption. You may experiment with key-dependent S-Boxes for future research.

4.6 Padding

PKCS#7 padding for 8-byte blocks is used. Padding should remain enabled unless you manage exact block alignment manually.

4.7 Security and Integrity

4.8 File Handling

4.9 Performance Notes

4.10 Summary Recommendations

ScenarioRecommended Settings
Text encryption128-bit blocks, ≈ 19–32 rounds, HMAC on
File encryptionRandom nonce, 128-bit key, HMAC on
Lightweight / IoT64-bit blocks, ≈ 16 rounds, HMAC off
High-security mode≥ 128-bit blocks, ≥ 32 rounds, HMAC on, random nonce

5. References


Note: This JavaScript implementation reproduces the essential functional behavior of M-XXTEA as described in Ragab et al. (2021), extended for web demonstration purposes with HMAC and file support. For research publication or interoperability testing, ensure compliance with block sizes, substitution table, and chaotic key schedule as specified.