-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesarCipher.java
More file actions
32 lines (29 loc) · 824 Bytes
/
CaesarCipher.java
File metadata and controls
32 lines (29 loc) · 824 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
import java.io.*;
import java.util.*;
import javax.swing.*;
class CaesarCipher
{
public static String displayMessageBox()
{
String response = JOptionPane.showInputDialog(null,
"Enter the string to be encoded", "Enter String", 3);
return response;
}
public static void displayEncryptedString(String output)
{
JOptionPane.showMessageDialog(null,output);
}
public static void main(String [] args)
{
String input=displayMessageBox();
Random rndm_method = new Random();
int shift=rndm_method.nextInt(26);
char[] myNameChars = input.toCharArray();
for(int i=0;i<input.length();i++)
{
myNameChars[i] = (char)((myNameChars[i] + shift - (int)'a') % 26 + (int)'a');
}
String output = String.valueOf(myNameChars);
displayEncryptedString(output);
}
}