Commit 402af014 authored by daniel.parker's avatar daniel.parker

initial.

parent a7175211
Pipeline #385 failed with stages
public class AssessmentPartThree { public class AssessmentPartThree {
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher) // The simplest form of encryption is the rotation cipher (also known as
// An offset value is chosen to encrypt a message. Each letter is replaced by the // Caeser's Cipher)
// An offset value is chosen to encrypt a message. Each letter is replaced by
// the
// letter that that number of places away from it. // letter that that number of places away from it.
// So if an offset value of 1 is chosen, each letter is replaced by the one after it // So if an offset value of 1 is chosen, each letter is replaced by the one
// after it
// - so a becomes b, b becomes c, etc // - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on // If a value of -2 is chosen a becomes y, b becomes z and so on......
public char enryptedCharacter(char theChar, int theOffset) { public char enryptedCharacter(char theChar, int theOffset) {
char returnChar = theChar; char returnChar = theChar;
int x = 0; int x = 0;
String alphabet = "abcdefghijklmnopqrstuvwxyz"; String alphabet = "abcdefghijklmnopqrstuvwxyz";
if (Character.isUpperCase(theChar)) { if (Character.isUpperCase(theChar)) {
alphabet = alphabet.toUpperCase(); alphabet = alphabet.toUpperCase();
} }
...@@ -29,28 +32,27 @@ public class AssessmentPartThree { ...@@ -29,28 +32,27 @@ public class AssessmentPartThree {
} }
} }
// 05 - encryptedCharacter // 05 - encryptedCharacter
// Complete this method so that it returns the encrypted character for // Complete this method so that it returns the encrypted character for
// theChar when and offset of theOffset is used // theChar when and offset of theOffset is used
// So if theChar='m' and theOffset is 3 the method will return 'p' // So if theChar='m' and theOffset is 3 the method will return 'p'
// 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 returnChar; return returnChar;
} }
public String encryptedString(String theMessage, int theOffset) { public String encryptedString(String theMessage, int theOffset) {
String alphabet = "abcdefghijklmnopqrstuvwxyz"; String alphabet = "abcdefghijklmnopqrstuvwxyz";
String codedString = ""; String codedString = "";
char[] theMessageChars = theMessage.toCharArray(); char[] theMessageChars = theMessage.toCharArray();
int x = -1; int x = -1;
for (int i = 0; i < theMessage.length(); i++) { for (int i = 0; i < theMessage.length(); i++) {
char character = theMessage.charAt(i); char character = theMessage.charAt(i);
codedString+=enryptedCharacter(character,theOffset); codedString += enryptedCharacter(character, theOffset);
//codedString = String.valueOf(theMessageChars);
} }
return codedString; return codedString;
} }
......
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