3661 - Reverse Rot 3661 - Invertir y Rotar 3661 - Reverse Rot

Statistics Sub: 339 | AC: 264 | AC%: 77,88 | Score: 0,71
Created by ACM-ICPC Mid-Central - USA
Added by kko (2016-06-01)
Limits
Total Time: 1000 MS |Memory: 512 MB | Output: 64 MB | Size: 9 KB
Enabled languages
Available in

Description

A very simplistic scheme, which was used at one time to encode information, is to rotate the characters within an alphabet and rewrite them. ROT13 is the variant in which the characters A-Z are rotated 13 places, and it was a commonly used insecure scheme that attempted to "hide" data in many applications from the late 1990's and into the early 2000's.

It has been decided by Insecure Inc. to develop a product that "improves" upon this scheme by first reversing the entire string and then rotating it. As an example, if we apply this scheme to string ABCD with a reversal and rotation of 1, after the reversal we would have DCBA and then after rotating that by 1 position we have the result EDCB.

Your task is to implement this encoding scheme for strings that contain only capital letters, underscores, and periods. Rotations are to be performed using the alphabet order:

    ABCDEFGHIJKLMNOPQRSTUVWXYZ_.

Note that underscore follows Z, and the period follows the underscore. Thus a forward rotation of 1 means 'A' is shifted to 'B', that is, 'A'->'B', 'B'->'C', ..., 'Z'->'_', '_'->'.', and '.'->'A'. Likewise, a rotation of 3 means 'A'->'D', 'B'->'E', ..., '.'->'C'.
Un esquema muy simple usado en el pasado para cifrar información, consiste en rotar los caracteres de un alfabeto y reescribirlos. ROT13 es la variante donde los caracteres A-Z son rotados 13 lugares y este fue un esquema inseguro usado comúnmente para intentar ocultar los datos en muchas aplicaciones en los lejanos años 1990’s y en los más cercanos 2000’s.

La organización Inseguro Inc. ha decidido desarrollar un producto que mejore este esquema de modo que inicialmente se invierta la cadena completa para posteriormente rotarla. A manera de ejemplo, si se aplicara este esquema a la cadena ABCD con una inversión y rotación de 1, después de la inversión se obtendría DCBA, que después de ser rotada por 1 posición se transformaría en EDCB.

Su tarea es implementar este esquema de cifrado para cadenas que contienen solamente letras mayúsculas, guiones bajos y puntos. Las rotaciones serán realizadas utilizando el alfabeto:

ABCDEFGHIJKLMNOPQRSTUVWXYZ_.

Nótese que el guion bajo sucede a la Z y el punto sucede al guion bajo. De esta manera, una rotación hacia adelante de tamaño 1 indica que A se transforma en B, en otras palabras 'A'→'B', 'B'→'C', ..., 'Z'→'_', '_'→'.', y '.'→'A'. de la misma manera, una rotación de tamaño 3 indica que 'A'→'D', 'B'→'E', ..., '.'→'C'.
A very simplistic scheme, which was used at one time to encode information, is to rotate the characters within an alphabet and rewrite them. ROT13 is the variant in which the characters A-Z are rotated 13 places, and it was a commonly used insecure scheme that attempted to "hide" data in many applications from the late 1990's and into the early 2000's.

It has been decided by Insecure Inc. to develop a product that "improves" upon this scheme by first reversing the entire string and then rotating it. As an example, if we apply this scheme to string ABCD with a reversal and rotation of 1, after the reversal we would have DCBA and then after rotating that by 1 position we have the result EDCB.

Your task is to implement this encoding scheme for strings that contain only capital letters, underscores, and periods. Rotations are to be performed using the alphabet order:

    ABCDEFGHIJKLMNOPQRSTUVWXYZ_.

Note that underscore follows Z, and the period follows the underscore. Thus a forward rotation of 1 means 'A' is shifted to 'B', that is, 'A'->'B', 'B'->'C', ..., 'Z'->'_', '_'->'.', and '.'->'A'. Likewise, a rotation of 3 means 'A'->'D', 'B'->'E', ..., '.'->'C'.

Input specification

Each input line will consist of an integer N, followed by a string. N is the amount of forward rotation, such that 1 <= N <= 27. The string is the message to be encrypted, and will consist of 1 to 40 characters, using only capital letters, underscores, and periods. The end of the input will be denoted by a final line with only the number 0.
Cada línea de entrada estará formada por un entero N, seguido por una cadena. N es el tamaño de la rotación hacia adelante, de modo que 1 <= N <= 27. La cadena es el mensaje que deberá ser cifrado y estará formada por una cantidad de caracteres entre 1 y 40, empleando solamente letras mayúsculas, guiones bajos y puntos. El final de la entrada estará denotado por una línea formada únicamente por el número 0.
Each input line will consist of an integer N, followed by a string. N is the amount of forward rotation, such that 1 <= N <= 27. The string is the message to be encrypted, and will consist of 1 to 40 characters, using only capital letters, underscores, and periods. The end of the input will be denoted by a final line with only the number 0.

Output specification

For each test case, display the "encrypted" message that results after being reversed and then shifted.
Por cada caso de prueba, imprima el mensaje cifrado que resulta después de invertido y rotado hacia adelante.
Each input line will consist of an integer N, followed by a string. N is the amount of forward rotation, such that 1 <= N <= 27. The string is the message to be encrypted, and will consist of 1 to 40 characters, using only capital letters, underscores, and periods. The end of the input will be denoted by a final line with only the number 0.

Sample input

1 ABCD
3 YO_THERE.
1 .DOT
14 ROAD
9 SHIFTING_AND_ROTATING_IS_NOT_ENCRYPTING
2 STRING_TO_BE_CONVERTED
1 SNQZDRQDUDQ
0

Sample output

EDCB
CHUHKWBR.
UPEA
ROAD
PWRAYF_LWNHAXWH.RHPWRAJAX_HMWJHPWRAORQ.
FGVTGXPQEAGDAQVAIPKTVU
REVERSE_ROT

Hint(s)

http://coj.uci.cu/24h/
http://coj.uci.cu/24h/
http://coj.uci.cu/24h/

Recommendation

We have carefully selected several similar problems: 3380 | 1721 | 3166 | 3375 | 2623 | 3667