Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class GooseSalam_Encrypter
- {
- public static void main()throws IOException
- {
- InputStreamReader read = new InputStreamReader(System.in);
- BufferedReader in = new BufferedReader(read);
- boolean baba=false;
- long name=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')
- {
- name++;
- baba=true;
- }
- else
- baba=false;
- System.out.print("\u000c");
- }
- while(baba);
- System.out.println("You have used this program "+name+" times.");
- System.out.println("Thanks for using this program.");
- }
- private static String encrypt(String sent)
- {
- sent=sent.toUpperCase();
- char a[]=new char[26];
- char b[]=new char[26];int k=65;
- String news="";
- for(int i=0;i<26;i++,k++)
- a[i]=(char)k;
- k=(int)'N';
- for(int i=0;i<13;i++,k++)
- b[i]=(char)k;
- k=(int)'A';
- for(int i=13;i<26;i++,k++)
- b[i]=(char)k;
- for(int i=0;i<sent.length();i++)
- {
- char t=sent.charAt(i);
- if(Character.isLetter(t))
- {
- for(int j=0;j<=25;j++)
- if(t==a[j])
- news=news+b[j];
- }
- else
- news=news+t;
- }
- return news;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement