ctf密码学(4)_rail_fence

ctf密码学(4)_rail_fence

#coding:utf-8
#栅栏  余数,栏数

s = 'ccehgyaefnpeoobe{lcirg}epriec_ora_g'

def decrypt(strs):
    lists = []
    for i in strs:
        lists.append(i)

    fact = []
    for i in range(2, len(lists)):
        if len(lists) % i == 0:
            fact.append(i)

    out_list = []
    for i in fact:
        tmp_list = [['' for x in range(int(len(lists) / i))] for y in range(i)]

        block = int(len(lists) / i)
        block2 = block
        c = 1
        while c <= i:
            for j in range(block2):
                tmp_list[c - 1][j] = lists[j + (c - 1) * block]
            c += 1

        #print(tmp_list)
        column = 0
        while column < len(tmp_list[0]):
            for row in range(len(tmp_list)):
                out_list.append(tmp_list[row][column])
            column += 1
        out_list.append('\n')
        print(''.join(out_list))

if __name__ == '__main__':
    decrypt(s)

上一篇:CF Gym 101955C Insertion Sort


下一篇:7-10 求组合数 (15 分) PTA