ucrypto – encryption related functions

The ucrypto module provides cryptographic functions for both generic algorithms and game-specific custom encryption schemes. All functions operate in-place on bytearray/memoryview objects.

Constants

ucrypto.DECRYPT = 0

Constant representing decryption mode for functions that support encryption/decryption.

ucrypto.ENCRYPT = 1

Constant representing encryption mode for functions that support encryption/decryption.

Game-Specific Cryptography Functions

These functions implement custom encryption schemes used by various video games.

ucrypto.diablo3(enc_mode, data)

Encrypts or decrypts data using Diablo 3’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

Returns:

The data parameter

Return type:

bytearray

ucrypto.dw8xl(data)

Encodes data using Dynasty Warriors 8: Xtreme Legends’ encoding scheme.

Parameters:

data (bytearray) – Data buffer to encode (modified in-place)

Returns:

The data parameter

Return type:

bytearray

ucrypto.silent_hill3(enc_mode, data)

Encrypts or decrypts data using Silent Hill 3’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

Returns:

The data parameter

Return type:

bytearray

ucrypto.nfs_undercover(enc_mode, data)

Encrypts or decrypts data using Need for Speed: Undercover’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

Returns:

The data parameter

Return type:

bytearray

ucrypto.final_fantasy13(enc_mode, data, key, version)

Encrypts or decrypts data using Final Fantasy XIII’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key

  • version (int) – Algorithm version parameter

Returns:

The data parameter

Return type:

bytearray

ucrypto.borderlands3(enc_mode, data, type)

Encrypts or decrypts data using Borderlands 3’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • type (int) – Encryption type parameter

Returns:

The data parameter

Return type:

bytearray

ucrypto.mgs_pw(enc_mode, data)

Encrypts or decrypts data using Metal Gear Solid: Peace Walker’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

Returns:

The data parameter

Return type:

bytearray

ucrypto.mgs_base64(enc_mode, data)

Encodes or decodes data using Metal Gear Solid’s custom Base64 algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT for encode, DECRYPT for decode)

  • data (bytearray) – Data buffer to process (modified in-place)

Returns:

The data parameter

Return type:

bytearray

ucrypto.mgs(enc_mode, data, key)

Encrypts or decrypts data using a generic Metal Gear Solid encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key

Returns:

The data parameter

Return type:

bytearray

ucrypto.mgs5_tpp(data, key)

Encodes data using Metal Gear Solid V: The Phantom Pain’s encoding scheme.

Parameters:
  • data (bytearray) – Data buffer to encode (modified in-place)

  • key (int) – Encoding key parameter

Returns:

The data parameter

Return type:

bytearray

ucrypto.monster_hunter(enc_mode, data, game_version)

Encrypts or decrypts data using Monster Hunter’s encryption algorithm.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • game_version (int) – Game version (2 or 3)

Returns:

The data parameter

Return type:

bytearray

Raises:

ValueError – If game_version is not 2 or 3

ucrypto.rgg_studio(data, key)

Applies XOR encryption to data using RGG Studio’s algorithm.

Parameters:
  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – XOR key

Returns:

The data parameter

Return type:

bytearray

Generic Cryptography Functions

These functions implement standard cryptographic algorithms.

ucrypto.aes_ecb(enc_mode, data, key)

Encrypts or decrypts data using AES in ECB mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (16, 24, or 32 bytes for AES-128, AES-192, or AES-256)

Returns:

The data parameter

Return type:

bytearray

ucrypto.aes_cbc(enc_mode, data, key, iv)

Encrypts or decrypts data using AES in CBC mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (16, 24, or 32 bytes for AES-128, AES-192, or AES-256)

  • iv (bytearray) – Initialization vector (16 bytes)

Returns:

The data parameter

Return type:

bytearray

ucrypto.aes_ctr(data, key, iv)

Encrypts or decrypts data using AES in CTR mode.

Parameters:
  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (16, 24, or 32 bytes for AES-128, AES-192, or AES-256)

  • iv (bytearray) – Counter/nonce (16 bytes)

Returns:

The data parameter

Return type:

bytearray

ucrypto.des_ecb(enc_mode, data, key)

Encrypts or decrypts data using DES in ECB mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (8 bytes)

Returns:

The data parameter

Return type:

bytearray

ucrypto.des3_cbc(enc_mode, data, key, iv)

Encrypts or decrypts data using Triple DES in CBC mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (24 bytes for 3-key DES)

  • iv (bytearray) – Initialization vector (8 bytes)

Returns:

The data parameter

Return type:

bytearray

ucrypto.blowfish_ecb(enc_mode, data, key)

Encrypts or decrypts data using Blowfish in ECB mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (1 to 56 bytes)

Returns:

The data parameter

Return type:

bytearray

ucrypto.blowfish_cbc(enc_mode, data, key, iv)

Encrypts or decrypts data using Blowfish in CBC mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (1 to 56 bytes)

  • iv (bytearray) – Initialization vector (8 bytes)

Returns:

The data parameter

Return type:

bytearray

ucrypto.camellia_ecb(enc_mode, data, key)

Encrypts or decrypts data using Camellia in ECB mode.

Parameters:
  • enc_mode (int) – Operation mode (ENCRYPT or DECRYPT)

  • data (bytearray) – Data buffer to process (modified in-place)

  • key (bytearray) – Encryption key (16, 24, or 32 bytes)

Returns:

The data parameter

Return type:

bytearray

Usage Notes

  • All functions operate in-place on the provided data buffer

  • Input data should be provided as bytearray or memoryview objects

  • For functions with enc_mode parameter, use the module constants ENCRYPT (1) or DECRYPT (0)

  • Buffer lengths must be appropriate for each algorithm (e.g., multiples of block size for block ciphers)

  • Keys and IVs must be the correct size for each algorithm

Example

import ucrypto
from ucrypto import ENCRYPT, DECRYPT

# Example using AES-ECB
data = bytearray(b"Hello World!1234")  # Must be 16-byte aligned for AES
key = bytearray(16)  # 16-byte key for AES-128

# Encrypt
ucrypto.aes_ecb(ENCRYPT, data, key)

# Decrypt
ucrypto.aes_ecb(DECRYPT, data, key)

# Example using game-specific encryption
save_data = bytearray(...)  # Game save data
ucrypto.mgs_pw(DECRYPT, save_data)