CaesarShift

/** * Write a description of class Caesar here. *Shifts word * @author (Rahul Khullar) * @version (9/14/17) */ import java.util.*; public class Caesar { public Caesar() { Scanner scan = new Scanner(System.in); System.out.println(""); System.out.println("Enter what you want to encrypt"); String og = scan.nextLine(); System.out.println("Enter shift"); int shif = scan.nextInt(); String alph = "abcdefghijklmnopqrstuvwxyz"; //26 int oglen = og.length(); String word = ""; for (int i=0; i < oglen; i++){ String let = og.substring(i, i + 1);//finds letter of word in entry int point = alph.indexOf(let);//finds position of letter in alph int ex = (point + shif) % 26;//adds shift and solves wrap around String r = alph.substring(ex, ex + 1);//finds new shifted letter System.out.print(r);//prints letter to screen } } }

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.