Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, random, traceback
- # Select two random files from the folder this file is in and read them. Make sure there are at least two files. This will work best if all files are executable python programs.
- a, b = random.sample(os.listdir(os.path.dirname(os.path.realpath(__file__))), 2)
- a = open(a).read()
- b = open(b).read()
- # Loop until an executable program is found
- while 1:
- # Combinate the two files randomly
- ai = 1
- bi = 1
- s = ''
- while ai < len(a) or bi < len(a):
- # Append one byte at time
- if bi == len(b) or ai < len(a) and random.getrandbits(1):
- s += a[ai-1]
- ai += 1
- else:
- s += b[bi-1]
- bi += 1
- # After combining two files successfully, try executing new code
- try:
- exec(s)
- # If the execution happens to be successful, print the code and exit
- print s
- break
- except:
- # Most likely the execution will fail. Try again.
- traceback.print_exc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement