Saturday, April 5, 2014

Nuit Du Hack Quals CTF Writeup 2014 :: Crypto 50 - "Carbonara"


This challenge was solved with a mix of luck and a quick jump into the waters. The initial instinct was to start by transposing the characters in the cipher. This was the first attempt made:

for n in range(20): print ''.join([chr(ord(c) + n) for c in cipher])

One of the lines found was this (BINGO!):
4HE/FLAG/FOR/THIS/CHAL/IS/x`ЄMPERATOR/ЄULIUS/ЂAESAR/ѓIVUS`l

But this wasn't it, we obviously need to comb over this a few more times to get it to it's clean state.
Next up was to take every character and check in the string library to see if it was printable.
If it wasn't, let's shift it some more! :)
After playing around manually with the characters left, and subtracting the value with what we know as one of the characters, this yielded the result of the offset.
>>> ugly = ''.join([chr(ord(c)+47) for c in cypher])
TheOflagOforOthisOchalOisOўђДmperatorOДuliusOАaesarOбivusђї
>>> print {i:chr(ord(c)+47) for i, c in enumerate(cypher)}
{0: 'T', 1: 'h', 2: 'e', 3: 'O', 4: 'f', 5: 'l', 6: 'a', 7: 'g', 8: 'O', 9: 'f', 10: 'o', 11: 'r', 12: 'O', 13: 't', 14: 'h', 15: 'i', 16: 's', 17: 'O', 18: 'c', 19: 'h', 20: 'a', 21: 'l', 22: 'O', 23: 'i', 24: 's', 25: 'O', 26: '\x98', 27: '\x80', 28: '\xa7', 29: 'm', 30: 'p', 31: 'e', 32: 'r', 33: 'a', 34: 't', 35: 'o', 36: 'r', 37: 'O', 38: '\xa7', 39: 'u', 40: 'l', 41: 'i', 42: 'u', 43: 's', 44: 'O', 45: '\xa1', 46: 'a', 47: 'e', 48: 's', 49: 'a', 50: 'r', 51: 'O', 52: '\xa2', 53: 'i', 54: 'v', 55: 'u', 56: 's', 57: '\x80', 58: '\x8c'}
'Caesar' seemed like a prettty good keyword to go for, so let's see what our resulting shift is:
>>>0xa1 - ord('C')
94
Now we have our lowercase shift & uppercase shift!

Ideally we should roll around in the shift space (@TODO), instead in this solution it was caught by checking string.printable and multiplying the shift towards the other direction.
This gives us the resulting Flag:
The flag for this chal is :"Imperator Iulius Caesar Divus".

Included below is the formalized final result: