-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtbashCipher.java
47 lines (41 loc) · 948 Bytes
/
AtbashCipher.java
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
import java.util.Scanner;
public class AtbashCipher {
static String encrypt(String pt) {
int a,i;
char ch;
char[] encpt1 = pt.toCharArray();
for(i=0;i<pt.length();i++) {
a=encpt1[i];
a=91-(a-64);
ch=(char) a;
encpt1[i]=ch;
}
String encpt2 = new String(encpt1);
return encpt2;
}
static String decrypt(String encpt) {
int a,i;
char ch;
char[] decpt1 = encpt.toCharArray();
for(i=0;i<encpt.length();i++) {
a=decpt1[i];
a=91-a+64;
ch=(char) a;
decpt1[i]=ch;
}
String decpt2 = new String(decpt1);
return decpt2;
}
public static void main(String[] args) {
String pt,encpt,decpt;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter plaintext :");
pt=scanner.nextLine();
encpt=encrypt(pt);
System.out.println("Encrypted text :");
System.out.println(encpt);
decpt=decrypt(encpt);
System.out.println("Decrypted text :");
System.out.println(decpt);
}
}