Advertisement
7oSkaaa

flip this!

Mar 20th, 2024
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | Source Code | 0 0
  1. import math
  2.  
  3. flag = "e4f4f4e4644534f56733e6b763f5273343e6e603671363f50397f5330757f55733e6f512f5273367e6e6036333c6f5430397f5730346f557d712e677"
  4.  
  5. def encrypt(flag):
  6.     bytes = []
  7.     # flip individual bytes
  8.     for b in flag:
  9.         bb = hex(ord(b)).split("x")[1]
  10.         bytes.append(bb[1] + bb[0])
  11.     print(bytes)
  12.  
  13.     for b in range(math.floor(len(bytes)/2)):
  14.         byte = b * 2
  15.         t = bytes[byte+1]
  16.         bytes[byte+1] = bytes[byte]
  17.         bytes[byte] = t
  18.  
  19.     # swap neighboring byte pairs
  20.     for b in range(math.floor(len(bytes)/4)):
  21.         byte = b * 4
  22.         t = bytes[byte]
  23.         t2 = bytes[byte+1]
  24.         bytes[byte] = bytes[byte+2]
  25.         bytes[byte+1] = bytes[byte+3]
  26.         bytes[byte+2] = t
  27.         bytes[byte+3] = t2
  28.     return "".join([str(e) for e in bytes])
  29.  
  30.  
  31. def decrypt(encrypted_string):
  32.     bytes = [encrypted_string[i:i+2] for i in range(0, len(encrypted_string), 2)]
  33.  
  34.     # Reverse the operations done in encryption
  35.     for b in range(math.floor(len(bytes)/4)):
  36.         byte = b * 4
  37.         t = bytes[byte]
  38.         bytes[byte] = bytes[byte+2]
  39.         bytes[byte+2] = t
  40.         t2 = bytes[byte+1]
  41.         bytes[byte+1] = bytes[byte+3]
  42.         bytes[byte+3] = t2
  43.  
  44.     for b in range(math.floor(len(bytes)/2)):
  45.         byte = b * 2
  46.         t = bytes[byte]
  47.         bytes[byte] = bytes[byte+1]
  48.         bytes[byte+1] = t
  49.  
  50.     decrypted = "".join([chr(int(e[1] + e[0], 16)) for e in bytes])
  51.     return decrypted
  52.  
  53.  
  54. decrypted_flag = decrypt(flag)
  55. print("Decrypted:", decrypted_flag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement