Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- /**
- * Salamencizoric code is where 'A' becomes 'Z', 'B' becomes 'Y' and so on.
- * I thank my friends from the Tech & Code room for helping me to shorten this program.
- * @author Salamencizer
- * @version 6/14/2015
- */
- class o_O /*Credits to xfix for the class name*/
- {
- public static void main()throws IOException
- {
- InputStreamReader read = new InputStreamReader(System.in);
- BufferedReader in = new BufferedReader(read);
- boolean baba=false;
- long shut_up=1;
- do
- {
- String sent="",cord="";
- System.out.print("\u000c");
- System.out.println("-----------------------------------------------------");
- System.out.println("Welcome to the code generator. What do you wanna do? |");
- System.out.println("-----------------------------------------------------");
- System.out.println(" ---->Transform a sentence to a code\tEnter transform");
- System.out.println("");
- System.out.println(" ---->Decode a code sentence \tEnter Decode");
- System.out.println("");
- char wtd= ((in.readLine()).toUpperCase()).charAt(0);
- if(wtd=='T')
- {
- System.out.println("Enter the sentence to be transformed. (EVERTHING MUST BE CAPS)");
- sent=in.readLine();
- cord=encrypt(sent);
- System.out.println(" *****Transformation completed!! The code is: *****");
- System.out.println(cord);
- }
- else if(wtd=='D')
- {
- System.out.println("Enter the sentence to be decoded. (EVERTHING MUST BE CAPS)");
- sent=in.readLine();
- cord=encrypt(sent);
- System.out.println(" *****Decoding completed!! The code is: *****");
- System.out.println(cord);
- }
- else
- {
- System.out.println("Sorry, enter something valid!!");
- }
- System.out.println("Repeat the program??\t\t\t Y/N/y/n/yep/yeah/no/yes/nope/neva");
- char yn=in.readLine().charAt(0);
- if(yn=='Y'||yn=='y')
- {
- shut_up++;
- baba=true;
- }
- else
- baba=false;
- System.out.print("\u000c");
- }
- while(baba);
- System.out.println("You have used this program "+shut_up+" times.");
- System.out.println("Thanks for using this program.");
- }
- private static String encrypt(String senti)
- {
- String sent="";
- senti=senti.toUpperCase();
- char[] a=new char[26];
- char[] b=new char[26];int l=0;
- for(int i=0;i<26;i++)
- a[i]=(char)(i+65);
- for(int i=(int)'Z';i>=(int)'A';i--)
- {
- b[l]=(char)i;
- l++;
- }
- for(int i=0;i<senti.length();i++)
- if('A' <= senti.charAt(i) && senti.charAt(i) <= 'Z')
- {
- for(int j=0;j<=25;j++)
- if(senti.charAt(i)==a[j])
- sent=sent+b[j];
- }
- else
- sent=sent+senti.charAt(i);
- return sent;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement