Advertisement
Guest User

Encrypter #2

a guest
Jun 21st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. import java.io.*;
  2. public class GooseSalam_Encrypter
  3. {
  4.     public static void main()throws IOException
  5.     {
  6.         InputStreamReader read = new InputStreamReader(System.in);
  7.         BufferedReader in = new BufferedReader(read);
  8.         boolean baba=false;
  9.         long name=1;
  10.         do
  11.         {
  12.             String sent="",cord="";
  13.             System.out.print("\u000c");
  14.             System.out.println("-----------------------------------------------------");
  15.             System.out.println("Welcome to the code generator. What do you wanna do? |");
  16.             System.out.println("-----------------------------------------------------");
  17.             System.out.println(" ---->Transform a sentence to a code\tEnter transform");
  18.             System.out.println("");
  19.             System.out.println(" ---->Decode a code sentence        \tEnter Decode");
  20.             System.out.println("");
  21.             char wtd= ((in.readLine()).toUpperCase()).charAt(0);
  22.             if(wtd=='T')
  23.             {
  24.                 System.out.println("Enter the sentence to be transformed. (EVERTHING MUST BE CAPS)");
  25.                 sent=in.readLine();
  26.                 cord=encrypt(sent);
  27.                 System.out.println(" *****Transformation completed!! The code is: *****");
  28.                 System.out.println(cord);
  29.             }
  30.             else if(wtd=='D')
  31.             {
  32.                 System.out.println("Enter the sentence to be decoded. (EVERTHING MUST BE CAPS)");
  33.                 sent=in.readLine();
  34.                 cord=encrypt(sent);
  35.                 System.out.println(" *****Decoding completed!! The code is: *****");
  36.                 System.out.println(cord);
  37.             }
  38.             else
  39.             {
  40.                 System.out.println("Sorry, enter something valid!!");
  41.             }
  42.             System.out.println("Repeat the program??\t\t\t    Y/N/y/n/yep/yeah/no/yes/nope/neva");
  43.             char yn=in.readLine().charAt(0);
  44.             if(yn=='Y'||yn=='y')
  45.             {
  46.                 name++;
  47.                 baba=true;
  48.             }
  49.             else
  50.                 baba=false;
  51.             System.out.print("\u000c");
  52.         }
  53.         while(baba);
  54.         System.out.println("You have used this program "+name+" times.");
  55.         System.out.println("Thanks for using this program.");
  56.     }
  57.  
  58.     private static String encrypt(String sent)
  59.     {
  60.         sent=sent.toUpperCase();
  61.         char a[]=new char[26];
  62.         char b[]=new char[26];int k=65;
  63.         String news="";
  64.         for(int i=0;i<26;i++,k++)
  65.             a[i]=(char)k;
  66.         k=(int)'N';
  67.         for(int i=0;i<13;i++,k++)
  68.             b[i]=(char)k;
  69.         k=(int)'A';
  70.         for(int i=13;i<26;i++,k++)
  71.             b[i]=(char)k;
  72.         for(int i=0;i<sent.length();i++)
  73.         {
  74.             char t=sent.charAt(i);
  75.             if(Character.isLetter(t))
  76.             {
  77.                 for(int j=0;j<=25;j++)
  78.                     if(t==a[j])
  79.                         news=news+b[j];
  80.             }
  81.             else
  82.                 news=news+t;
  83.         }
  84.         return news;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement