SuperRot
SRM 154 · 2003-07-09 · by Karshikinpa
SRM 154 · 2003-07-09 · by Karshikinpa · Encryption/Compression, String Manipulation
Problem Statement
Problem Statement
There exists a basic encryption method known as ROT13. One property of ROT13 is that the encryption and decryption processes are exactly the same. These processes work by doing a simple transformation from one letter of the alphabet to another. The letters A through M become N through Z, such that A->N, B->O, ..., M->Z. The letters N through Z become A through M, such that N->A, O->B, ..., Z->M.
One of the problems with most implementations is that everything is converted to upper case. Another problem is that numbers are ignored completely, leaving them unencrypted. One way to overcome these limitations is to extend ROT13 to cover lowercase letters as well as numbers. Here is how our extended ROT transformations will work:
For example, the message "Uryyb 28" would become "Hello 73" after being transformed.
You have intercepted a message which you believe to be encrypted using this process. Create a class SuperRot with a method decoder that takes aString message and returns the decoded message as a String .
One of the problems with most implementations is that everything is converted to upper case. Another problem is that numbers are ignored completely, leaving them unencrypted. One way to overcome these limitations is to extend ROT13 to cover lowercase letters as well as numbers. Here is how our extended ROT transformations will work:
characters become A-M N-Z N-Z A-M a-m n-z n-z a-m 0-4 5-9 5-9 0-4
For example, the message "Uryyb 28" would become "Hello 73" after being transformed.
U -> H 2 -> 7 r -> e 8 -> 3 y -> l y -> l b -> 0Notice that the spaces were left as is.
You have intercepted a message which you believe to be encrypted using this process. Create a class SuperRot with a method decoder that takes a
Notes
- All spaces occuring in message are left as spaces in the decoded String.
Constraints
- message will have between 0 and 50 characters inclusive.
- message will consist only of letters 'a' - 'z' and 'A' - 'Z', digits '0' - '9', and the space character.
- message will not contain two or more consecutive spaces.
- There will be no leading or trailing spaces.
Examples
0)
"Uryyb 28" Returns: "Hello 73"
This is the example from above.
1)
"GbcPbqre" Returns: "TopCoder"
G -> T b -> o c -> p P -> C b -> o q -> d r -> e e -> r
2)
"" Returns: ""
Remember the empty String.
3)
"5678901234" Returns: "0123456789"
4)
"NnOoPpQqRr AaBbCcDdEe" Returns: "AaBbCcDdEe NnOoPpQqRr"
Submissions are judged against all 48 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class SuperRot with a public method string decoder(string message) · 48 test cases · 2 s / 256 MB per case