In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would be replaced by D, B would become E, and so on. The method is named after Julius Caesar, who used it in his private correspondence.
Cipher after shifting the plain text with a shift of 3:
Rar the Cat stumbled on the above Wikipedia article (Yes the first paragraph is copied from there) and now wants you to create a Caesar cipher machine! The machine has the following functions:
void loadCipher (string plaintext): This function would be called whenever a new plain text is loaded into the cipher machine. The current shift is reset to zero each time this function is called.
void shift (int x): Upon calling this function, the plain text should be shifted by x letters. x would be in the range -10000000 ≤ x ≤ 10000000. Note that shifts are cumulative, e.g. the function calls loadCipher("ABC"); shift(1); shift(2); would result in the string "ABC" being shifted by 3 positions.
char getLetter (int position): This function should return the letter at the specified position. The first letter would have position 1.
Your job is to code the above functions :D
You are not allowed to input or output to standard input or output in any of your functions when submitting to the judge. The grader will do that automatically for you (grader.cpp).
The plain text provided would all be in uppercase and does not contain any other non-alphabetical characters.
There are template files provided under attachment, you are strongly advised to write your solution within the template files instead of creating new source files. The command to compile is
g++ -O2 -o caesar grader.cpp caesar.cpp. Alternatively, you may just run
compile_cpp.sh which contains the compilation command.
Please ask clarifications if in doubt.
Subtask 1 (20%): There will be only 1 loadCipher call and the length of the text is at most 100. There will be at most 1000 function calls in total.
Subtask 2 (35%): There will be only 1 loadCipher call and the length of the text is at most 10000. There will be at most 100000 function calls in total.
Subtask 3 (45%): There will be at most 50 loadCipher calls and the length of the text is at most 10000. There will be at most 1000000 function calls in total.
Subtask 4 (0%): Sample Testcase
Sample Testcase 1