Skip to content

Commit

Permalink
Java implementation of Caesar Cipher algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Iris Yuan committed Aug 14, 2014
1 parent e441a91 commit 90b944e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Caesar-Cipher/Java/irisyuan/caesarCipher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.Scanner;

public class caesarCipher {

// cipher(String,int) returns original message shifted by 3 letters
// if input is numerical, adds 3 to number
public static char[] cipher(String message, int shift) {

// declare variables
String s = message;
// convert string to array of chars
char[] letters = message.toCharArray();

for(int i = 0; i < message.length(); i++){
letters[i] += 3;
}
return letters;
}

// main method takes user input and calls cipher
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.println("Plaintext: ");
String message = input.nextLine();

System.out.println("Ciphertext:");
System.out.println(cipher(message, 3));
}

}

0 comments on commit 90b944e

Please sign in to comment.