Commit 2fff3ac5 authored by neil.whitehead's avatar neil.whitehead

12:19 10/12/18

parent 39bb1959
public class AssessmentPartThree {
public class AssessmentPartThree
{
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// An offset value is chosen to encrypt a message. Each letter is replaced by the
......@@ -17,6 +18,10 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
//Dealing with negative offsets
theOffset = (theOffset < 0) ? 26 + theOffset : theOffset;
//ensures that the offset will "wrap around"
//Uppercase characters
if((theChar >= 65) && (theChar <= 90)) //65 to 90 = A to B
{
......@@ -35,7 +40,9 @@ public class AssessmentPartThree {
( + 97) + ASCII a/A to return result to ASCII char
(char) result needs to be casted to char
*/
return theChar;
//any non alphabetical chars will fall through and return original char
}
......
......@@ -23,7 +23,10 @@ class AssessmentPartThreeTest {
"q,-3,n",
"G,6,M",
"5,-3,5",
"T,-7,M"
"T,-7,M",
"a,31,f",
"T,-33,M",
"!, 2, !"
})
void testEnryptedCharacter(char theChar, int theOffset, char encChar) {
assertEquals(encChar,test.enryptedCharacter(theChar, theOffset));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment