Skip to content

Instantly share code, notes, and snippets.

@GordonOus
Last active August 20, 2021 15:38
Show Gist options
  • Save GordonOus/d3e9a2e7f1882c1f59aedb50f76ec219 to your computer and use it in GitHub Desktop.
Save GordonOus/d3e9a2e7f1882c1f59aedb50f76ec219 to your computer and use it in GitHub Desktop.
from binascii import unhexlify
import math
# STEP 1 => Get the bytes of the flag
encrypted_flag = unhexlify(open('output.txt','r').read().split(' ')[1].strip('\n'))
part_flag = b'HTB{'
# STEP 2 => Get the encryption key by xoring the known string with the similar placed output bytes
key = [chr(b ^ encrypted_flag[a]) for a,b in enumerate(part_flag)]
messages = []
#STEP 3 => decrypt the flag now that we have the key
for i in range(int(len(encrypted_flag) / len(key)) + 1):
k = math.floor(len(encrypted_flag)/len(key)) * key if len(encrypted_flag) % len(key) == 0 else math.floor(len(encrypted_flag)/len(key)) * key + key[:len(encrypted_flag)%len(key)]
message = b''
size = len(key)
d = encrypted_flag[size*i:size*(i+1)]
for a,b in enumerate(d):
message += bytes(chr(b ^ ord(key[a])),'utf-8')
messages.append(message)
print(b''.join(messages))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment