Advertisement
Guest User

Encrypter #1

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