Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class JavaProject
- {
- public static String Original;
- public static void main(String args[]) // Patrick
- {
- 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'.");
- System.out.println("");
- System.out.println("Enter a word or phrase");
- Original=Expo.enterString();
- Original.toUpperCase();
- JavaProject.Choose();
- }
- public static void Choose () //
- {
- System.out.println("");
- System.out.println("Do you want to encrypt or decrypt?");
- String choice = Expo.enterString();
- System.out.println();
- if(choice.equals("encrypt")) {
- JavaProject.Encrypt(); }
- else if (choice.equals("decrypt")) {
- JavaProject.Decrypt(); }
- else {System.out.println("Invalid response. Please use either 'encrypt' or 'decrypt'.");
- JavaProject.Choose();
- }
- }
- public static void Encrypt () //
- {
- char[] x;
- x = Original.toCharArray();
- char c = 'N';
- x[0] += (26-c);
- if (c>'Z') {
- c-=26;
- }
- /* String a = Original.replace('a','n');
- String b = a.replace('b','o');
- String c = b.replace('c','p');
- String d = c.replace('d','q');
- String e = d.replace('e','r');
- String f = e.replace('f','s');
- String g = f.replace('g','t');
- String h = g.replace('h','u');
- String i = h.replace('i','v');
- String j = i.replace('j','w');
- String k = j.replace('k','x');
- String l = k.replace('l','y');
- String m = l.replace('m','z');
- String n = m.replace('n','a');
- String o = n.replace('o','b');
- String p = o.replace('p','c');
- String q = p.replace('q','d');
- String r = q.replace('r','e');
- String s = r.replace('s','f');
- String t = s.replace('t','g');
- String u = t.replace('u','h');
- String v = u.replace('v','i');
- String w = v.replace('w','j');
- String x = w.replace('x','k');
- String y = x.replace('y','l');
- String encoded = y.replace('z','m');
- System.out.println(encoded); */
- }
- public static void Decrypt () //
- {
- char[] x;
- x = Original.toCharArray();
- char c = 'N';
- x[0] += (26-c);
- if (c>'Z') {
- c-=26;
- }
- /* String a1 = Original.replace('n','a');
- String b1 = a1.replace('o','b');
- String c1 = b1.replace('p','c');
- String d1 = c1.replace('q','d');
- String e1 = d1.replace('r','e');
- String f1 = e1.replace('s','f');
- String g1 = f1.replace('t','g');
- String h1 = g1.replace('u','h');
- String i1 = h1.replace('v','i');
- String j1 = i1.replace('w','j');
- String k1 = j1.replace('x','k');
- String l1 = k1.replace('y','l');
- String m1 = l1.replace('z','m');
- String n1 = m1.replace('a','n');
- String o1 = n1.replace('b','o');
- String p1 = o1.replace('c','p');
- String q1 = p1.replace('d','q');
- String r1 = q1.replace('e','r');
- String s1 = r1.replace('f','s');
- String t1 = s1.replace('g','t');
- String u1 = t1.replace('h','u');
- String v1 = u1.replace('i','v');
- String w1 = v1.replace('j','w');
- String x1 = w1.replace('k','x');
- String y1 = x1.replace('l','y');
- String decoded = y1.replace('m','z');
- System.out.println(decoded); */
- }
- }
Add Comment
Please, Sign In to add comment