/**
* Charlotte Weisman
* B Block Computer Science
* 9/15/17
* Caesar Shift
*/
import java.util.*;
public class caesarShift
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in); //scanner
System.out.println("Please type one word to encrypt: ");
String word = sc.nextLine();
int length = word.length();
int shift = 4;
String alpha = "abcdefghijklmnopqrstuvwxyz";
int count = 0;
while (count<length){
String lett = word.substring(count,count+1);//pick letter to be shifted
int ind = alpha.indexOf(lett);
int newLett = ind + shift;
if (newLett>26){
newLett = newLett%26;
}
String result=alpha.substring(newLett,newLett+1);
System.out.print(result);
count++;
}
System.out.println(" ");
}
}
Caesar Shift
AP Computer Science
9/15/17
AP Computer Science
9/15/17
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.