-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtbash.java
More file actions
42 lines (36 loc) · 887 Bytes
/
Atbash.java
File metadata and controls
42 lines (36 loc) · 887 Bytes
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
//Atbash Cipher
import java.io.*;
import java.util.*;
import javax.swing.*;
class Atbash
{
private static String displayMessageBox()
{
String response = JOptionPane.showInputDialog(null,
"Enter a string", "Atbash Cipher", 3);
return response;
}
private static void displayResultMessage(String input)
{
JOptionPane.showMessageDialog(null, input);
}
private static String Encrypt(String inputString)
{
String ans="";
for(int i=0;i<inputString.length();i++)
{
char charAtIndex=inputString.charAt(i);
int diff=charAtIndex-(int) ('a');
int newdiffer =25-diff;
char toBeInserted= (char)('a'+newdiffer);
ans+=toBeInserted;
}
return ans;
}
public static void main(String [] args)
{
String inputString=displayMessageBox();
String encryptedString=Encrypt(inputString);
displayResultMessage(encryptedString);
}
}