-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.java
More file actions
53 lines (51 loc) · 1.33 KB
/
Encryption.java
File metadata and controls
53 lines (51 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
public class Encryption
{
public static String decrypt(int shift,String code)
{
String ptext="";
code=code.toUpperCase().trim().replace(" ","");
for(int i=0;i<code.length();i++)
{
char ch=code.charAt(i);
ptext=ptext+decrypt(ch,shift);
}
ptext=ptext.replaceAll("QQ"," ").trim();
return ptext;
}
public static char decrypt(char c,int shift)
{
char alpha[]=new char[27];
char beta[]=new char[27];
int k=shift;
char c2=' ';
for(int i=0;i<26;i++)
{
alpha[i+1]=(char)(65+i);
}
int h=1;
for(;k<beta.length;h++)
{
beta[k++]=alpha[h];
}
for(k=1;k<shift;h++)
{
beta[k++]=alpha[h];
}
for(int i=1;i<beta.length;i++)
{
if(beta[i]==c)
c2=alpha[i];
}
return c2;
}
public static void main(String args[])
{
System.out.println("DECRYPTOR");
System.out.print("Shift value [int] ->");
int shift=new Scanner(System.in).nextInt();
System.out.print("Encrypted text [string] ->");
String str=new Scanner(System.in).nextLine();
System.out.println("Decrypted Text = "+decrypt(shift,str));
}
}