APCS A: D(Encryption) Summative

At first when approaching this summative, I was really confused at where to start. I originally had an idea to create an array which would be paralleled onto a new array, which would be made out of different letters and symbols. However, after a class period where we review how to utilise ASCII in java, I chose a slightly easier pathway.

First, both my Encrypt and Decrypt class contained one constructor and four methods. In each class, the only constructor defined the instance variable of word and text in the encrypt and decrypt classes respectively.

The first of the four methods, named getLength, simply identified how many characters existed a word that was specified within the main method class. I was able to utilise this method in my final encrypt method to set a a parameter for the loop, ending where there were only so many characters in whatever string input that the user wanted to use.

The second of the four methods, the returnACharacter method, functioned to return each of the characters that are present in the word, then spacing them out. This was utilised in my final method to make each character unique before I altered them into different forms, as you’re about to see. This method also used the getLength method in order to see how many characters a word had, thus only carrying out a function on the letters in the word and no more.

The third of the four methods was the returnASCII method. This method took characters and returned their ASCII value instead of their string value, thus assigning each character to a numeric value that we could use to further encrypt our code.

Finally, our fourth of the four methods was used to actually wrap everything together. Here, I set up two variables, x, which represented the getLength method, letting me set a parameter on the function that I was planning to carry out. The second variable, counter, helping me make increments on the progress of the reaction, where each increment had a function that was carried out on that certain letter. Finally, I had a final variable which was just an empty string which I later combined with an integer in order to turn it back into a string. After setting up these variables, I created a while loop, setting the parameter to up to as many characters there are in the word. Here, I created an integer-based ASCII variable, which first took the character at a certain place depending on the counter, then returned it’s respective ASCII value. Here is where the two classes, Encrypt and Decrypt, were different. Encrypt had a +1 after the returnASCII and returnACharacter, this ensured that the letters were scrambled to go from ‘abc’ to ‘bcd,’ which actually resulted in a different character, which is where the encryption was happening. Decrypt did the opposite, returning a word to it’s original meaning by being able to go from ‘bcd’ back to ‘abc.’ After this ASCII variable was declared, I set a new variable which changed the numeric-integer value that the ASCII variable contained into a character, which would be turning the numeric value back into english alphabetic letters. Then, a simple line of code adding together each of the characters in order to build a word back up using characters, which would be concatenated into words.

When writing this code, I didn’t actually consult any online sources or something like stack overflow. Instead, I took the work that we did in class on Tuesday, the 21st of November, and added a few changes to it. Things that really aided me in this project included the creation of flowcharts which helped me understand what I was trying to accomplish, and the steps that it took for me to get there. From previous classes, I was able to understand that in order to turn the integer value back into a string, I had to concatenate it with an empty string, as indicated in my code. By doing this, I was able to create the flow of how my code worked.

Finally, after all pulling together, I was able to create a program that took a string that could take in all words and letters, and changed it into something different, an encrypted word! In a similar way, my program is also able to return an encrypted word into it’s generic english meaning, or at least back to whatever you were trying to hide…

Proof that it works:

Sorry about the quality of the second picture, blueJ doesn’t fold into new lines and I wanted to show off all of the symbols. You can click on it to enlarge it.

Leave a Reply