python caser运行编码

python caser运行编码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os


def encryption():
str_raw = raw_input("请输入明文:")
k = int(raw_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 = raw_input("请输入密文:")
k = int(raw_input("请输入位移值:"))
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))

while True:
print (u"1. 加密")
print (u"2. 解密")
choice = raw_input("请选择:")
if choice == "1":
encryption()
elif choice == "2":
decryption()
else:
print (u"您的输入有误!")

posted on 2018-11-18 21:40  朝远 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/Taolinbies666/p/9979677.html

你可能感兴趣的:(python caser运行编码)