题目
思路:
值得注意的测试点是:
对于固定加密用正整数A长度长于要加密的对象B时,需要对B进行相应的补零操作
当固定加密用正整数A长度小于要加密的对象B时,直接保留B长出的字符片段
代码
alpha={10:'J',11:'Q',12:'K'}
key_,password=input().split(' ')
strat=len(password)-len(key_)
if strat<0: #当要加密的数字串没有固定密钥的长度时,需要进行补零操作再运算
password='0'*abs(strat)+password
strat=0
ji_or_ou=1
result_=password[0:strat] #当要加密的数字串长于固定密钥的长度时,直接保留原密文
for i in range(len(password)-1,strat-1,-1):
if ji_or_ou==1: #奇数位时
temp=(int(password[i]) + int(key_[i - strat]))%13
if temp>9:
temp=alpha[temp]
result_=result_[0:strat]+str(temp)+result_[strat:]
ji_or_ou=-ji_or_ou
else: #偶数位时
temp = int(password[i] )-int(key_[i - strat])
if temp < 0:
temp =temp+10
result_=result_[0:strat]+str(temp)+result_[strat:]
ji_or_ou = -ji_or_ou
print(result_)