Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package encryptionprogram;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author Elliott Cade
  14. */
  15. public class EncryptionProgram
  16. {
  17.  
  18. public static void main(String[] args)
  19. {
  20. // TODO code application logic here
  21. Scanner sc = new Scanner(System.in);
  22. String plainText, encryptedText, decryptedText, asciiValue, ASCII;
  23.  
  24. System.out.print("Enter message: ");
  25. plainText = sc.nextLine(); //takes user input
  26. asciiValue= plainText;
  27.  
  28. System.out.println();
  29. System.out.println("Encrypted message");
  30. encryptedText = EncryptCharacter(asciiValue);
  31. System.out.println(encryptedText); //disregard
  32. System.out.println();
  33.  
  34. System.out.println("Decrypted message:");
  35. decryptedText = DecryptMessage(encryptedText); //disregard
  36. System.out.println(decryptedText);
  37. ASCII = EncryptCharacter(asciiValue);
  38. }
  39.  
  40. public static String EncryptMessage(String plainText)
  41. {
  42.  
  43. encryptedMsg =
  44.  
  45. { //disregard all
  46.  
  47.  
  48. }
  49. {
  50. encryptedChar = EncryptCharacter(plainText.charAt(i));
  51. encryptedMsg = encryptedMsg + encryptedChar;
  52. }
  53. Return encryptedMsg
  54. }
  55.  
  56.  
  57.  
  58. public static String DecryptMessage(String encryptedText)
  59. { String decryptedMsg,encryptedLetter;
  60.  
  61. decryptedMsg = “”
  62. for each group of 4 characters character in encryptedText
  63. {
  64. encryptedLetter = encryptedText.substring 4 characters
  65. decryptedChar = DecryptCharacter(encryptedLetter);
  66. encryptedMsg = encryptedMsg + decryptedChar;
  67. }
  68. return decryptedMsg;
  69.  
  70. }
  71.  
  72. private static String EncryptCharacter(String asciiValue)
  73. {
  74.  
  75. char[] chars = asciiValue.toCharArray();
  76. StringBuilder hex = new StringBuilder();
  77. for (int i = 0; i < chars.length; i++) //takes input and converts it to hex format
  78. hex.append(Integer.toHexString((int) chars[i]));
  79. System.out.println();
  80. {
  81.  
  82. }
  83. return hex.toString();
  84.  
  85.  
  86. }
  87.  
  88. public static char DecryptCharacter(String encryptedCharacter)
  89. {
  90. // You need to implement this function
  91.  
  92.  
  93.  
  94. decryptedChar = char1 + char3
  95. ASCIICode = convert hexadecimal decryptedChar to an ASCII decimal code
  96. decryptedChar = convert ASCII code to a character
  97. return decryptedChar;
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement