Guest User

Untitled

a guest
Jun 25th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. public class JavaProject
  2. {
  3.  
  4.     public static String Original;
  5.  
  6.     public static void main(String args[])  // Patrick
  7.     {
  8.         System.out.println("This is a program that encrypts or decrypts your input word or phrase.\n It uses the autokey cipher, with a key letter 'N'.");
  9.         System.out.println("");
  10.         System.out.println("Enter a word or phrase");
  11.         Original=Expo.enterString();
  12.         Original.toUpperCase();
  13.         JavaProject.Choose();
  14.     }
  15.  
  16.  
  17.     public static void Choose () //
  18.     {
  19.         System.out.println("");
  20.         System.out.println("Do you want to encrypt or decrypt?");
  21.         String choice = Expo.enterString();
  22.         System.out.println();
  23.         if(choice.equals("encrypt")) {
  24.             JavaProject.Encrypt();  }
  25.         else if (choice.equals("decrypt")) {
  26.             JavaProject.Decrypt();  }
  27.         else {System.out.println("Invalid response. Please use either 'encrypt' or 'decrypt'.");
  28.             JavaProject.Choose();
  29.         }
  30.     }
  31.  
  32.     public static void Encrypt () //
  33.     {
  34.  
  35.         char[] x;
  36.         x = Original.toCharArray();
  37.         char c = 'N';
  38.         x[0] += (26-c);
  39.         if (c>'Z') {
  40.             c-=26;
  41.         }
  42. /*      String a = Original.replace('a','n');
  43.         String b = a.replace('b','o');
  44.         String c = b.replace('c','p');
  45.         String d = c.replace('d','q');
  46.         String e = d.replace('e','r');
  47.         String f = e.replace('f','s');
  48.         String g = f.replace('g','t');
  49.         String h = g.replace('h','u');
  50.         String i = h.replace('i','v');
  51.         String j = i.replace('j','w');
  52.         String k = j.replace('k','x');
  53.         String l = k.replace('l','y');
  54.         String m = l.replace('m','z');
  55.         String n = m.replace('n','a');
  56.         String o = n.replace('o','b');
  57.         String p = o.replace('p','c');
  58.         String q = p.replace('q','d');
  59.         String r = q.replace('r','e');
  60.         String s = r.replace('s','f');
  61.         String t = s.replace('t','g');
  62.         String u = t.replace('u','h');
  63.         String v = u.replace('v','i');
  64.         String w = v.replace('w','j');
  65.         String x = w.replace('x','k');
  66.         String y = x.replace('y','l');
  67.         String encoded = y.replace('z','m');
  68.         System.out.println(encoded);               */
  69.     }
  70.  
  71.     public static void Decrypt ()  //
  72.     {
  73.         char[] x;
  74.         x = Original.toCharArray();
  75.         char c = 'N';
  76.         x[0] += (26-c);
  77.         if (c>'Z') {
  78.             c-=26;
  79.         }
  80.  /*     String a1 = Original.replace('n','a');
  81.         String b1 = a1.replace('o','b');
  82.         String c1 = b1.replace('p','c');
  83.         String d1 = c1.replace('q','d');
  84.         String e1 = d1.replace('r','e');
  85.         String f1 = e1.replace('s','f');
  86.         String g1 = f1.replace('t','g');
  87.         String h1 = g1.replace('u','h');
  88.         String i1 = h1.replace('v','i');
  89.         String j1 = i1.replace('w','j');
  90.         String k1 = j1.replace('x','k');
  91.         String l1 = k1.replace('y','l');
  92.         String m1 = l1.replace('z','m');
  93.         String n1 = m1.replace('a','n');
  94.         String o1 = n1.replace('b','o');
  95.         String p1 = o1.replace('c','p');
  96.         String q1 = p1.replace('d','q');
  97.         String r1 = q1.replace('e','r');
  98.         String s1 = r1.replace('f','s');
  99.         String t1 = s1.replace('g','t');
  100.         String u1 = t1.replace('h','u');
  101.         String v1 = u1.replace('i','v');
  102.         String w1 = v1.replace('j','w');
  103.         String x1 = w1.replace('k','x');
  104.         String y1 = x1.replace('l','y');
  105.         String decoded = y1.replace('m','z');
  106.         System.out.println(decoded);             */
  107.     }
  108.  
  109. }
Add Comment
Please, Sign In to add comment