MHuiG

「看庭前花开花落,望天上云卷云舒」

Caesar

# Python Caesar

Caesar.py

    #-*-coding:utf-8-*-
    import os
    def encryption():
        str_raw = input("请输入明文：")
        k = int(input("请输入位移值："))
        str_change = str_raw.lower()
        str_list = list(str_change)
        str_list_encry = str_list
        i = 0
        while i < len(str_list):
            if ord(str_list[i]) < 123-k:
                str_list_encry[i] = chr(ord(str_list[i]) + k)
            else:
                str_list_encry[i] = chr(ord(str_list[i]) + k - 26)
            i = i+1
        print ("加密结果为："+"".join(str_list_encry))

    def decryption():
        str_raw = input("请输入密文：")
        k = int(input("请输入位移值：(-1代表穷举)"))
        if k==-1:
            print("解密结果为：")
            for k in range(1,27):
                str_change = str_raw.lower()
                str_list = list(str_change)
                str_list_decry = str_list
                i = 0
                while i < len(str_list):
                    if ord(str_list[i]) >= 97+k:
                        str_list_decry[i] = chr(ord(str_list[i]) - k)
                    else:
                        str_list_decry[i] = chr(ord(str_list[i]) + 26 - k)
                    i = i+1
                print ("".join(str_list_decry))
        else:
            print("解密结果为：")
            str_change = str_raw.lower()
            str_list = list(str_change)
            str_list_decry = str_list
            i = 0
            while i < len(str_list):
                if ord(str_list[i]) >= 97+k:
                    str_list_decry[i] = chr(ord(str_list[i]) - k)
                else:
                    str_list_decry[i] = chr(ord(str_list[i]) + 26 - k)
                i = i+1
            print ("".join(str_list_decry))

    def caesar():
        print (u"1. 加密")
        print (u"2. 解密")
        choice = input("请选择：")
        if choice == "1":
            encryption()
        elif choice == "2":
            decryption()
        else:
            print (u"您的输入有误！")

    if __name__ == '__main__':
        try:
            while True:
                caesar()
        except EOFError:
            exit()

Python BinaryConversion

BinaryConversion Python BinaryConversion Binary.py#coding:utf-8import reimport argparse def ...

Python MD5

MD5 Python MD5 MD5.pyimport hashlibclass MD5: def str(): str=input() m = h...

推荐阅读
Python Baconian Mac Code Test Python ASCII 字符串 转换 Python MD5 Python RailFenceCipher Python Playfair

留言区

Notes
Cryptography
Are You A Robot?