Question

In: Computer Science

Write a Java program that uses the RC4 cipher algorithm to encrypt the following message using...

Write a Java program that uses the RC4 cipher algorithm to encrypt the following message using the word CODES as the key:  

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. Ignore spaces and punctuations and put the message in groups of five letters.

Solutions

Expert Solution

First, Let's see how code is encrypted..

Java Code of implementation is given below:

CryptoCode.java file

public class CryptoCode
{
    public static StringBuffer code_encryption(String texttoencrypt, int shiftnumber)
    {
        StringBuffer result= new StringBuffer();

        for (int i=0; i<texttoencrypt.length(); i++)
        {
            if (Character.isUpperCase(texttoencrypt.charAt(i)))
            {
                char character = (char)(((int)texttoencrypt.charAt(i) + shiftnumber - 65) % 26 + 65);
                result.append(character);
            }
            else
            {
                char character = (char)(((int)texttoencrypt.charAt(i) +
                                  shiftnumber - 97) % 26 + 97);
                result.append(character);
            }
        }
        return result;
    }
    public static void main(String[] args)
    {
        String texttoencrypt = "WHATISNEXTMOVE";
        int shiftnumber = 3;
        System.out.println("Command : " + texttoencrypt);
        System.out.println("Shift number : " + shiftnumber);
        System.out.println(code_encryption(texttoencrypt, shiftnumber));
    }
}

Code encryption and decryption ultimately can generate using given formula

Encrypt(n) = DeCrypt(26-n)

Where n is shift-number


Related Solutions

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...
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
Use the Affine cipher algorithm with k1=7,k2=11 to encrypt the following message : I want to...
Use the Affine cipher algorithm with k1=7,k2=11 to encrypt the following message : I want to get a hundred in this test
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.        
1 Introduction A cipher is an algorithm which encrypts a message into cipher text so that...
1 Introduction A cipher is an algorithm which encrypts a message into cipher text so that it can be safely transmitted without an eavesdropper being able to (easily) read it. For the purposes of this assignment the message and ciphertext will be stored as strings of ASCII characters. Cipher algorithms always perform two tasks: encryption and decryption. The encryption process takes a “message” and “key” as inputs and produces cipher text. The decryption process performs the reverse: it turns cipher...
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...
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Assume you need to write a Java program that uses a binary search algorithm to search...
Assume you need to write a Java program that uses a binary search algorithm to search a sorted array for a given value. 1. Write a Java pseudocode that uses recursion to accomplish the task. Here is a hint. When you are searching for a particular value in an array, there are two possible outcomes. 1) The value is found and the array index of that value is returned. 2) The value is not found and we return -1. (5...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT