Advertisement
Visual-mov

Caesar Cipher Encoder

Dec 23rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. // Caesar Cipher Encoder. Made by Ryan D. 2018
  2. // (Currently only works with lower-case letters.)
  3. package visual;
  4. import java.util.*;
  5. public class Main {
  6.     static int shiftFac = 0;
  7.     static String message = "";
  8.     static String out = "";
  9.     public static void main(String[] args) {
  10.         Scanner sc = new Scanner(System.in);
  11.         System.out.println("Enter the amount to shift:");
  12.         shiftFac = Integer.parseInt(sc.nextLine());
  13.         System.out.println("Enter the String:");
  14.         message = sc.nextLine();
  15.         char[] cmessage = message.toCharArray();
  16.         for (char c: cmessage) {
  17.             if(c!=' '&&c!='?'&&c!='!'&&c!='.'&&c!=',') {
  18.                 char shiftc = (char)(c + shiftFac);
  19.                 if (shiftc >= 123) {
  20.                     shiftc = (char)(shiftc - 26);
  21.                     out += shiftc;
  22.                 } else {
  23.                     out += shiftc;
  24.                 }
  25.             } else {
  26.                 out += c;
  27.             }
  28.         }
  29.         System.out.println("New string: " + out);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement