Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Module1;
- import java.util.Scanner;
- @interface KakumiriziDaud
- {String name();
- String ID();
- }
- @KakumiriziDaud(name = "Kakumirizi Daud", ID = "17/BSS/BU/R/0010")
- public class Demo1 {
- Scanner in;
- Demo1() {
- in = new Scanner(System.in);
- }
- public void security() {
- System.out.println("Please Enter your text: ");
- String sp = in.nextLine();
- String ss = sp.toLowerCase();
- System.out.println("Please enter your key: ");
- String sy = in.nextLine();
- String sx = sy.toLowerCase();
- System.out.println("1 Encrypt plain text using binary and Or");
- System.out.println("2 Decrypt cipher text using binary and Or");
- System.out.println("0 Exit the program");
- System.out.println("Please enter your menu selection:--------- ");
- int x = in.nextInt();
- String binary1 = " ";
- String binary2 = " ";
- if (x == 1) {
- if(ss.length()==sx.length())
- {
- char [] ch = ss.toCharArray();
- char [] hc = sx.toCharArray();
- System.out.print("You entered: ");
- for (char cc : ch) {
- int i = (int) cc - (int) 'a';
- String binary = Integer.toBinaryString(i);
- System.out.print(cc+" ");
- }
- System.out.println();
- System.gc();
- System.out.print("You key is: ");
- for (char mc : ch) {
- int j = (int) mc - (int) 'a';
- String binary = Integer.toBinaryString(j);
- System.out.print(mc + " ");
- }
- System.out.println();
- }
- else
- {
- System.out.println("The length of strings do not match ");
- while (ss.length() != sx.length())
- return;
- System.exit(0);
- }
- }
- else if (x == 2) {
- // public void dencrypt(){
- System.out.println("I am the decrypt method");
- } else if (x == 0) {
- // public void exit()
- {
- System.exit(0);
- }
- } else {
- System.out.println("Enter one of the value from the list provided");
- }
- System.out.println("Your text in base 10: "+i);
- System.out.println("Your key in base 10: "+j);
- System.out.println("Your text in base 2: "+binary1);
- System.out.println("Your key in base 2: "+binary2);
- System.out.println();
- System.out.println("-------------------------------------------------");
- System.out.println("Your cipher text in plain text: ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement