# Frase de entrada:
text = input ( "Entre com uma frase: \n " )
# Chave de entrada:
key = int ( input ( "Entre com uma chave: \n " ) )
# Sequência de entrada:
sequence = [ ]
for i in range ( key) :
sequence.append ( int ( input ( "Entre com um número da sequência: \n " ) ) )
# Remove os espaços em branco do texto:
text = text.replace ( " " , "" )
# Divide o texto em grupos definidos pela chave:
groups = [ text[ i:i+key] .ljust ( key, "*" ) for i in range ( 0 , len ( text) , key) ]
# Percorre os grupos gerando os novos grupos:
result = [ ]
for group in groups:
output = ""
for i in sequence:
output += group[ i-1 ]
result.append ( output)
print ( result)
IyBGcmFzZSBkZSBlbnRyYWRhOgp0ZXh0ID0gaW5wdXQoIkVudHJlIGNvbSB1bWEgZnJhc2U6IFxuIikKCiMgQ2hhdmUgZGUgZW50cmFkYToKa2V5ID0gaW50KGlucHV0KCJFbnRyZSBjb20gdW1hIGNoYXZlOiBcbiIpKQoKIyBTZXF1w6puY2lhIGRlIGVudHJhZGE6CnNlcXVlbmNlID0gW10KZm9yIGkgaW4gcmFuZ2Uoa2V5KToKICAgIHNlcXVlbmNlLmFwcGVuZChpbnQoaW5wdXQoIkVudHJlIGNvbSB1bSBuw7ptZXJvIGRhIHNlcXXDqm5jaWE6IFxuIikpKQogICAgCiMgUmVtb3ZlIG9zIGVzcGHDp29zIGVtIGJyYW5jbyBkbyB0ZXh0bzoKdGV4dCA9IHRleHQucmVwbGFjZSgiICIsICIiKQogICAgCiMgRGl2aWRlIG8gdGV4dG8gZW0gZ3J1cG9zIGRlZmluaWRvcyBwZWxhIGNoYXZlOgpncm91cHMgPSBbdGV4dFtpOmkra2V5XS5sanVzdChrZXksICIqIikgZm9yIGkgaW4gcmFuZ2UoMCwgbGVuKHRleHQpLCBrZXkpXQoKIyBQZXJjb3JyZSBvcyBncnVwb3MgZ2VyYW5kbyBvcyBub3ZvcyBncnVwb3M6CnJlc3VsdCA9IFtdCmZvciBncm91cCBpbiBncm91cHM6CiAgICBvdXRwdXQgPSAiIgogICAgZm9yIGkgaW4gc2VxdWVuY2U6CiAgICAgICAgb3V0cHV0ICs9IGdyb3VwW2ktMV0KICAgIHJlc3VsdC5hcHBlbmQob3V0cHV0KQogICAgCnByaW50KHJlc3VsdCk=