123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package NS1;
- import java.util.Scanner;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Mohit Lokhande
- */
- public class NS1 {
- public static void main(String []args) {
-
-
- @SuppressWarnings("resource")
- Scanner in = new Scanner(System.in);
- String input;
-
- int key;
- String lib = "0123456789";
- char[] stringtoarray = lib.toCharArray();
-
- System.out.println("ENTER THE STRING YOU WANT TO ENCRYPT:");
-
- input = in.nextLine();
- char[] cipher = input.toCharArray();
-
-
-
- System.out.println("\nENTER THE KEY:");
- key = Integer.parseInt(in.nextLine());
-
-
-
-
- //for encryption
- System.out.println("\nENCRYPTED TEXT IS:");
- for(int i = 0; i< cipher.length; i++)
- {
- for(int j = 0; j< stringtoarray.length; j++)
- {
- if (cipher[i] == stringtoarray[j])
- {
- cipher[i] = stringtoarray[(j + key) % 10];
- break;
- }
-
- }
- System.out.print(cipher[i]);
- }
-
-
-
-
- //for decryption
- System.out.println("\n\nDECRYPTED TEXT OR COMBINATION IS:");
- for(int k=0;k<36;k++)
- {
- for(int i=0;i<cipher.length;i++)
- for (int j = 0; j < stringtoarray.length; j++)
- if(cipher[i]==stringtoarray[j])
- {
- System.out.print(stringtoarray[(j+k)%10]);
- break;
- }
- System.out.println("\t");
- }
-
-
-
- }
-
- }
|