Created
December 2, 2012 01:29
-
-
Save codelance/4186425 to your computer and use it in GitHub Desktop.
Ceasar Cipher Break
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 static void main(String[] args) { | |
| String ciphertext = "HSPAASLJPWOLYALEAJVBSKILHWYVISLTIBAUVAPMPAPZHZOPMAJPWOLY"; | |
| for(int shiftKey = 0; shiftKey < 26; shiftKey++) | |
| { | |
| String plainText = ""; | |
| for (int i=0; i<ciphertext.length(); i++) | |
| { | |
| int asciiValue = (int) ciphertext.charAt(i); | |
| int alphabetIndex = asciiValue - 65; | |
| int newshiftedAsciiValue = -1000; | |
| if (alphabetIndex - shiftKey < 0){ | |
| newshiftedAsciiValue = 90 - (shiftKey - alphabetIndex) + 1; | |
| } | |
| else{ | |
| newshiftedAsciiValue = 65 + (alphabetIndex - shiftKey); | |
| } | |
| plainText += (char) newshiftedAsciiValue; | |
| } | |
| System.out.println(plainText); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment