Skip to content

Instantly share code, notes, and snippets.

@fado
Forked from LordNairu/Encoder.java
Last active August 29, 2015 13:56
Show Gist options
  • Save fado/8979990 to your computer and use it in GitHub Desktop.
Save fado/8979990 to your computer and use it in GitHub Desktop.
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