// Helene Martin, CSE 142 // Encodes a secret message by rotating each letter // by the amount given in a secret key. // http://en.wikipedia.org/wiki/Caesar_cipher import java.util.*; public class CaesarCypher { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Your secret message: "); String message = console.nextLine(); message = message.toLowerCase(); System.out.print("Your secret key: "); int key = console.nextInt(); for (int i = 0; i < message.length(); i++) { // we can use == on chars because they are primitives if (message.charAt(i) == ' ') { System.out.print(" "); } else { System.out.print((char)(message.charAt(i) + key)); } } } }