Verticode90 points  Solved 126 times  Cryptography  Arun Dunna

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:

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}.

問題文に書かれていることを整理します。まず、黒がビット1、白がビット0を表します。したがって、下の画像は1000001=0x41=A、1000010=0x42=B、1000011=0x43=C、となり、ABCを表します。

A-Code


次の画像は、元の値(文字コード)に、左側の色ごとに決められた数値を加算して、白黒のビット化をしています。紫は+1加算、赤は0加算(そのまま)です。したがって、ABCがそれぞれ紫赤紫により、紫A=1000001+1=1000010、赤B=1000010+0=1000010、紫C=1000011+1=1000100になります。


B-Code

それでは、問題文の内容をRubyプログラムで書いてみます。

require "RMagick"
include Magick

def get_rgb_arry(file)
  img = ImageList.new(file)
  str = ""
  for y in 0...img.rows/12
    ch = 0
    color = img.pixel_color(0, y * 12)         #色を取得
    if color.red == 65535 and color.green == 0 and color.blue == 0 then
      add = 0   #赤
    elsif color.red == 32896 and color.green == 0 and color.blue == 32896 then
      add = 1   #紫
    elsif color.red == 0 and color.green == 0 and color.blue == 65535 then
      add = 2   #青
    elsif color.red == 0 and color.green == 32896 and color.blue == 0 then
      add = 3   #緑
    elsif color.red == 65535 and color.green == 65535 and color.blue == 0 then
      add = 4   #黄
    elsif color.red == 65535 and color.green == 42405 and color.blue == 0 then
      add = 5   #橙
    else
      p color.red
      p color.green
      p color.blue
    end
    for x in 0..6
      src = img.pixel_color(7 * 12 + x * 12, y * 12)      #文字を取得
      ch = ch << 1
      if src.red == 0 then
        ch += 1
      end
    end
    str = str + (ch - add).chr
  end
  return str
end

pic1 = "code1.png"
print get_rgb_arry(pic1)

これを実行すると、下記の文字列を得ることができます。

JoeLopowasamanofmildtemperamentshortstatureandhadthegoaltobecometheworldsfastesttelephoneeaterThoughLoponeverknewevenbasicphysicshecreatedatelescopecapableofsightingthesmallesthaironanalienwholivedquiteafewlightyearsawayJoeLopoquicklydestroyedalargeboulderandusedtheshatteredremainstoformeightsmallstatuesthatstronglyresembledtinycreaturesbeingorrelatedtothewaterfleaHeplacedtheminacircularpatterntoformasortofshrineandplacedthetelescopeinthemiddleofitHethenchanneledthepowerofthestonewaterfleasintothetelescopetoviewthepoweroftheheavensHewasinatrancewiththebeautyofthemysteriousdimensionanddidntevennoticetheverylargetornadoheadingtowardhimTheshrinewasquicklydemolishedandtheimmediatewithdrawlofpowersentJoeLobointoalairofpitchblacknessfoundtobeaparalleldimensionthatcausABCiamtheflagalllowercasenojokeDEFanyonewhosefirstnamebeganwithJalongwithMLandQtobecomeratheruncomfortableJoewasalsosuddenlyintroducedtoundroclamaticolomphasisciousytheeccentrictapewormwithastrongmorrocanaccentImundroclamaticolomphasisciousytheeccentrictapewormIlikepizzasohowareyadoinIhavenoideasaidJoe

flagで検索するとABC~DEFで囲まれた部分がヒットします。これをフラグの形式にしてsubmitすると正解でした。
よって、フラグは、

sctf{iamtheflagalllowercasenojoke}

です。