Dynastic

Catégorie: Crypto Difficulté: very-easy Flag: HTB{DID_YOU_KNOW_ABOUT_THE_TRITHEMIUS_CIPHER?!_IT_IS_SIMILAR_TO_CAESAR_CIPHER}

Challenge

Description


You find yourself trapped inside a sealed gas chamber, and suddenly, the air is pierced by the sound of a distorted voice played through a pre-recorded tape. Through this eerie transmission, you discover that within the next 15 minutes, this very chamber will be inundated with lethal hydrogen cyanide. As the tape’s message concludes, a sudden mechanical whirring fills the chamber, followed by the ominous ticking of a clock. You realise that each beat is one step closer to death. Darkness envelops you, your right hand restrained by handcuffs, and the exit door is locked. Your situation deteriorates as you realise that both the door and the handcuffs demand the same passcode to unlock. Panic is a luxury you cannot afford; swift action is imperative. As you explore your surroundings, your trembling fingers encounter a torch. Instantly, upon flipping the switch, the chamber is bathed in a dim glow, unveiling cryptic letters etched into the walls and a disturbing image of a Roman emperor drawn in blood. Decrypting the letters will provide you the key required to unlock the locks. Use the torch wisely as its battery is almost drained out!

Analyse du code

La fonction encrypt fait tout simplement un shift de i lettre dans l’alphabet en fonction de sa position dans le texte. C’est à dire que DJF se déchiffre en DID

On doit juste inverser la fonction celui-ci en changeant :

ech = from_identity_map(chi + i)ech = from_identity_map(chi - i)

Script de résolution

def to_identity_map(a):
	return ord(a) - 0x41

def from_identity_map(a):
	return chr(a % 26 + 0x41)

def decrypt(m):
	c = ''
	for i in range(len(m)):
		ch = m[i]
		if not ch.isalpha():
			ech = ch
		else:
			chi = to_identity_map(ch)
			ech = from_identity_map(chi - i)
		c += ech
	return c

def solve():
	encrypted = "DJF_CTA_SWYH_NPDKK_MBZ_QPHTIGPMZY_KRZSQE?!_ZL_CN_PGLIMCU_YU_KJODME_RYGZXL"
	flag = "HTB{" + decrypt(encrypted) + "}"
	print(f"Flag: {flag}")

if __name__ == '__main__':
	solve()

Dernière mise à jour

Cet article vous a-t-il été utile ?