

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


import java.util.Scanner;
public class Encryptor { // necessary declarations or initializations for your program private String plaintext; private char plain_char, cipher_char; // Actual encryption method public void convert() { System.out.println("Enter the plaintext. English Alphabet characters ONLY please."); // Read plaintext from standard input Scanner reader = new Scanner(System.in); plaintext = reader.nextLine(); /* Optional. To check if you got the plaintext correctly, you may display it right here. If you are using a JOptionPane for input, you must display your input somewhere. / / Now, you will process each plaintext letter one by one to encrypt and find the corresponding ciphertext letter. For this, you need to know the length of your arbitrary plaintext. / int text_length = plaintext.length(); // You can calculate the length of // an arbitrary string with the // length() method of String class. // Start processing the plaintext characters for (int i = 0; i < text_length; i++) { plain_char=plaintext.charAt(i); // charAt(position) method returns the character // at a particular position in a given string. cipher_char=findCipher(plain_char); displayCipher(cipher_char); } } private void displayCipher(char ccc) { // Display your ciphertext letters one by one to the standard output } private char findCipher(char pp) { / Find the ciphertext letter counterpart of your input plaintext letter Hint: char is a numerical type. Look up an ASCII character table Then return the ciphertext letter found. */ } } // end of encryptor class
Encryptor myEncryptor = new Encryptor();