CSenshi

Cryptography - HW1.5 (Challenge-05)

Jan 10th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def encrypt_xor(plain_text, key):
  2.     result = ''
  3.     # iterate each char of word
  4.     for i in range(len(plain_text)):
  5.         # key to xor on
  6.         xor = ord(key[i % len(key)])
  7.         # char to xor
  8.         char = ord(plain_text[i])
  9.         # xor resutl
  10.         res = char ^ xor
  11.         # convert to hex
  12.         res_hex = "{0:0{1}x}".format(res, 2)
  13.         # append result
  14.         result += res_hex
  15.     return result
  16.  
  17.  
  18. if __name__ == "__main__":
  19.     # input key
  20.     key = input()
  21.     # input plain text
  22.     plain_text = input()
  23.  
  24.     # encryption
  25.     cipher = encrypt_xor(plain_text, key)
  26.  
  27.     # result
  28.     print(cipher)
Add Comment
Please, Sign In to add comment