Question

In: Computer Science

Write a Java program to encrypt the following message using the RC4 cipher using key CODES:...

Write a Java program to encrypt the following message using the RC4 cipher using key CODES:

Cryptography is a method of protecting information and communications through the use of codes so that only those for whom the information is intended can read and process it.

Instead of using stream length 256, we will use length 26. When encrypting, let A = 0 to Z = 25 (hence CODES = [2 14 3 4 18]). Ignore spaces and punctuations and put the message in groups of five letters.

Solutions

Expert Solution

For the above problem, we need to have the following things into consideration.

  1. We need to convert each character into a lower case in order to reduce the work to be done.
  2. We need to Get the cryptic version only for the characters, not for the punctuation.

Following is the JAVA program:

import java.util.ArrayList;
import java.util.List;

public class Crypt {
   public static void main(String args[])
   {
       String message = "This is the message";
       List<Integer> crypt = new ArrayList<Integer>();
       for(int i = 0 ; i < message.length(); i++) {
           char current = Character.toLowerCase(message.charAt(i));
           if(current >= 'a' && current <= 'z') {
               crypt.add(current - 'a');
           }
       }
       System.out.print("Printing the Crypt Message: [");
       for(int i = 0 ;i<crypt.size();i++) {
           System.out.print(crypt.get(i) + " " );
       }
       System.out.println("]");
   }

}

In the above program, there is a variable message in which we need to provide the message and then crypt is the list which will store the output.
Following is the output of the above-written program:

That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like if you think effort deserves a like.
Thanks


Related Solutions

Write a small program to encrypt and decrypt a message using Python library.
Write a small program to encrypt and decrypt a message using Python library.
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given...
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given that the Vigenere cipher of part (a) with the same keyword was used to produce the ciphertext: VFPUSVSNBVRCNQW Find the plaintext message.        
how to write program in java for encrypt and decrypt input text using DH algorithm
how to write program in java for encrypt and decrypt input text using DH algorithm
Write a Java program that will encode plain text into cipher text and decode cipher text...
Write a Java program that will encode plain text into cipher text and decode cipher text into plain text. Create following methods and add them to your class: • a method named encode(String p, int key) that takes a plain text p and encodes it to a cipher text by adding the key value to each alphabet character of plain text p using the ASCII chart. The method should return the encoded String. For example, if p = "attack at...
1. Use a Vigenere cipher with a key of "Patton" to encrypt: "If everyone is thinking...
1. Use a Vigenere cipher with a key of "Patton" to encrypt: "If everyone is thinking alike, then somebody isn't thinking." Is this a good key? Why or why not? 2.  Calculate the index of coincidence for the result. SHOW ALL WORK PLEASE
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Part 1: Design a Cipher allow user to use a “key” to encrypt and decrypt the...
Part 1: Design a Cipher allow user to use a “key” to encrypt and decrypt the message. Use at least two ciphers combined to design your own cipher Specify the min. and max. length of the message user can enter to encrypt Specify the length of the “key” user can enter to encrypt and decrypt the message Part 2: Programme the cipher and make it available to validate. Cleartext for the original programming scripts has to submitted. A frontend webpage...
write a Java method that decrypts a keyword columnar transposition cipher with a given key
write a Java method that decrypts a keyword columnar transposition cipher with a given key
write a java program to Translate or Encrypt the given string : (input char is all...
write a java program to Translate or Encrypt the given string : (input char is all in capital letters) { 15 } *) Each character replaced by new character based on its position value in english alphabet. As A is position is 1, and Z is position 26. *) New characters will be formed after skipping the N (position value MOD 10) char forward. A->A+1= B , B->B+2=D ,C->C+3=F, .... Y->Y+(25%10)->Y+5=D A B C D E F G H I...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the console input and create a file. ['$' character denotes end of content in file.] Close the file after creation. Now encrypt the text file using Caesar Cipher (Use key value as 5). Display the contents of the updated file. #include <iostream> using namespace std; int main() { // write code here }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT