zoukankan      html  css  js  c++  java
  • 【python密码学编程】6.凯撒加密法

    凯撒加密法的密钥是0~25的整数

    # _*_ coding:utf-8 _*_
    #Caeser Ciper
    import pyperclip
    messgae = 'this is my secret messgae.'
    key = 13
    mode = 'encrypt'    #模式是加密而非解密(decrypt)
    LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'    #常量要大写
    translated = ''
    messgae = messgae.upper()
    for symbol in messgae:
        if symbol in LETTERS:
            num = LETTERS.find(symbol)    #find()返回的是该字符在字符串中的位置
    
            if mode == 'encrypt':#判断当前是加密还是解密过程
                num = num+key
            elif mode == 'decrypt':
                num = num-key
    
            if num > len(LETTERS):#当处理后的数字脱离26个字母的数字范围后的处理
                num = num - len(LETTERS)
            elif num < 0:
                num = num + len(LETTERS)
    
            translated = translated + LETTERS[num]#空字符串一个个加上翻译后得到的字符
    
        else:
            #如果要翻译的字符不在26个大写字母的范围内
            translated =translated + symbol
    
    print translated
    pyperclip.copy(translated)
    >>>
    GUVF VF ZL FRPERG ZRFFTNR.
    [Finished in 0.8s]

       仅允许非商业转载,转载请注明出处

  • 相关阅读:
    Bluetooth GATT介绍
    Bluetooth ATT介绍
    Bluetooth GAP介绍
    Bluetooth Low Energy介绍
    CC2540介绍
    DBus介绍
    802.11 MAC层
    802.11介绍
    Python资料
    Bluedroid之GKI
  • 原文地址:https://www.cnblogs.com/Archimedes/p/7064336.html
Copyright © 2011-2022 走看看