char[]alphabet={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};// creates an array string string containing each letter of the alphabet
booleanupperCaseCharacter;//creates a boolean caleld uppercasecharacter
intletterPlace=0;//creates an int called letterplace and assigns it a value of 0
upperChar=Character.isUpperCase(theChar);
theChar=Character.toLowerCase(theChar);
upperCaseCharacter=Character.isUpperCase(theChar);// makes uppercasecharacter equal to the uppercse value of theChar
theChar=Character.toLowerCase(theChar);//makes theChar equal to the lowercase value of theChar
for(inti=0;i<alphabet.length;i++)
for(inti=0;i<alphabet.length;i++)// creates a for loop that runs as long as i is less than the length of the array string alphabet
{
if(theChar==alphabet[i])
if(theChar==alphabet[i])// if thechar is equal to the i'th value of alphabet
{
theOffset=theOffset+i;
break;
theOffset=theOffset+i;//makes the offset equal to theoffset plus the value of i
}
}
if(Character.isLetter(theChar))
if(Character.isLetter(theChar))//if theChar is a Letter
{
if(theOffset<0)
if(theOffset<0)// if the value of theOffset is less than 0
{
theOffset=theOffset+26;
theOffset=theOffset+26;//makes theOffset equal to theOffset plus 26
}
if(theOffset>alphabet.length)
if(theOffset>alphabet.length)// if the value of theOfset is greater than the length of the string alphabet
{
theOffset=theOffset-26;
theOffset=theOffset-26;//makes theOffset equal to theOffset - 26
}
else
else//if none of the above if statements were met
{
theChar=alphabet[theOffset];
theChar=alphabet[theOffset];//makes thechar equal to the character in alphabet equal to the value of the offset
}
}
else
else//if the previous if statement is not met
{
returntheChar;
returntheChar;//return the value of theChar
}
if(upperChar)
if(upperCaseCharacter)// if uppercasecharacter has a value
{
theChar=Character.toUpperCase(theChar);
theChar=Character.toUpperCase(theChar);//makes thechar equal to the uppercase value of thechar
}
returntheChar;
returntheChar;//returns thechar
}
/* String lowerbet = "abcdefghijklmnopqrstuvwxyz"; //creates a string containing all the letter of the alphabet in lowercase
String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // creates a string containing all the letters of the alphabet in uppercase
for (int i = 0; i < lowerbet.length(); i++) // creates a for loop that declares a variable called I, then iterates until i is greater than the length of the string lowerbet (in this case it would be 26)
{
if (theChar == lowerbet.charAt(i)) // creates an if statement that triggers if the character in theChar is equal to the ith value of the string lowerbet
{
char newnumber = lowerbet.charAt(theOffset + i); // assigns character equal to the character at the value of offset + the value of I of the string lowerbet to a char called newnum
return newnumber; // returns the value of newnum
}
if (theChar == capitalbet.charAt(i)) // if the value of theChar is equal to the i'th character of the string capitalbet
{
char newnumber = capitalbet.charAt(theOffset + i); // assigns character equal to the character at the value of offset + the value of i
return newnumber; //returns the value of newnum
}
}
char newnumber = theChar; // assigns the value of theChar to newnum
@@ -110,50 +79,13 @@ public class AssessmentPartThree {
Stringoutput="";
for(charletter:theMessage.toCharArray())
for(charletter:theMessage.toCharArray())//creates a or loop that iterates the char "letter" through theMessage.tochararray
{
letter=enryptedCharacter(letter,theOffset);
output=output+letter;
letter=enryptedCharacter(letter,theOffset);// makes letter equal to the value obtained when running the value of theMessage through the encryptedcharacter method above
output=output+letter;// makes output equal to output + letter
}
returnoutput;
/* StringBuilder string = new StringBuilder(); //creates an empty StringBuilder called String
char j ; // creates an empty char called j
for (int i = 0; i < theMessage.length(); i++) // creates a for loop that iterates until i is greater then the length of whatever is stored in the string "theMessage"
{
j = theMessage.charAt(i); // makes j equal to the i'th character of theMessage
if (Character.isLetter(j)) // if the value assigned to j is a letter runs the following
{
j = (char) (theMessage.charAt(i) + theOffset); // makes j a char equal to the i'th value of theMessage + the value of the offset
}
if ((Character.isLowerCase(theMessage.charAt(i))) && j > 'z') // if the i'th character of theMessage is lowercase and the value stored in j is greater than the lowercase value of z
{
j = (char) (theMessage.charAt(i) - (theOffset - 26)); // makes j equal to the value of i'th character of themessage minus the value of theoffset minus 26
}
if (Character.isUpperCase(theMessage.charAt(i)) && j > 'Z') // if the i'th character of theMessage is uppercasecase and the value stored in j is greater than the uppercase value of z
{
j = (char) (theMessage.charAt(i) - (theOffset - 26)); //makes j equal to the i'th character of themessage minus the value of theOffset, minus 26
}
if (Character.isUpperCase(theMessage.charAt(i)) && j < 'A') // if the i'th character of theMessage is uppercasecase and the value stored in j is less than the uppercase value of A
{
j = (char) (theMessage.charAt(i) + (theOffset + 26)); // makes j equal to the i'th character of themessage plus the value of the offset plus 26
}
if ((Character.isLowerCase(theMessage.charAt(i)) && j < 'a')) // if the i'th character of theMessage is lowercase and the value stored in j is less than the lowercase value of a
{
j = (char) (theMessage.charAt(i) + (theOffset + 26)); // makes j equal to the i'th character of themessage plus the value of the offset plus 26
}
string.append (j); // returns string with the value of j added too it
}
return string.toString(); // returns a string containing whatever is stored in the stringbuilder "string" */