Caesar Shift

/** * 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){//run once for every letter in word String lett = word.substring(count,count+1);//pick letter to be shifted int ind = alpha.indexOf(lett); int newLett = ind + shift;//shift to new letter if (newLett>26){//wraparound newLett = newLett%26;} String result=alpha.substring(newLett,newLett+1); System.out.print(result); count++;//print out and repeat } System.out.println(" "); } }
Caesar Shift
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.