Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CryptClient {
- public static void main(String[] args) {
- Scanner inScan = new Scanner(System.in);
- System.out.println("Please enter d for decryption or e for encryption");
- String encrypt = inScan.nextLine();
- if (encrypt.equalsIgnoreCase("e")){
- System.out.println("Enter the encryption password: ");
- // They can choose to encrypt using Inconceivable OR JogHimTooHard
- // This way it has preset shifts and can be accessed using the preset passwords
- String password = inScan.nextLine();
- Crypto C1 = new Crypto(password);
- System.out.println("Please enter the file name (including extension): ");
- String F1 = inScan.nextLine();
- F1 = new String(F1);
- tryEncrypt(F1, C1);
- }
- if (encrypt.equalsIgnoreCase("d")){
- System.out.println("Enter the password to decrypt: ");
- String password = inScan.nextLine();
- Crypto C1 = new Crypto(password);
- System.out.println("Please enter the file name (including extension): ");
- String F1 = inScan.nextLine();
- F1 = new String(F1);
- tryDecrypt(F1, C1);
- }
- }
- public static void tryEncrypt(String file, Crypto agent)
- {
- // Your Crypto class must have a public method "encryptFile()". This method
- // takes a file name (String) as an argument and makes an encrypted version
- // of that file with extension ".cyp". The method should return a boolean
- // result -- true if everything worked or false if there was a problem (ex:
- // the original file did not exist). See the Assignment sheet for the details
- // of how the encryption should be done and the format of the resulting file.
- if (agent.encryptFile(file))
- {
- System.out.println("File " + file + " encrypted successfully");
- System.out.println("Encryption agent:\n" + agent.toString());
- }
- else
- {
- System.out.println("File " + file + " NOT encrypted");
- System.out.println("Encryption agent:\n" + agent.toString());
- }
- System.out.println();
- }
- public static void tryDecrypt(String file, Crypto agent)
- {
- // Your Crypto class must have a public method "decryptFile()". This method
- // takes a file name (String) as an argument and makes an decrypted version
- // of that file, removing the ".cyp" in the name and replacing it with the
- // extension ".copy". The method should return a boolean result -- true if
- // everything worked or false if there was a problem (ex: the password did
- // not match, the file did not have the correct extension). See the Assignment
- // sheet for the details of how the decryption should be done.
- if (agent.decryptFile(file))
- {
- System.out.println("File " + file + " decrypted successfully");
- System.out.println("Decryption agent\n" + agent.toString());
- }
- else
- {
- System.out.println("File " + file + " could not be decrypted");
- System.out.println("Decryption agent\n" + agent.toString());
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment