Tuesday, April 19, 2016

SCTF 2016 Q - Verticode (Crypto)


SCTF  2016 Q

Welcome to Verticode, the new method of translating text into vertical codes.
Each verticode has two parts: the color shift and the code.
The code takes the inputted character and translates it into an ASCII code, and then into binary, then puts that into an image in which each black pixel represents a 1 and each white pixel represents a 0.
For example, A is 65 which is 1000001 in binary, B is 66 which is 1000010, and C is 67 which is 1000011, so the corresponding verticode would look like this.
Except, it isn't that simple.
A color shift is also integrated, which means that the color before each verticode shifts the ASCII code, by adding the number that the color corresponds to, before translating it into binary. In that case, the previous verticode could also look like this.
The table for the color codes is:
Value Color
0 Red
1 Purple
2 Blue
3 Green
4 Yellow
5 Orange
This means that a red color shift for the letter A, which is 65 + 0 = 65, would translate into 1000001 in binary; however, a green color shift for the letter A, which is 65 + 3 = 68, would translate into 1000100 in binary.
Given this verticode, read the verticode into text and find the flag.
Note that the flag will not be in the typical sctf{flag} format, but will be painfully obvious text. Once you find this text, you will submit it in the sctf{text} format. So, if the text you find is adunnaisawesome, you will submit it as sctf{adunnaisawesome}.



Python script to decode the image :

import Image
def open_image(path):
    im = Image.open(path)
    im = im.convert('RGB')
    return im
im = open_image("code1.png")
def decode_line(j):
    row1 = [im.getpixel((i,j)) for i in range(im.size[0]/2)]
    row2 = [im.getpixel((i,j)) for i in range(im.size[0]/2,im.size[0])]
    row1 = row1 [::12]
    row2 = row2 [::12]
    for i in range(len(row2)):
        if row2[i] == (0,0,0):
            row2[i]= 1
        if row2[i] == (255,255,255):
            row2[i]= 0

    bincode   = ''.join([str(item) for item in row2])
    table_color = [(255,0,0),(128,0,128),(0,0,255),(0,128,0),(255,255,0),(255,165,0)]
    position = table_color.index(row1[0])
    decoded = chr(int(bincode, 2) - position )
    return decoded

flag=''

for j in range(0,im.size[1],12):
    flag += str(decode_line(j))
print flag 

JoeLopowasamanofmildtemperamentshortstatureandhadthegoaltobecometheworldsfastesttelephonee
aterThoughLoponeverknewevenbasicphysicshecreatedatelescopecapableofsightingthesmallesthair
onanalienwholivedquiteafewlightyearsawayJoeLopoquicklydestroyedalargeboulderandusedtheshat
teredremainstoformeightsmallstatuesthatstronglyresembledtinycreaturesbeingorrelatedtothewa
terfleaHeplacedtheminacircularpatterntoformasortofshrineandplacedthetelescopeinthemiddleof
itHethenchanneledthepowerofthestonewaterfleasintothetelescopetoviewthepoweroftheheavensHew
asinatrancewiththebeautyofthemysteriousdimensionanddidntevennoticetheverylargetornadoheadi
ngtowardhimTheshrinewasquicklydemolishedandtheimmediatewithdrawlofpowersentJoeLobointoalai
rofpitchblacknessfoundtobeaparalleldimensionthatcausABCiamtheflagalllowercasenojokeDEFanyo
newhosefirstnamebeganwithJalongwithMLandQtobecomeratheruncomfortableJoewasalsosuddenlyintr
oducedtoundroclamaticolomphasisciousytheeccentrictapewormwithastrongmorrocanaccentImundroc
lamaticolomphasisciousytheeccentrictapewormIlikepizzasohowareyadoinIhavenoideasaidJoe

flag is :  sctf{iamtheflagalllowercasenojoke}


No comments:

Post a Comment