Initial commit

This commit is contained in:
Mattéo Delabre 2021-01-26 22:36:26 +01:00
commit bc244e3a79
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
3 changed files with 70 additions and 0 deletions

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM alpine
RUN apk add --no-cache bash python3
RUN adduser -D user
USER user
ADD runall.py /
CMD ["python3", "/runall.py"]

6
README.md Normal file
View File

@ -0,0 +1,6 @@
How to run:
```
docker image build --quiet --tag runall-image .
docker container run --tty --rm --read-only runall-image
```

58
runall.py Normal file
View File

@ -0,0 +1,58 @@
from itertools import product
import string
import subprocess
def check_pair(script, instr, outstr):
result = subprocess.run(
["/usr/bin/env", "bash", "-c", script],
input=instr.encode(),
capture_output=True,
)
return result.returncode == 0 and result.stdout == outstr.encode()
def check_pairs(script, pairs):
for pair in pairs:
if not check_pair(script, *pair):
return False
return True
def find_script(pairs, max_length):
candidates = []
total_options = len(string.printable) ** max_length
current_option = 0
for length in range(max_length + 1):
for letters in product(string.printable, repeat=length):
if current_option % 1000 == 0:
print(f"Progress: {current_option}/{total_options}")
script = "".join(letters)
if check_pairs(script, pairs):
print("> Found candidate:", script)
candidates.append(script)
current_option += 1
print("Candidates:", candidates)
if __name__ == '__main__':
# Identity
print("\nSearching for identity")
find_script((
("1", "1"),
("2", "2"),
("3", "3"),
), max_length=2)
# Successor
print("\nSearching for successor")
find_script((
("1", "2"),
("2", "3"),
("3", "4"),
), max_length=5)