Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Last active February 22, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan2904/9e92cf559be94ded4f3d to your computer and use it in GitHub Desktop.
Save stefan2904/9e92cf559be94ded4f3d to your computer and use it in GitHub Desktop.
Crypto-Pirat, Internetwache CTF crypto50 challenge. Writeup: http://losfuzzys.github.io/writeup/2016/02/21/iwctf2016-crypto-pirat/
♆♀♇♀♆ ♇♇♀♆⊕ ♇♀♇♀♆ ♇♆♇♆⊕ ♆♇♆♇♇ ♀♆♇♆⊕ ♆♇♆♇♆ ♇♆♇♆⊕ ♆♇♇♀♇ ♀♆⊕♇♀ ♆⊕♇♀♆ ⊕♆♇♆♇ ♇♀♆♇♆ ⊕♇♀♇♀ ♆⊕♆♇♆ ♇♆♇♇♀ ♆⊕♆♇♆ ♇♆♇♆⊕ ♆♇♆♇♆ ♇♆⊕♇♀ ♆♇♇♀♆ ♇♆⊕♇♀ ♆♇♆♇♇ ♀♆⊕♆♇ ♆♇♇♀♇ ♀♇♀♆⊕ ♆♇♆♇♇ ♀♆⊕♇♀ ♇♀♆♇♆ ⊕♆♇♇♀ ♆⊕♇♀♆ ♇♇♀♇♀ ♆⊕♆♇♆ ♇♆♇♆♇ ♆⊕♇♀♆ ♇♇♀♆♇ ♆⊕♇♀♆ ♇♆♇♇♀ ♆⊕♆♇♆ ♇♇♀♇♀ ♇♀♆⊕♇ ♀♆♇♆♇ ♆⊕♇♀♇ ♀♇♀♆⊕ ♇♀♇♀♆ ♇♆♇♆⊕ ♆♇♆♇♆ ♇♆⊕♆♇ ♇♀♇♀♆ ⊕♆♇♆♇ ♆♇♆♇♇ ♀♆⊕♇♀ ♇♀♆♇♆ ♇♆⊕♆♇ ♆♇♆♇♇ ♀♇♀♆⊕ ♆♇♆♇♆ ♇♆⊕♆♇ ♇♀♆♇♆ ♇♆⊕♆♇ ♆♇♆♇♆ ♇♆♇♆⊕ ♆♇♇♀♇ ♀♆⊕♇♀ ♇♀♆♇♆ ⊕♆♇♆⊕ ♆♇♆♇♇ ♀♇♀♇♀ ♆⊕♇♀♆ ♇♇♀♆♇ ♆⊕♇♀♇ ♀♆♇♆♇ ♆♇♆⊕♇ ♀♆♇♆⊕ ♇♀♇♀♆ ♇♆♇♆⊕ ♆♇♆♇♆ ♇♆⊕♇♀ ♆♇♆♇♇ ♀♆⊕♆♇ ♆⊕♇♀♇ ♀♇♀♆⊕ ♆♇♇♀♆ ♇♆⊕♆♇ ♇♀♇♀♇ ♀♆⊕♆♇ ♇♀♇♀♆ ♇♆⊕♆♇ ♆♇♇♀♆ ⊕♇♀♆♇ ♆♇♆♇♇ ♀♆⊕♇♀ ♆♇♆♇♆ ♇♇♀♆⊕ ♇♀♆♇♆ ♇♆♇♇♀ ♆⊕♇♀♆ ♇♆♇♆♇ ♇♀♆⊕♇ ♀♆♇♆♇ ♆♇♇♀♆ ⊕♇♀♆♇ ♆♇♆♇♇ ♀
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pwn import *
import morse_talk as morse
from base64 import b32decode
log.info('load the ciphertext ... ')
ciphertext = open('README.txt').read()
log.info('initialize planets and mapping ... ')
neptun = '♆' # 8
pluto = '♇' # 9
venus = '♀' # 2
earth = '⊕' # 3
mapping = {'♆': 8, '♇': 9, '♀': 2, '⊕': 3}
log.info('load the tapir table ... ')
tapir = dict()
for line in open('TAPIR.txt').read().split('\n'):
data = line.split(' ')
if len(data) <= 1:
break
tapir[data[0]] = data[1]
# control chars are not relevant, to we ignore them ... ')
blacklist = ['Zi', 'ZwR']
log.info('decode the planet mapping ...')
i = 0
group = ''
while i < len(ciphertext):
if ciphertext[i] is not ' ':
num = mapping[ciphertext[i:i + 3]]
# print(num),
i += 3
group += str(num)
else:
# print '_',
i += 1
clist = list(group)
log.info('planet-decoded plaintext:')
print group
log.info('decode the tapir mapping ...')
tapirDecoded = ''
while len(clist) > 0:
c = clist.pop(0)
if len(clist) <= 0:
break
if int(float(c)) >= 5:
c2 = clist.pop(0)
char = tapir[c + c2]
else:
char = tapir[c]
if char not in blacklist: # Control chars are not relevant
tapirDecoded += char
if char == 'ZwR': # 'Zwr' is 'Zwischenraum', needed in morse
tapirDecoded += ' '
log.info('tapir-decoded plaintext:')
print tapirDecoded
log.info('morse-decoded plaintext:')
morsecode = tapirDecoded.replace(' -...-', '')
morseDecoded = morse.decode(morsecode)
print morseDecoded
log.info('base32-decoded plaintext:')
b32decoded = b32decode(morseDecoded + '======')
print b32decoded
for caesarKey in range(1, 27):
caesarDecrypted = ''
for c in b32decoded:
if not c.isalnum():
caesarDecrypted += c
else:
offset = ord('a') if c.islower() else ord('A')
c = ord(c) - offset
c = (c + caesarKey) % 26
caesarDecrypted += chr(c + offset)
if caesarDecrypted.startswith('IW{'):
break
log.info('caesar-decrypted plaintext:')
print caesarDecrypted
pwn==1.0
pwntools==2.2.0
morse-talk==0.2
0 A
1 E
2 I
3 N
4 R
50 B
B1 BE
52 C
53 CH
54 D
55 DE
56 F
57 G
58 GE
59 H
60 J
61 K
62 L
63 M
64 O
65 _
66 _
67 P
68 Q
69 S
70 T
71 TE
72 U
73 UN
74 V
75 _
76 W
77 X
78 Y
79 Z
80 WR
81 Bu
82 Zi
83 ZwR
84 Code
85 RPT
86 _
87 _
88 _
89 .
90 :
91 ,
92 -
93 /
94 (
95 )
96 +
97 =
98 "
99 _
00 0
11 1
22 2
33 3
44 4
55 5
66 6
77 7
88 8
99 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment