Commit 39bb1959 authored by neil.whitehead's avatar neil.whitehead

12:08 03/12/18

parent e56f0d16
Pipeline #377 failed with stages
...@@ -17,8 +17,27 @@ public class AssessmentPartThree { ...@@ -17,8 +17,27 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case // Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged // Any other characters are returned unchanged
return 'a'; //Uppercase characters
if((theChar >= 65) && (theChar <= 90)) //65 to 90 = A to B
{
theChar = (char) (((theChar - 65 + theOffset) % 26) + 65);
}
//Lowercase characters
else if((theChar >= 97) && (theChar <= 122)) // 97 to 122 = a to b
{
theChar = (char) (((theChar - 97 + theOffset) % 26) + 97);
} }
/*
theChar = (char) (((theChar - 97 + theOffset) % 26) + 97); formulae
(theChar - 97 - ASCII a/A to give value between 1 and 26
+ theOffset) + the offset value
( % 26) % modulo ensures value is always between 1 and 26
( + 97) + ASCII a/A to return result to ASCII char
(char) result needs to be casted to char
*/
return theChar;
}
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
{ {
...@@ -26,7 +45,19 @@ public class AssessmentPartThree { ...@@ -26,7 +45,19 @@ public class AssessmentPartThree {
// Complete this method so that it uses encryptedCharacter to // Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset // return the encrypted version of theMessage using theOffset
return "Encryptred message"; char chaMessageArr[] = theMessage.toCharArray();
char[] chaResultArr = new char[chaMessageArr.length];
//initialising Arrays
for(int i = 0; i < chaMessageArr.length; i++)
//loop to run through each character in encrypted message
{
chaResultArr[i] = enryptedCharacter(chaMessageArr[i], theOffset);
//passing each character to decryption method and saving result in array
}
return (new String(chaResultArr));
//converting result array into string, and returning this
} }
} }
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