Guest User

Untitled

a guest
Jul 16th, 2020
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from Crypto.Util.number import bytes_to_long, getPrime
  2. from random import randint
  3. from secret import flag
  4.  
  5. MIN = randint(0x30, 0x40)
  6. P = 2**521 - 1
  7.  
  8. def eval_at(poly, x, prime):
  9. """Evaluates polynomial (coefficient tuple) at x"""
  10. accum = 0
  11. for coeff in reversed(poly):
  12. accum *= x
  13. accum += coeff
  14. accum %= prime
  15. return accum
  16.  
  17. def main():
  18. poly = [bytes_to_long(flag.encode())]
  19. poly.extend(set([randint(1, P - 1) for i in range(MIN)]))
  20. print("┌───────────────┐")
  21. print("│ SSS Encryptor │")
  22. print("└───────────────┘")
  23. print("Enter text to encrypt, leave empty to quit.")
  24. while True:
  25. data = input(">>> ")
  26. if bytes_to_long(data.encode()) % P == 0:
  27. break
  28. print(eval_at(poly, bytes_to_long(data.encode()), P))
  29.  
  30. if __name__ == "__main__":
  31. main()
RAW Paste Data