25.py 585 B

12345678910111213141516171819202122232425262728293031
  1. lines = []
  2. with open("25.input") as f:
  3. for line in f.readlines():
  4. lines.append(int(line))
  5. subject = 7
  6. def crack_key(public_key):
  7. value = 1
  8. for i in range(1, 1000000000):
  9. value *= subject
  10. value %= 20201227
  11. if value == public_key:
  12. return i
  13. return None
  14. def generate_key(subject, loop_size):
  15. value = 1
  16. for i in range(0, loop_size):
  17. value *= subject
  18. value %= 20201227
  19. return value
  20. loop_sizes = [crack_key(line) for line in lines]
  21. print(loop_sizes)
  22. print(generate_key(lines[0], loop_sizes[1]))