-
-
Save fado/8979990 to your computer and use it in GitHub Desktop.
This file contains 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
package practical2p3.uk.ac.qub; | |
public class CaesarCypher { | |
private String stringToEncode; | |
private int codeKey; | |
public CaesarCypher(){ | |
} | |
public CaesarCypher (String stringToEncode, int codeKey) { | |
this.stringToEncode = stringToEncode; | |
this.codeKey = codeKey; | |
} | |
public void encode (String stringToEncode, int codeKey) { | |
String cipherText = ""; | |
char currentCharacter; | |
for (int counter = 0; counter < stringToEncode.length(); counter++) { | |
currentCharacter = stringToEncode.charAt(counter); | |
for (int loop = 0; loop < codeKey; loop++) { | |
if (currentCharacter == 'Z') { | |
currentCharacter = 'A'; | |
} else if (currentCharacter == 'z') { | |
currentCharacter = 'a'; | |
} else if (Character.isAlphabetic(currentCharacter)) { | |
currentCharacter++; | |
} | |
} | |
String cipherText =+ currentCharacter; | |
} | |
System.out.println(cipherText); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment