def main():
    
    lalpha = 
    ralpha = 
    msg = 

    print(, lalpha)
    print(, ralpha)
    print(, msg)
    print(, do_chao(msg, lalpha, ralpha, 1, 0), )

    do_chao(msg, lalpha, ralpha, 1, 1)

def do_chao(msg, lalpha, ralpha, en=1, show=0):
    msg = correct_case(msg)
    out =     
    if show:
        print(*54)        
        print(10* +  + 21* + )
        print(*54)        
        print(lalpha, ralpha, )
    for L in msg:
        if en:
            lalpha, ralpha = rotate_wheels(lalpha, ralpha, L)
            out += lalpha[0]
        else:
            ralpha, lalpha = rotate_wheels(ralpha, lalpha, L)
            out += ralpha[0]
        lalpha, ralpha = scramble_wheels(lalpha, ralpha)
        if show:
            print(lalpha, ralpha)            
    return out

def makealpha(key=):
    alpha = 
    z = set()
    key = [x.upper() for x in (key + alpha[::-1])
           if not (x.upper() in z or z.add(x.upper()))]
    return .join(key)

def correct_case(string):
    return .join([s.upper() for s in string if s.isalpha()])

def permu(alp, num):
    alp = alp[:num], alp[num:]
    return .join(alp[::-1])

def rotate_wheels(lalph, ralph, key):
    newin = ralph.index(key)
    return permu(lalph, newin), permu(ralph, newin)    

def scramble_wheels(lalph, ralph):
    
    
    lalph = list(lalph)
    lalph = .join([*lalph[0],
                    *lalph[2:14],
                    lalph[1],
                    *lalph[14:]])

    
    
    
    ralph = list(ralph)
    ralph = .join([*ralph[1:3],
                     *ralph[4:15],
                     ralph[3],
                     *ralph[15:],
                     ralph[0]])
    return lalph, ralph

main()