Skip to content

jam.utils.xor

xor

Functions:

Name Description
xor_my_data

Encrypts a string using a secret key with the XOR cipher.

xor_my_data

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

Encrypts a string using a secret key with the XOR cipher.

This function performs an XOR operation on each byte of the input data with the corresponding byte of the key. If the key is shorter than the data, it wraps around and continues from the beginning of the key. If you need to decrypt data, use the same function with the same secret key. XOR is a symmetric operation.

Parameters:

Name Type Description Default
data str

The plain text string to be encrypted.

required
key str

The secret key used for encryption.

required

Returns:

Name Type Description
str str

The encrypted data represented as a hexadecimal string.

Example
>>> encrypted = xor_my_data("Hello, World!", "secretkey")
>>> print(encrypted)
<...encrypted hex string...>

FILE PATH: jam/utils/xor.py