input = list("Poiktum_esach_u")
key = "ABASLATEAMROCKET"

input = list("onsauoramat_dsilno___r_,rela.itd__eestnmuec")
key = "CestevidemmentduruniquedisaitleprofesseurenfroncantlesourcilMaisilyaunsecretetjeledécouvriraisinon"

plain = list()

key = key[:len(input)].upper()
offset = -1
for c in key:
    decalage = ord(c) - ord('A') + 1
    print("".join(input), c, decalage, offset, end=" ")
    while decalage > 0:
        offset += 1
        if offset > len(input)-1:
            offset = 0
        if offset < 0:
            offset = len(input)-1
        if input[offset] != "#":
            decalage -= 1
    print(offset, input[offset], "==>", end=" ")
    plain.append(input[offset])
    input[offset] = "#"
    print("".join(plain))

print("".join(plain))
