1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MAVERICK [17]
3 years ago
5

Create an interface MessageDecoder that has a single abstract method decode(cipherText), where cipherText is the message to be d

ecoded. The method will return the decoded message. Modify the classes SubstitutionCipher and ShuffleCipher, as described in Programming Problem 2, above, so that they implement MessageDecoder as well as the interface MessageEncoder described above. Finally, write a program that allows a user to encode and decode messages entered on the keyboard.

Computers and Technology
1 answer:
Nastasia [14]3 years ago
3 0

Answer:

Check the explanation

Explanation:

MessageEncoder. java

public interface MessageEncoder

{

  //single abstract method encode(plainText) where plainText is the message to be encoded.

  public String encode(String plainText);

}//end interface

SubstitutionCipher. java

import java.util.Scanner;

public class SubstitutionCipher implements MessageEncoder, MessageDecoder

{

   /**

     The constructor should have 1 parameter called shift

   */

   private int shift;

 

   /**

     Non-default constructor with one parameter    

   */

   public SubstitutionCipher(int numberSpaces)

   {

       shift = numberSpaces;

   }//end non default constructor

 

   /**

     Define the method encode so that each letter is shifted by the value in shift

   */

   public String encode(String plainText)

   {

       String cipherText = "";

       for(int i = 0; i < plainText. length(); i++)

       {

           Character encodeLetter = plainText.charAt(i);

           cipherText = cipherText + shift1Character(encodeLetter);

       }//end for loop

       return cipherText;

   }//end encode method

 

   /**

     Define the method decode so that each letter is shifted by minus the value in shift

   */

   public String decode(String cipherText)

   {

       String plainText = "";

       for(int i = 0; i < cipherText. length(); i++)

       {

           Character decodeLetter = cipherText.charAt(i);

           plainText = plainText + shift1CharacterBack(decodeLetter);

       }//end for loop

       return plainText;

   }//end encode method

   /**

     Hint: You may wish to define a private method that shifts a single character

   */

   private Character shift1Character(Character oneLetter)

   {

       return (char)(oneLetter + shift);

   }//end method

 

   /**

     Hint: You may wish to define a private method that shifts a single character

           back to its original position

   */

   private Character shift1CharacterBack(Character oneLetter)

   {

       return (char)(oneLetter - shift);

   }//end method

 

////////////////////////////////////////////////////////////////////////////////////////////////////////

   public static void main(String[] args)

   {

       Scanner keyboard = new Scanner(System.in);

       SubstitutionCipher shift3Places = new SubstitutionCipher(3);

       System.out.println("Substituation method using caesar shift: \n");

       String plainText = "I think I am finally back on track\n";

       System.out.println("Plain text to be encoded: " + plainText);

     

       String cipher = shift3Places.encode(plainText);

       System.out.println("Cipher text after encoding: " + cipher);

     

       SubstitutionCipher shiftMinus3 = new SubstitutionCipher(-3);

       System.out.println("\n\nTime to decode the cipher now.\n");

     

       String decoded = shiftMinus3. encode(cipher);

       System.out.println("Decoded text after removing cipher: " + decoded);

   

       ////////////////////////////////////////////////////////////////////////////System.out.println("Testing the decode method.");

       ////////////////////////////////////////////////////////////////////////////decoded = shift3Places. decode(cipher);

       ////////////////////////////////////////////////////////////////////////////System.out.println("Text after decoding: " + decoded);

   }//end main

}//end class

MessageDecoder. java

public interface MessageDecoder

{

  //single abstract method decode(cipherText) where cipherText is the message to be decoded.

  public String decode(String cipherText);

}//end interface

You might be interested in
Which of the following, (1) money deposited in a bank account, (2) student recording her answer to a question in an online test,
tamaranim1 [39]

An Information System is when key components such as hardware, software, data, and process are combined for collection, processing, and distribution of data. All of these scenarios mentioned on the choices above are considered transactions in an information system. There is an exchange of information that fully satisfies the request of a user and describes what transactions in information systems are. They are good examples of users entering information whether, physically or electronically, as data into computers. This data is then processed, and the database changes adjusted with some being made permanent.

3 0
4 years ago
Make and run a Python program which:
PSYCHO15rus [73]

Answer:

ok

Explanation:

6 0
2 years ago
All organizations with a router at the boundary between the organization’s internal networks and the external service provider w
Anika [276]

Answer:

False

Explanation:

Access Control Lists (ACLs) are network filters used by routers and some switches to permit and restrict data flows in and out of network devices. When an ACL is implemented in a device or interface, the network device analyses data passing through it, compares it to the specification described in the ACL, and allows it the data to flow or prohibits it. One of the main reasons ACLs arre used is to provide a basic level of security for networks. If anything, the use of ACLs and their complexities bring about a delay in transmission through networks.

3 0
3 years ago
152<br>what is the role of Computer as<br>transforming agent in the<br>Information society.​
hichkok12 [17]
I have a question what grade are you in
8 0
3 years ago
What is computer hadware​
Alex Ar [27]

Answer: like the monitor or the keyboard

Explanation: it is true i even looked it up and it was true

8 0
2 years ago
Other questions:
  • Rewrite this method so that it avoids the use of a return statement:
    15·1 answer
  • According to Mintzberg's classification of managerial roles, the role of a(n) ______ is to transmit information received from ou
    7·1 answer
  • You have a Bluetooth headset that integrates with your computer so that you can talk to partners through Microsoft Lync. This is
    6·2 answers
  • What is the name of the port that you plug an ethernet network cable into?
    6·1 answer
  • Which of the following works on the pay-per-click (PPC) and cost-per-click (CPC) concept? ~ Plato
    9·1 answer
  • It is possible to change the shape of a text box.
    10·1 answer
  • Controlling access of information on the internet
    15·1 answer
  • Is Filmora 9 or Final Cut Pro Better for personal use?
    12·1 answer
  • Which of the following ""invisible"" marks represents an inserted tab?
    10·1 answer
  • Examples of system software include operating systems like macos, Linux, Android and
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!