码迷,mamicode.com
首页 > 编程语言 > 详细

Python 栅栏凯撒

时间:2016-04-28 16:58:22      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

def fence_Crypto(msg,priority="row"):
    ‘‘‘
    usage:
        fence_Crypto(msg[, priority])->msg to encrypt or decrypt with fence crypto
    args:
        msg:
            a plaintext which will be crypted or a ciphertext which will be decrypted
        priority:
            row priority or column priority,default is the former
    return:
        result:
            if msg is plaintext,it contains all of possible ciphertext.
            if msg is ciphertext,it contains all of possible plaintext
    ‘‘‘
    msg_len = len(msg)
    row_num = 1
    result = []
    if priority == "row":        
        while row_num<=msg_len:    
            temp = [msg[block_num::row_num] for block_num in xrange(row_num)]
            result.append("".join(temp))
            row_num += 1
        return result
    elif priority == "columns":
        pass
    else:
        print "parameter error!please help(fence_Crypto)"

 

 

def caesar_Crypto(msg):
    ‘‘‘
    usage:
        caesar_Crypto(msg) ---> to encrypt or decrypt the msg with caesar crypto
    ‘‘‘
    lowercase = abcdefghijklmnopqrstuvwxyz
    uppercase = ABCDEFGHIJKLMNOPQRSTUVWXYZ
    result = []
    offset = 1
    while offset<=26:        
        temp = []
        for char in msg:
            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
    #return result

 

Python 栅栏凯撒

标签:

原文地址:http://www.cnblogs.com/test404/p/5443215.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!