TopCoder problem "TwoRotationCypher" used in SRM 378 (Division II Level One)



Problem Statement

    

You have decided to create your own simple encryption method for strings containing only lowercase letters and spaces. You start by splitting the alphabet into two groups. The first group consists of the first firstSize letters of the alphabet, and the second consists of the remaining 26 - firstSize letters. To encrypt a character in your message, you do the following:

  1. If it a space, it is kept as is.
  2. If it is a letter in the first group, it is moved firstRotate letters forward in the group, wrapping back to the start if necessary. For example, if firstSize is 6 and firstRotate is 2, then 'A' would become 'C', and 'F' would become 'B'.
  3. If it is a letter in the second group, then it is moved secondRotate letters forward in the group, again wrapping back to the start of the group if necessary.

Given firstSize, firstRotate, secondRotate and a message, return the encrypted form of the message.

 

Definition

    
Class:TwoRotationCypher
Method:encrypt
Parameters:int, int, int, String
Returns:String
Method signature:String encrypt(int firstSize, int firstRotate, int secondRotate, String message)
(be sure your method is public)
    
 

Constraints

-firstSize will be between 1 and 25, inclusive.
-firstRotate will be between 0 and firstSize - 1, inclusive.
-secondRotate will be between 0 and 25 - firstSize, inclusive.
-message will contain between 1 and 50 characters, inclusive.
-message will contain only lowercase letters ('a' - 'z') and spaces.
 

Examples

0)
    
13
0
0
"this string will not change at all"
Returns: "this string will not change at all"
1)
    
13
7
0
"only the letters a to m in this string change"
Returns: "onfy tbl flttlrs h to g cn tbcs strcna jbhnal"
2)
    
9
0
16
"j to z will change here"
Returns: "z sn y vikk chamge heqe"
3)
    
17
9
5
"the quick brown fox jumped over the lazy dog"
Returns: "yqn izalc kwgsf ogt bzehnm grnw yqn djvu mgp"
4)
    
3
1
2
"  watch   out for strange  spacing "
Returns: "  ybvaj   qwv hqt uvtbpig  urbakpi "

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8304

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10798&pm=8304

Writer:

bmerry

Testers:

PabloGilberto , Olexiy , marek.cygan , ivan_metelsky

Problem categories:

Simulation, String Manipulation