Problem Statement
Scrambling of a message is performed using the
To make the encryption even more confusing, you are going to repeat the above process K times in a row. Given message, key, and the
Definition
- Class:
- VerySecureEncryption
- Method:
- encrypt
- Parameters:
- String, int[], int
- Returns:
- String
- Method signature:
- String encrypt(String message, int[] key, int K)
- (be sure your method is public)
Constraints
- N will be between 1 and 10, inclusive.
- message will contain N characters.
- Each character of message will be a lowercase English letter.
- key will contain N elements.
- Each element of key will be between 0 and N-1, inclusive.
- The elements of key will be distinct.
- K will be between 1 and 50, inclusive.
Examples
"abc"
{1,2,0}
1
Returns: "cab"
The character 'a' will go from position 0 to position key[0]=1. The character 'b' will go from position 1 to position key[1]=2. The character 'c' will go from position 2 to position key[2]=0.
"abcde"
{4, 3, 2, 1, 0}
1
Returns: "edcba"
"abcde"
{4, 3, 2, 1, 0}
2
Returns: "abcde"
This is the same message and the same key as in example 1, but now K=2, so we scramble the message twice. For this particular key we see that each scrambling reverses the order of letters, which means that the final message is the same as the original we started with.
"uogcodlk"
{4, 3, 6, 2, 5, 1, 0, 7}
44
Returns: "goodluck"
"k"
{0}
34
Returns: "k"
"yq"
{0,1}
50
Returns: "yq"
"hzq"
{2,1,0}
40
Returns: "hzq"
"omch"
{0,3,2,1}
47
Returns: "ohcm"
"mpeit"
{1,2,3,0,4}
1
Returns: "impet"
"efcxbn"
{2,0,1,4,5,3}
11
Returns: "cefbnx"
"ospuuqo"
{2,3,5,6,4,0,1}
30
Returns: "ospuuqo"
"pyoncpoi"
{5,2,3,7,6,0,1,4}
50
Returns: "pcoynpio"
"ijqztpkmb"
{1,0,2,8,5,4,3,7,6}
35
Returns: "jiqbptzmk"
"rsjuscwybr"
{6,0,8,5,4,3,2,9,7,1}
50
Returns: "srwuscrbjy"
"uogcodlk"
{4, 3, 6, 2, 5, 1, 0, 7 }
44
Returns: "goodluck"
"abcde"
{4, 3, 2, 1, 0 }
1
Returns: "edcba"
"abc"
{1, 2, 0 }
1
Returns: "cab"