Skip to content

Instantly share code, notes, and snippets.

@rexim
Created January 5, 2022 19:50
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rexim/81de1139a91839b96f9a65ad05c61406 to your computer and use it in GitHub Desktop.
Save rexim/81de1139a91839b96f9a65ad05c61406 to your computer and use it in GitHub Desktop.
from random import Random
def generate_bytes_for_seed(seed: int, message: str) -> bytearray:
data = Random(seed)
garbage = Random(34988394)
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(garbage.randrange(256))
return result
seed = 69420
message = 'Your secret message!'
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)))
""")
@artus25200
Copy link

Really cool ! Good job

@Ernest1338
Copy link

Isn't the line 7 redundant as the seed was already set in the line 4?

@SoutrikBandyopadhyay
Copy link

@Ernest1338 You are right ! That seed definition in line 7 is redundant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment