Skip to content

Crypto

Cryptographic utilities for Geometry Dash encoding.

XOR Cipher

gdpy.crypto.xor

XOR cipher implementations for Geometry Dash encoding.

The XOR cipher is used throughout Geometry Dash for various encoding purposes, including level passwords and other data.

xor_cipher

xor_cipher(data: str, key: str) -> str

Apply XOR cipher to data using a string key.

Each character in the data is XOR'd with the corresponding character in the key, cycling through the key as needed.

Parameters:

Name Type Description Default
data str

The string to encode/decode.

required
key str

The key to use for XOR operation.

required

Returns:

Type Description
str

The XOR'd result string.

Example
encoded = xor_cipher("hello", "key")
decoded = xor_cipher(encoded, "key")  # Returns "hello"
Source code in gdpy/crypto/xor.py
def xor_cipher(data: str, key: str) -> str:
    """Apply XOR cipher to data using a string key.

    Each character in the data is XOR'd with the corresponding
    character in the key, cycling through the key as needed.

    Args:
        data: The string to encode/decode.
        key: The key to use for XOR operation.

    Returns:
        The XOR'd result string.

    Example:
        ```python
        encoded = xor_cipher("hello", "key")
        decoded = xor_cipher(encoded, "key")  # Returns "hello"
        ```
    """
    result = []
    for i, char in enumerate(data):
        key_char = key[i % len(key)]
        result.append(chr(ord(char) ^ ord(key_char)))
    return "".join(result)

xor_cipher_int

xor_cipher_int(data: str, key: int) -> str

Apply XOR cipher to data using an integer key.

Each character in the data is XOR'd with the key value.

Parameters:

Name Type Description Default
data str

The string to encode/decode.

required
key int

The integer key to use for XOR operation.

required

Returns:

Type Description
str

The XOR'd result string.

Example
encoded = xor_cipher_int("hello", 11)
decoded = xor_cipher_int(encoded, 11)  # Returns "hello"
Source code in gdpy/crypto/xor.py
def xor_cipher_int(data: str, key: int) -> str:
    """Apply XOR cipher to data using an integer key.

    Each character in the data is XOR'd with the key value.

    Args:
        data: The string to encode/decode.
        key: The integer key to use for XOR operation.

    Returns:
        The XOR'd result string.

    Example:
        ```python
        encoded = xor_cipher_int("hello", 11)
        decoded = xor_cipher_int(encoded, 11)  # Returns "hello"
        ```
    """
    result = []
    for char in data:
        result.append(chr(ord(char) ^ key))
    return "".join(result)

GJP2 Encoding

gdpy.crypto.gjp

GJP2 password encoding for Geometry Dash authentication.

GJP2 (Geometry Jump Password 2) is the hashing algorithm used for encoding passwords when communicating with the Geometry Dash servers.

generate_gjp2

generate_gjp2(password: str) -> str

Generate a GJP2 hash from a password.

GJP2 is used for authenticating with the Geometry Dash API. The password is salted with a fixed string and hashed using SHA-1.

Parameters:

Name Type Description Default
password str

The plaintext password to hash.

required

Returns:

Type Description
str

A 40-character hexadecimal SHA-1 hash string.

Example
gjp2_hash = generate_gjp2("my_password")
# Returns a 40-character hex string
Source code in gdpy/crypto/gjp.py
def generate_gjp2(password: str) -> str:
    """Generate a GJP2 hash from a password.

    GJP2 is used for authenticating with the Geometry Dash API.
    The password is salted with a fixed string and hashed using SHA-1.

    Args:
        password: The plaintext password to hash.

    Returns:
        A 40-character hexadecimal SHA-1 hash string.

    Example:
        ```python
        gjp2_hash = generate_gjp2("my_password")
        # Returns a 40-character hex string
        ```
    """
    salted = password + Salts.GJP2
    return hashlib.sha1(salted.encode()).hexdigest()

Checksums

gdpy.crypto.chk

decode_rewards_response

decode_rewards_response(
    response: str, key: str = "59182"
) -> str

Decode the XOR'd and base64 encoded rewards response.

Parameters:

Name Type Description Default
response str

The response from the server.

required
key str

XOR key to use for decoding.

'59182'

Returns:

Type Description
str

The decoded response string.

Source code in gdpy/crypto/chk.py
def decode_rewards_response(response: str, key: str = "59182") -> str:
    """Decode the XOR'd and base64 encoded rewards response.

    Args:
        response: The response from the server.
        key: XOR key to use for decoding.

    Returns:
        The decoded response string.
    """
    # Remove the 5 random chars at the start and split by |
    encoded_part = response.split("|")[0][5:]
    decoded = base64.urlsafe_b64decode(encoded_part.encode()).decode()
    return "".join(chr(ord(char) ^ ord(key[i % len(key)])) for i, char in enumerate(decoded))

generate_rewards_chk

generate_rewards_chk(key: str = '59182') -> str

Generate chk parameter for rewards endpoints.

Parameters:

Name Type Description Default
key str

XOR key to use (19847 for challenges, 59182 for chest rewards)

'59182'

Returns:

Type Description
str

The chk parameter string.

Source code in gdpy/crypto/chk.py
def generate_rewards_chk(key: str = "59182") -> str:
    """Generate chk parameter for rewards endpoints.

    Args:
        key: XOR key to use (19847 for challenges, 59182 for chest rewards)

    Returns:
        The chk parameter string.
    """
    random_string = "".join(
        random.choice("1234567890qwertyuiopaqsdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM")
        for _ in range(5)
    )
    random_number = str(random.randint(10000, 1000000))
    xor_result = "".join(
        chr(ord(char) ^ ord(key[i % len(key)])) for i, char in enumerate(random_number)
    )
    encoded = base64.b64encode(xor_result.encode()).decode()
    return random_string + encoded

Base64

gdpy.crypto.base64