Created
March 22, 2017 04:16
-
-
Save M-ZubairAhmed/7c1ba8f7aa28a3fbc1141c0280c5d1b3 to your computer and use it in GitHub Desktop.
Caesar Decryption Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NotePassing { | |
| public static String decipher (String codedMessage, int key){ | |
| char[] charArray = new char[codedMessage.length()]; | |
| int[] intArray = new int[codedMessage.length()+1]; | |
| for (int r = 0; r < codedMessage.length(); r++){ | |
| boolean isUCase = (codedMessage.charAt(r)>=65) && (codedMessage.charAt(r)<=90); | |
| boolean isLCase = (codedMessage.charAt(r)>=97) && (codedMessage.charAt(r)<=122); | |
| int changedAsci = ((int)codedMessage.charAt(r)) + key; | |
| if (isUCase) { | |
| intArray[r] = (changedAsci > 90) ? 64 + (changedAsci - 90) : changedAsci; | |
| } | |
| else if (isLCase){ | |
| intArray[r] = (changedAsci > 122) ? 96 + (changedAsci - 122) : changedAsci; | |
| } | |
| else{ | |
| intArray[r] = changedAsci - key; | |
| } | |
| charArray[r] = (char) intArray[r]; | |
| } | |
| String decodedString = new String(charArray); //passing char array object to string | |
| return decodedString; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caesar Decryption
Objective
This Algorithm converts a text encrypted via Caesar back to plain English text.
Methodology