【每日一题20220427】移位加密

:mage:‍ 我们今天的任务是实现一个简单的ascii加密算法,具体的要求是:给定一个纯英文的字符串,将其中的每一个字母 加上各自的索引,最终得到ascii编码表中的最新字符。

【示例】
输入:“AAAA”
输出:“AAAA”
解释:AAAA的索引分别是’0,1,2,3’,而A的ascii编号是65,所以增量后是’65,66,67,68’,对应字符为’ABCD’

题目难度:简单
题目来源:CodeWars-ASCII Shift Encryption/Decryption

def solution(src: str)-> str:
    # your code here

assert solution("AAAA") == "ABCD"
assert solution("PASSWORD") == "PBUV[TXK"
assert solution("0123456789") == "02468:<>@B"
def solution(src: str)-> str:
    # your code here
    return "".join(chr(ord(e)+i) for i, e in enumerate(src))

assert solution("AAAA") == "ABCD"
assert solution("PASSWORD") == "PBUV[TXK"
assert solution("0123456789") == "02468:<>@B"
def solution(src: str) -> str:
    # your code here

    ls = "".join([chr(ord(src[i]) + i) for i in range(len(src))])
    return ls


if __name__ == '__main__':
    assert solution("AAAA") == "ABCD"
    assert solution("PASSWORD") == "PBUV[TXK"
    assert solution("0123456789") == "02468:<>@B"
def solution(src: str)-> str:
    return "".join([chr(ord(src[i])+i) for i in range(len(src))])

assert solution("AAAA") == "ABCD"
assert solution("PASSWORD") == "PBUV[TXK"
assert solution("0123456789") == "02468:<>@B"
def solution(src: str) -> str:
    return ''.join([chr(ord(src[i]) + i) for i in range(len(src))])


assert solution("AAAA") == "ABCD"
assert solution("PASSWORD") == "PBUV[TXK"
assert solution("0123456789") == "02468:<>@B"
def solution(src: str) -> str:
    return ''.join(chr(i+ord(src[i])) for i in range(len(src)))
def solution(src: str)-> str:
    # your code here
    # l = list(src)
    # for i in range(len(l)):
    #     l[i] = chr(i + ord(l[i]))
    # return ''.join(l)

    return ''.join([chr(i + ord(list(src)[i])) for i in range(len(list(src)))])

assert solution("AAAA") == "ABCD"
assert solution("PASSWORD") == "PBUV[TXK"
assert solution("0123456789") == "02468:<>@B"
关闭