Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package encryptionprogram;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author Elliott Cade
- */
- public class EncryptionProgram
- {
- public static void main(String[] args)
- {
- // TODO code application logic here
- Scanner sc = new Scanner(System.in);
- String plainText, encryptedText, decryptedText, asciiValue, ASCII;
- System.out.print("Enter message: ");
- plainText = sc.nextLine(); //takes user input
- asciiValue= plainText;
- System.out.println();
- System.out.println("Encrypted message");
- encryptedText = EncryptCharacter(asciiValue);
- System.out.println(encryptedText); //disregard
- System.out.println();
- System.out.println("Decrypted message:");
- decryptedText = DecryptMessage(encryptedText); //disregard
- System.out.println(decryptedText);
- ASCII = EncryptCharacter(asciiValue);
- }
- public static String EncryptMessage(String plainText)
- {
- encryptedMsg =
- { //disregard all
- }
- {
- encryptedChar = EncryptCharacter(plainText.charAt(i));
- encryptedMsg = encryptedMsg + encryptedChar;
- }
- Return encryptedMsg
- }
- public static String DecryptMessage(String encryptedText)
- { String decryptedMsg,encryptedLetter;
- decryptedMsg = “”
- for each group of 4 characters character in encryptedText
- {
- encryptedLetter = encryptedText.substring 4 characters
- decryptedChar = DecryptCharacter(encryptedLetter);
- encryptedMsg = encryptedMsg + decryptedChar;
- }
- return decryptedMsg;
- }
- private static String EncryptCharacter(String asciiValue)
- {
- char[] chars = asciiValue.toCharArray();
- StringBuilder hex = new StringBuilder();
- for (int i = 0; i < chars.length; i++) //takes input and converts it to hex format
- hex.append(Integer.toHexString((int) chars[i]));
- System.out.println();
- {
- }
- return hex.toString();
- }
- public static char DecryptCharacter(String encryptedCharacter)
- {
- // You need to implement this function
- decryptedChar = char1 + char3
- ASCIICode = convert hexadecimal decryptedChar to an ASCII decimal code
- decryptedChar = convert ASCII code to a character
- return decryptedChar;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement