从打CTF某人博客上偷来的脚本。

#coding=utf-8

from prettytable import PrettyTable

########## 01-栅栏 ##########
def x01(e,key):
    elen = len(e)
    field=[]
    for i in range(1,elen):
        if elen%i==0:
            field.append(i)
    for f in field:
        b = elen / f
        result = {x:'' for x in range(b)}
          for i in range(elen):
            a = i % b
            result.update({a:result[a] + e[i]})
           d = ''
          for i in range(b):
                d = d + result[i]
        print 'Columnar '+str(f)+' --- '+d

########## 02-凯撒 ##########

def x02(s,key):
    lowercase = 'abcdefghijklmnopqrstuvwxyz'
    uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    result = []
    offset = 1
    while offset<=26:
        temp = []
        for char in s:
            if char in lowercase:
                temp.append(chr(97 + (ord(char) - 97 + offset) % 26))
            elif char in uppercase:
                temp.append(chr(65 + (ord(char) - 65 + offset) % 26))
            else:
                temp.append(char)
        string = "".join(temp)
        print "Offset %d --- "%offset,string
        result.append(string)
        offset += 1

########## 03-Base64 ##########

def x03(s,key):
    import base64
    print base64.b64decode(s)

########## 04-rot13 ##########

def x04(s,key):
    print s.encode('rot_13')

########## 05-Manchester ##########

def x05(s,key):
    r = ''
    for i in xrange(len(s)/2):
        c = s[i*2:i*2+2]
        if c == '01':
            r += '1'
        else:
            r += '0'
    print r

########## 06-Bacon ##########

def x06(s,key):
        Bacon = []
        for i in range(26):
                Bacon.append(str('{:0>5}'.format(bin(i).split('0b')[1])).replace('0','A').replace('1','B'))
        result = ''.join([chr(Bacon.index(s[i:i+5])+97) for i in range(0,len(s)-4,5)])
        print result

########## 07-Morse ##########

def x07(s,key):
        Morse= {'A': '.-',     'B': '-...',   'C': '-.-.',
                'D': '-..',    'E': '.',      'F': '..-.',
                'G': '--.',    'H': '....',   'I': '..',
                'J': '.---',   'K': '-.-',    'L': '.-..',
                'M': '--',     'N': '-.',     'O': '---',
                'P': '.--.',   'Q': '--.-',   'R': '.-.',
                'S': '...',    'T': '-',      'U': '..-',
                'V': '...-',   'W': '.--',    'X': '-..-',
                'Y': '-.--',   'Z': '--..',

                '0': '-----',  '1': '.----',  '2': '..---',
                '3': '...--',  '4': '....-',  '5': '.....',
                '6': '-....',  '7': '--...',  '8': '---..',
                '9': '----.'}
        result = ''
        for i in s.split(' '):
                for j in Morse:
                        if Morse[j] == i:
                                result += j
        print result

########## 08-维吉尼亚 ##########

def x08(s,key):
    import string
    i=0
    list2=[]
    while i<26:
        str2=s[i:i+8]
        i+=8
        list2.append(str2)
    list1=[]
    for i in string.uppercase:
        list1.append(i)
    str4=''
    for i in list2:
        for j in range(len(i)):
            for k in range(len(list1)):
                if  i[j]==list1[k]:
                    for m in range(len(list1)):
                        if key[j]==list1[m]:
                            str4+=list1[(m+k)%26]
    print str4


#############################################
if __name__ == '__main__':
        x = PrettyTable(['Id','Decrypt Method'])
        Method = ['Columnar','Caesar','Base64','Rot13','Manchester','Bacon','Morse','Vigenere']
        Id = map(lambda x:'0'+str(x) if len(str(x))==1 else str(x),xrange(1,len(Method)+1))
        for i,j in zip(Id,Method):
                x.add_row([i,j])
        print x
        a = raw_input('I need :  ')
        s = raw_input('The clear text : \n')
        key = raw_input('The key is :                      #if null, pass\n')
        print 'The cipher text :'
        eval('x'+str(a)+'('+'s'+','+'key'+')')

http://amyang.xyz/?p=161

页面下部广告

2 对 “A Decrypt Python Tool”的想法;

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*

鲁ICP备17018668号-1