-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordTest.java
47 lines (39 loc) · 1.52 KB
/
PasswordTest.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
/**
* PasswordTest.java
* @author Sammy Lincroft
* @date 9/27/17
* a driver class for testing the Vigenere class
* uses a snazzy GUI!
* */
//import the JOptionPane to allow for GUI (see main method)
import javax.swing.JOptionPane;
public class PasswordTest{
/**
* method main
* instanciates and tests out a Vigenere cypher
* */
public static void main(String args[]){
//declare private variables
String message, key, encrypted, decrypted;
int decrypt;
// ask the user what they would like to encrypt and what password they would like to use
message = JOptionPane.showInputDialog("Enter the message to be encrypted:");
key = JOptionPane.showInputDialog("Enter your password:");
//create a new Vigenere cypher with the users settings
Vigenere mySecret = new Vigenere(message, key);
//encrypt the message and store it in encrypted
mySecret.encrypt();
encrypted = mySecret.toString();
//print encrypted to the terminal and the GUI
System.out.println(encrypted);
JOptionPane.showMessageDialog(null, encrypted);
//ask if the user would like to decrypt the message
decrypt = JOptionPane.showConfirmDialog(null, "Do you want it decrypted?");
//if they would print the decrypted message to the GUI and the terminal
if(decrypt == JOptionPane.YES_OPTION){
decrypted = mySecret.decrypt();
System.out.println(decrypted);
JOptionPane.showMessageDialog(null, decrypted);
}
}
}