Caesar Cypher

/** * Write a description of class CaesarCypher here. * * @author (Sebastian garrubbo) * @version (9/14/17) */ import java.util.*; public class CaesarCypher { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int shift = 4; String encrypt = " "; String a = "abcdefghijklmnopqrstuvwxyz"; System.out.println("\nEnter a word to be encrypted: " ); String in = sc.next(); int ln = in.length(); int count = 0; while(count<ln){ String temp = in.substring(count, count+1); int spot = a.indexOf(temp); int shiftSpot = (spot+shift)%26; encrypt += a.substring(shiftSpot, shiftSpot+1); count++; } System.out.println("Your newly encrypted word is" + encrypt); } }

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.