Advertisement
kdaud

MyCode

Feb 12th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.21 KB | None | 0 0
  1. package Module1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. @interface KakumiriziDaud
  6. {String name();
  7. String ID();
  8. }
  9. @KakumiriziDaud(name = "Kakumirizi Daud", ID = "17/BSS/BU/R/0010")
  10. public class Demo1 {
  11.  
  12.           Scanner in;
  13.  
  14.           Demo1() {
  15.               in = new Scanner(System.in);
  16.           }
  17.  
  18.         public  void security() {
  19.  
  20.  
  21.             System.out.println("Please Enter your text: ");
  22.             String sp = in.nextLine();
  23.             String ss = sp.toLowerCase();
  24.  
  25.             System.out.println("Please enter your key: ");
  26.             String sy = in.nextLine();
  27.             String sx = sy.toLowerCase();
  28.  
  29.             System.out.println("1  Encrypt plain text using binary and Or");
  30.             System.out.println("2  Decrypt cipher text using binary and Or");
  31.             System.out.println("0  Exit the program");
  32.  
  33.             System.out.println("Please enter your menu selection:--------- ");
  34.  
  35.             int x = in.nextInt();
  36.            
  37.             String binary1 = " ";
  38.             String binary2 = " ";
  39.  
  40.  
  41.             if (x == 1) {
  42.  
  43.                     if(ss.length()==sx.length())
  44.                     {
  45.  
  46.                         char [] ch = ss.toCharArray();
  47.                         char [] hc = sx.toCharArray();
  48.  
  49.  
  50.                         System.out.print("You entered:                ");
  51.                 for (char cc : ch) {
  52.  
  53.                     int i = (int) cc - (int) 'a';
  54.                     String binary = Integer.toBinaryString(i);
  55.                    System.out.print(cc+"     ");
  56.  
  57.                 }
  58.  
  59.                         System.out.println();
  60.                         System.gc();
  61.                         System.out.print("You key is:                 ");
  62.                 for (char mc : ch) {
  63.  
  64.                     int j = (int) mc - (int) 'a';
  65.                     String binary = Integer.toBinaryString(j);
  66.  
  67.                     System.out.print(mc + "     ");
  68.  
  69.                 }
  70.                         System.out.println();
  71.  
  72.                     }
  73.                     else
  74.                     {
  75.                        System.out.println("The length of  strings do not match ");
  76.                        while (ss.length() != sx.length())
  77.                            return;
  78.                         System.exit(0);
  79.                    }
  80.  
  81.  
  82.            }
  83.             else if (x == 2) {
  84.                 // public void dencrypt(){
  85.                 System.out.println("I am the decrypt method");
  86.  
  87.             } else if (x == 0) {
  88.                 // public void exit()
  89.                 {
  90.  
  91.                     System.exit(0);
  92.                 }
  93.             } else {
  94.                 System.out.println("Enter one of the value  from the list provided");
  95.             }
  96.  
  97.  
  98.             System.out.println("Your text in base 10:        "+i);
  99.             System.out.println("Your key in base 10:         "+j);
  100.             System.out.println("Your text in base 2:        "+binary1);
  101.             System.out.println("Your key in base 2:        "+binary2);
  102.             System.out.println();
  103.             System.out.println("-------------------------------------------------");
  104.             System.out.println("Your cipher text in plain text: ");
  105.         }
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement