Login
Immutable PageDiscussionInfoAttachments
ytoku/CTF/Writeup/AdventCalendarCTF2014/2014-12-07

MMA

reader

問題

Read 10 times.

nc adctf2014.katsudon.org 43010

メモ

解法

バーコードらしきものが与えられる。 出現する文字は4種類 "▌"(\u258c), "█"(\u2588), "▐"(\u2590), " "(\x20)である。 それぞれ,[1, 0], [1, 1], [0, 1], [0]として扱う。

合う規格を探したところCode-93が合致した。 以下のコードで解いた。

   1 import socket
   2 
   3 table = {
   4 "100010100": "0",
   5 "101001000": "1",
   6 "101000100": "2",
   7 "101000010": "3",
   8 "100101000": "4",
   9 "100100100": "5",
  10 "100100010": "6",
  11 "101010000": "7",
  12 "100010010": "8",
  13 "100001010": "9",
  14 "110101000": "A",
  15 "110100100": "B",
  16 "110100010": "C",
  17 "110010100": "D",
  18 "110010010": "E",
  19 "110001010": "F",
  20 "101101000": "G",
  21 "101100100": "H",
  22 "101100010": "I",
  23 "100110100": "J",
  24 "100011010": "K",
  25 "101011000": "L",
  26 "101001100": "M",
  27 "101000110": "N",
  28 "100101100": "O",
  29 "100010110": "P",
  30 "110110100": "Q",
  31 "110110010": "R",
  32 "110101100": "S",
  33 "110100110": "T",
  34 "110010110": "U",
  35 "110011010": "V",
  36 "101101100": "W",
  37 "101100110": "X",
  38 "100110110": "Y",
  39 "100111010": "Z",
  40 "100101110": "-",
  41 "111010100": ".",
  42 "111010010": " ",
  43 "111001010": "$",
  44 "101101110": "/",
  45 "101110110": "+",
  46 "110101110": "%",
  47 "100100110": "($)",
  48 "111011010": "(%)",
  49 "111010110": "(/)",
  50 "100110010": "(+)",
  51 "101011110": "Start/Stop",
  52 }
  53 
  54 def char2bar(c):
  55     if c == u'\u258c':
  56         return [1, 0]
  57     elif c == u'\u2588':
  58         return [1, 1]
  59     elif c == u'\u2590':
  60         return [0, 1]
  61     elif c == ' ':
  62         return [0]
  63     else:
  64         raise Exception("Unknown Character")
  65 
  66 
  67 s = socket.create_connection(("adctf2014.katsudon.org", 43010))
  68 f = s.makefile()
  69 
  70 for j in range(10):
  71     la = f.readline()[:-1]
  72     print la
  73     if la == "wrong":
  74         exit(1)
  75     l = la.decode("utf-8")
  76     b = sum(map(char2bar, l), [])
  77     s = []
  78     for i in range(0, len(b), 9):
  79         k = "".join(map(str, b[i:i+9]))
  80         if len(k) < 9: break
  81         if table[k] == "Start/Stop": continue
  82         s.append(table[k])
  83     print s
  84     f.write("".join(s[:-2]) + "\n")
  85     f.flush()
  86     
  87 print f.readline()

ytoku/CTF/Writeup/AdventCalendarCTF2014/2014-12-07 (last edited 2014-12-08 04:45:07 by ytoku)