1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ksnctf #22 Square Cipher

Posted at

#Square Cipher

a-z,A-Zのテキストが31×31で書かれている。

大文字を黒、小文字を白と置き換えて画像を作って見る。

  1. まず大文字を1、小文字を0と置き換える。
  2. 与えられたテキストを1次元から2次元に変換する
  3. OpenCVを使って、1を黒、0を白で置き換えて画像を作る
import cv2
import numpy as np

#1次元→2次元
def convert_1d_to_2d(l, cols):
    return [l[i:i + cols] for i in range(0, len(l), cols)]

text = '''oomktvziqtaovmmpxzoqrzsxlpwpgoj
uDQEMISYnnVYnvyWRhHsDXnSCXAVVZj
tZbknedErdpvAwQWpUiLqOxIqpafvXp
dXoAVWcKppbEPuaqmXWjXJwRoRFOoEg
pDiRUXlQjKJlslskVpGwtljGyVJPxHv
bQsQNKxCsdYMdQPJiBmyrsuOrJQOtXg
pMekeinUaMoDXqFzweLKipkBuggnsUv
eQFYCJSKfBgHaJgZnZoWmOmAOJLVQHi
hljrplajyKNXtwmfOjRwOqcqeeplyzy
gkFOltsOyrPgIaerIaSjQQaVMyEhfyd
vEaRHbBzfrcwJbCZmHdddLpuEJwspbt
sXQGkwpKaTZmWJiZzpbkpHNiToawxKn
wJpIKbGhnLjVAJNcxrqkKEJCKCOocSv
mTRDNDpFtRUmcHoRELeSqXoGUIIsuYu
ajeHaSVlQGLaEprSQarDzTomJdAWfqb
zIJLHRBXMvNDegYeaoVRDuWBbdSBtLv
xIeKdAYwajGHMgRLDGgDinBiLNBgatb
kHepNsCQSJjTRmQrCHYWJqIPOVAUOer
rvhmZfmogPglGNuLyAuSivBctlvVfzb
qBJdHUkSaTArlgkhtHPyGhXOPkwmkBq
rvbzZfwvLtTnhyXVHPlwsuGZQnNiNcm
yCMtAVwYVgtZHVNznolGMBETIHFmoWj
wfezbysbvOzsAhxSZFFAfOouyHldEYh
gNHKKSFUtcUxfRyXHMugYBtAxBwDJZh
rHmsozuNeoJqyzMDHsNbUDwzaNLtdxr
bVmQMHyNndOWCZLnhrPxZXCYLDTWQre
aSiEEJjZtoRpUzgsxsiiGzvnRpKLMrk
qTzGCKvNhUhjrmCjAdwQAvkgqHyJZLm
sSxzwjxAnWesTszIxirRwcWIXUPtwwa
nTDEMTRGyhzdCtkTTDWbxdSjsNYlfXz
eawtidzosgaofjxxyfcdoiulemirqap
'''

#大文字を1、小文字を0
bin_list=[]
for char in text:
    if(char.isupper()):
        bin_list.append(1)
    elif(char.islower()):
        bin_list.append(0)

#1次元→2次元
bin_list_2d = convert_1d_to_2d(bin_list, 31)

#1を黒、0を白で画像作成
img = np.full((50, 50, 3), 128, dtype=np.uint8)
for i in range (31):
    for j in range (31):
        if(bin_list_2d[i][j]==1):
            cv2.rectangle(img, (i, j), (i+1,j+1), (255,255,255), thickness=-1)
        elif(bin_list_2d[i][j]==0):
            cv2.rectangle(img, (i, j), (i+1,j+1), 0, thickness=-1)
            
cv2.imwrite('q21_QRcode.png', img)

得られたQRコードを読み取るとFLAGが得られた。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?