CSenshi

Cryptography - HW1.2 (Challenge-02)

Jan 10th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def fixed_xor(s1, s2):
  2.     res = ''
  3.  
  4.     for i in range(len(s1)):
  5.         # # convert hex numbers to decimal
  6.         i1, i2 = int(s1[i], 16), int(s2[i], 16)
  7.  
  8.         # evaluate xor product
  9.         xor = i1 ^ i2
  10.  
  11.         # convert decimal back to hex
  12.         xor_s = hex(xor)
  13.  
  14.         # remove '0x' in the beginning of the string
  15.         xor_s = xor_s[2:]
  16.  
  17.         # append to result
  18.         res += xor_s
  19.  
  20.     return res
  21.  
  22.  
  23. if __name__ == "__main__":
  24.     s1 = input()
  25.     s2 = input()
  26.     result = fixed_xor(s1, s2)
  27.     print(result)
Add Comment
Please, Sign In to add comment