secret-python-message/main.py
2023-05-11 21:15:11 +03:00

28 lines
692 B
Python

#!/bin/python3
from random import Random
import random
def generate_bytes_for_seed(seed: int, message: str) -> bytearray:
data = Random(seed)
data.seed(seed)
result = bytearray()
i = 0
while i < len(message):
c = message[i]
if data.randrange(2):
result.append(data.randrange(256) ^ ord(c))
i += 1
else:
result.append(random.randrange(256))
return result
seed = 69420
message = 'Hello, World!'
print(f"""import random
random.seed({seed})
print(''.join(chr(random.randrange(256) ^ c)
for c in bytes.fromhex({repr(generate_bytes_for_seed(seed, message).hex().upper())})
if random.randrange(2)))
""")