daily pastebin goal
34%
SHARE
TWEET

keyedxor

a guest Feb 13th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python2.7
  2.  
  3. key = "unreformed"
  4.  
  5. with open("/home/ano21lx/Desktop/easyctf2018/CRYPTO/keyedXOR/keyedxor.txt", 'rb') as bin:
  6.     file = bin.read()
  7.  
  8. def xor(plain, key):
  9.  
  10.     dec = ""
  11.  
  12.     key_length = len(key)
  13.     plain_as_int = [ord(i) for i in plain]
  14.     key_as_int = [ord(i) for i in key]
  15.  
  16.     for i in range(len(plain)):
  17.         dec += chr((plain_as_int[i] ^ key_as_int[i % key_length]) % 256)
  18.  
  19.     return dec
  20.  
  21. def main():
  22.  
  23.     res = ""
  24.  
  25.     try:
  26.         for word in open("/home/ano21lx/Desktop/easyctf2018/CRYPTO/keyedXOR/wordlist.txt", 'rb'):
  27.             new_key = key + word
  28.  
  29.             res = xor(file, new_key)
  30.  
  31.             if "easyctf{fl" in res:
  32.                 print word, "is ok"
  33.                 print "FLAG : ", res
  34.             else:
  35.                 print "nope"
  36.  
  37.     except IOError:
  38.         print "error"
  39.  
  40. if __name__ == "__main__":
  41.     main()
RAW Paste Data
Top