Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- flag = "e4f4f4e4644534f56733e6b763f5273343e6e603671363f50397f5330757f55733e6f512f5273367e6e6036333c6f5430397f5730346f557d712e677"
- def encrypt(flag):
- bytes = []
- # flip individual bytes
- for b in flag:
- bb = hex(ord(b)).split("x")[1]
- bytes.append(bb[1] + bb[0])
- print(bytes)
- for b in range(math.floor(len(bytes)/2)):
- byte = b * 2
- t = bytes[byte+1]
- bytes[byte+1] = bytes[byte]
- bytes[byte] = t
- # swap neighboring byte pairs
- for b in range(math.floor(len(bytes)/4)):
- byte = b * 4
- t = bytes[byte]
- t2 = bytes[byte+1]
- bytes[byte] = bytes[byte+2]
- bytes[byte+1] = bytes[byte+3]
- bytes[byte+2] = t
- bytes[byte+3] = t2
- return "".join([str(e) for e in bytes])
- def decrypt(encrypted_string):
- bytes = [encrypted_string[i:i+2] for i in range(0, len(encrypted_string), 2)]
- # Reverse the operations done in encryption
- for b in range(math.floor(len(bytes)/4)):
- byte = b * 4
- t = bytes[byte]
- bytes[byte] = bytes[byte+2]
- bytes[byte+2] = t
- t2 = bytes[byte+1]
- bytes[byte+1] = bytes[byte+3]
- bytes[byte+3] = t2
- for b in range(math.floor(len(bytes)/2)):
- byte = b * 2
- t = bytes[byte]
- bytes[byte] = bytes[byte+1]
- bytes[byte+1] = t
- decrypted = "".join([chr(int(e[1] + e[0], 16)) for e in bytes])
- return decrypted
- decrypted_flag = decrypt(flag)
- print("Decrypted:", decrypted_flag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement