Practical: XOR cipher with bytearray Dry Run in PYTHON

Practical: XOR cipher with bytearray is an interactive PYTHON dry run visualizer from the Bytes programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Practical: XOR cipher with bytearray Program Code

# XOR encryption with bytearray
def xor_crypt(data, key):
    ba = bytearray(data)
    for i in range(len(ba)):
        ba[i] ^= key
    return bytes(ba)

plain = b"Secret message"
key = 0x55

encrypted = xor_crypt(plain, key)
decrypted = xor_crypt(encrypted, key)

print("plain:   ", plain)
print("encrypted:", encrypted.hex())
print("decrypted:", decrypted)

# simple checksum (sum of bytes)
checksum = sum(plain) & 0xFF
print("checksum:", hex(checksum))

View the complete Bytes programs page.

Program Console Practical: XOR cipher with bytearray Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.