15

【Root-Me】 Shift cipher

 2 years ago
source link: https://exp-blog.com/safe/ctf/rootme/cryptanalysis/shift-cipher/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【Root-Me】 Shift cipher



水题,题目就是提示,位移加密(其实就是凯撒加密)。

点击挑战后下载了一个 ch7.bin 文件,文件内容是乱码。

考虑到凯撒加密的特性,尝试对文件内容的每个字符的 ASCII 码做偏移,偏移范围从 -256 枚举到 +256

简单写了一段 python 代码实现,于是在偏移值为 -10 的时候,还原出了明文,得到密码,完成挑战。

代码比较简单,贴在下面:

python
#!/usr/bin/python
# -*- coding: UTF-8 -*-

# ch7.bin 的文件内容
ch7_bin = 'L|k€y+*^*zo‚*€kvsno|*k€om*vo*zk}}*cyvksr'

for offset in range(1, 256) :

    # ASCII码负向偏移
    try :
        pwd = ''
        for c in ch7_bin : 
            cn = chr(ord(c) - offset)
            pwd += cn
        print('offset=-%i, pwd=%s' % (offset, pwd))

    except Exception :
        pass # ascii overflow


    # ASCII码正向偏移
    try :
        pwd = ''
        for c in ch7_bin : 
            cp = chr(ord(c) + offset)
            pwd += cp
        print('offset=+%i, pwd=%s' % (offset, pwd))

    except Exception :
        pass # ascii overflow
01.png

flag 下载后的 flagzip 的文件需要手动更改后缀为 *.zip,然后解压即可(为了避免直接刷答案)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK