Skip to content

Instantly share code, notes, and snippets.

@dhust
Created August 1, 2013 19:02
Show Gist options
  • Save dhust/6134208 to your computer and use it in GitHub Desktop.
Save dhust/6134208 to your computer and use it in GitHub Desktop.
public class Cipher {
public static void main(String[] args) {
// TODO Auto-generated method stub
String plaintext = "Oh say can you see";
String ciphertext = "";
String key = "shift";
//String alphabet = "abcdefghijklmnopqrstuvwxyz";
if (key == "shift") {
//newAlphabet = "bcdefghijklmnopqrstuvwxyza";
}
for (int i = 0; plaintext.length() > i; i++) {
char character = plaintext.charAt(i);
int ascii = (int) character;
// Shift +1
int newAscii = ascii+1;
char newCharacter = (char) newAscii;
// Create ciphertext using the shifted character
ciphertext += newCharacter;
}
System.out.println(ciphertext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment