描述:对输入的字符串进行加解密,并输出。
加密方法为:当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a;当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0;其他字符不做变化。解密方法为加密的逆过程。
数据范围:输入的两个字符串长度满足 1 \le n \le 1000 \1≤n≤1000 ,保证输入的字符串都是只由大小写字母或者数字组成
输入描述:第一行输入一串要加密的密码 第二行输入一串加过密的密码
输出描述:第一行输出加密后的字符 第二行输出解密后的字符
输入:
abcdefg
BCDEFGH
输出:
BCDEFGH
abcdefg
# print(ord('A'),ord('Z'),ord('a'),ord('z'))
# 65 90 97 122
def addSercet(stra):
sa=stra
# print('add: ',sa)
num = [str(i) for i in range(0,10)]
big = [ chr(i) for i in range(65,91)]
low = [ chr(i).lower() for i in range(65,91)]
# print(num,big,low)
res = ''
for i in sa:
# 不在0-9数字/不在大小写字母,则直接加字符
if i not in num and i not in big and i not in low:
res += i
# 在0-8之间值,则转数字后+1后转str
if i in num and int(i) != 9:
temp = str(int(i)+1)
res += temp
if i == '9':
res += '0'
# 字符为大写字母,且+1才为Z,则+1后转小写
if 65 <= ord(i) < 90 and ord(i)+1 <= 90:
temp = chr(ord(i)+1)
res += temp.lower()
# 字符为小写字母,且+1才为z,则+1后转大写
if 97 <= ord(i) < 122 and ord(i)+1 <= 122:
temp = chr(ord(i)+1)
res += temp.upper()
if i == 'Z':
res += 'a'
if i == 'z':
res += 'A'
print(res)
def minSercet(strb):
sb=strb
res = ''
num = [str(i) for i in range(0,10)]
big = [ chr(i) for i in range(65,91)]
low = [ chr(i).lower() for i in range(65,91)]
for i in sb:
if i not in num and i not in big and i not in low:
res += i
if i in num and i != '0':
temp = str(int(i)-1)
res += temp
if i == '0':
res += '9'
# 解密过程为减去1,则要保证减去1的值仍然最小为a或A,方便下面为A换z和a换Z
if 65 < ord(i) <= 90 and ord(i)-1 >= 65:
temp = chr(ord(i)-1)
res += temp.lower()
if 97 < ord(i) <= 122 and ord(i)-1 >= 97:
temp = chr(ord(i)-1)
res += temp.upper()
if i == 'A':
res += 'z'
if i == 'a':
res += 'Z'
print(res)
stra = input().strip()
strb = input().strip()
addSercet(stra=stra)
minSercet(strb=strb)