python编程

提问:python编程

若字符串“He is in Beijing XYZ”为明文,请给出其密文,反之若其为密文,请给出其明文?加密规则为:大小写字符首尾相连,并往后移5个字符。解密规则与加密规则相反。

网友回答:

完整的程序参考

#coding:utf-8
def encode(str):
   strn=''
   for c in str:
       if c.isupper():
           d=ord(c)+5-ord('A')
           if d>=26:
               d-=26
           strn+=chr(d+ord('A'))  
       elif c.islower():
           d=ord(c)+5-ord('a')
           if d>=26:
              d-=26
           strn+=chr(d+ord('a'))  
       else:
           strn+=c        
   return strn        
def decode(str):
   strn=''
   for c in str:
       if c.isupper():
           d=ord(c)-5-ord('A')
           if d<0:
               d+=26
           strn+=chr(d+ord('A'))  
       elif c.islower():
           d=ord(c)-5-ord('a')
           if d<0:
              d+=26
           strn+=chr(d+ord('a'))  
       else:
           strn+=c        
   return strn            
##测试
s=encode("He is in Beijing XYZ")
print(s)
s1=decode(s)
print(s1)

相关推荐

python编程

python编程

python编程:随机生成含有100个整数元素的数组,任意设置一个值,线性检索其是否在数组中

python编程:随机生成含有100个整数元素的数组,任意设置一个值,线性检索其是否在数组中

青少年编程python等级考试 考过1级后可以直接报3级吗

青少年编程python等级考试 考过1级后可以直接报3级吗

决战坦克是用什么编程的(java?c?c++?python?)

决战坦克是用什么编程的(java?c?c++?python?)

python问题

python问题

python问题

python问题

python制作

python制作

python问题

python问题

python相关问题

python相关问题

Python for循环

Python for循环

使用python编写

使用python编写

python找出500以内的所有质数

python找出500以内的所有质数

Python tkinter按钮怎么设置位置?

Python tkinter按钮怎么设置位置?

python代码如何转换成C语言代码?代码如下:

python代码如何转换成C语言代码?代码如下:

Python安装pyecharts后 测试不显示图表

Python安装pyecharts后 测试不显示图表

盒子游戏,游戏玩家专属个性阅读社区


©CopyRight 2010- 2020 BOXUU.COM Inc All Rights Reserved

鄂公网安备 35020302000061号- 鄂ICP备2020015574号-1