Ingin menangid
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
870 B

5 years ago
  1. from base64 import *
  2. def enkripsi(plain, keys):
  3. enc = []
  4. plain = b64encode(plain)
  5. for i, l in enumerate(plain):
  6. kunci = ord(keys[i % len(keys)])
  7. teks = ord(l)
  8. enc.append(chr((teks + kunci) % 127))
  9. #enc = teks + kunci
  10. return ''.join(enc)
  11. def findKey():
  12. key = []
  13. known = b64encode("IDCC{")
  14. file = open("enkripsi", "rb")
  15. file = file.read()
  16. for i, l in enumerate(known):
  17. kunci = ord(file[i])
  18. teks = ord(l)
  19. key.append((chr((kunci - teks) % 127)))
  20. return ''.join(key)
  21. def decryption():
  22. key = "raja"
  23. flag = []
  24. file = open("enkripsi", "r").read()
  25. for i, l in enumerate(file):
  26. kunci = ord(key[i % len(key)])
  27. cipher = ord(l)
  28. flag.append(chr((cipher - kunci) % 127))
  29. return ''.join(flag)
  30. print findKey()
  31. print b64decode(decryption())