Guest User

CryptClient

a guest
Oct 20th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. public class CryptClient {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner inScan = new Scanner(System.in);
  8. System.out.println("Please enter d for decryption or e for encryption");
  9. String encrypt = inScan.nextLine();
  10. if (encrypt.equalsIgnoreCase("e")){
  11.  
  12.  
  13. System.out.println("Enter the encryption password: ");
  14. // They can choose to encrypt using Inconceivable OR JogHimTooHard
  15. // This way it has preset shifts and can be accessed using the preset passwords
  16. String password = inScan.nextLine();
  17. Crypto C1 = new Crypto(password);
  18. System.out.println("Please enter the file name (including extension): ");
  19. String F1 = inScan.nextLine();
  20. F1 = new String(F1);
  21.  
  22. tryEncrypt(F1, C1);
  23. }
  24. if (encrypt.equalsIgnoreCase("d")){
  25.  
  26. System.out.println("Enter the password to decrypt: ");
  27. String password = inScan.nextLine();
  28. Crypto C1 = new Crypto(password);
  29. System.out.println("Please enter the file name (including extension): ");
  30. String F1 = inScan.nextLine();
  31. F1 = new String(F1);
  32.  
  33. tryDecrypt(F1, C1);
  34.  
  35. }
  36.  
  37. }
  38.  
  39.  
  40.  
  41. public static void tryEncrypt(String file, Crypto agent)
  42. {
  43. // Your Crypto class must have a public method "encryptFile()". This method
  44. // takes a file name (String) as an argument and makes an encrypted version
  45. // of that file with extension ".cyp". The method should return a boolean
  46. // result -- true if everything worked or false if there was a problem (ex:
  47. // the original file did not exist). See the Assignment sheet for the details
  48. // of how the encryption should be done and the format of the resulting file.
  49. if (agent.encryptFile(file))
  50. {
  51. System.out.println("File " + file + " encrypted successfully");
  52. System.out.println("Encryption agent:\n" + agent.toString());
  53. }
  54. else
  55. {
  56. System.out.println("File " + file + " NOT encrypted");
  57. System.out.println("Encryption agent:\n" + agent.toString());
  58. }
  59. System.out.println();
  60. }
  61.  
  62. public static void tryDecrypt(String file, Crypto agent)
  63. {
  64. // Your Crypto class must have a public method "decryptFile()". This method
  65. // takes a file name (String) as an argument and makes an decrypted version
  66. // of that file, removing the ".cyp" in the name and replacing it with the
  67. // extension ".copy". The method should return a boolean result -- true if
  68. // everything worked or false if there was a problem (ex: the password did
  69. // not match, the file did not have the correct extension). See the Assignment
  70. // sheet for the details of how the decryption should be done.
  71. if (agent.decryptFile(file))
  72. {
  73. System.out.println("File " + file + " decrypted successfully");
  74. System.out.println("Decryption agent\n" + agent.toString());
  75. }
  76. else
  77. {
  78. System.out.println("File " + file + " could not be decrypted");
  79. System.out.println("Decryption agent\n" + agent.toString());
  80. }
  81. System.out.println();
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment