Question

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.

Homework Answers

Answer #1

import java.util.*;
import java.lang.*;
class Main
{

public static void main (String[]args)
{

Scanner sc = new Scanner (System.in);

String s = "";

s = s + sc.nextLine ();

String inp = "";

int i = 0;

for (i = 0; i < s.length (); i++)

{

   if (s.charAt (i) >= 'A' && s.charAt (i) <= 'Z')

   {

   inp += s.charAt (i);

   }

}
int l=inp.length();
int siz=l/5;
if(l%5!=0)
siz++;
String[] out=new String[siz];
for(i=0;i<siz;i++)
out[i]="";
for(i=0;i<l;i++)
{
int tmp=inp.charAt(i)-'A';
String teemp=String.valueOf(tmp);
teemp=teemp+" ";
out[i/5]+=teemp;
}
for(i=0;i<siz;i++)
System.out.println(out[i]);
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Vigenère Cipher. In the Vigenère Cipher, we use a special keyword to encrypt a message. We...
Vigenère Cipher. In the Vigenère Cipher, we use a special keyword to encrypt a message. We represent each letter of the alphabet as a number from 0-25. In order, we add each letter from the keyword to the message and mod by 26. If the keyword is shorter than the message, we simply repeat the keyword. For example, lets say that the message is HOWSTUFFWORKS and the keyword is CIPHER. The following table shows how we can find the final...
Using One-Time Pad Encryption, encrypt the message "JELLO" with one time pad key "YMCKM". Use the...
Using One-Time Pad Encryption, encrypt the message "JELLO" with one time pad key "YMCKM". Use the resultant cipher (from above step) and the one time pad key (pre-shared "YMCKM") to get the plain text.
Program using java !! Create two files, file1.csv and file2.csv Write the following information in file1.csv:...
Program using java !! Create two files, file1.csv and file2.csv Write the following information in file1.csv: Apple 1.69 001 Banana 1.39 002 Write the following information in file2.csv: Apple 1.69 001 Carrot 1.09 003 Beef 6.99 004 You have two files, both of the two files have some information about products: • Read these two files, find out which products exist in both files, and then save these products in a new file. You can use the two files you...
What role could the governance of ethics have played if it had been in existence in...
What role could the governance of ethics have played if it had been in existence in the organization? Assess the leadership of Enron from an ethical perspective. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among the top Fortune 500 companies, collapsed in 2001 under a mountain of debt...
Discuss ethical issues that can be identified in this case and the mode of managing ethics...
Discuss ethical issues that can be identified in this case and the mode of managing ethics Enron finds itself in this case. How would you describe the ethical culture and levels of trust at Enron? Provide reasons for your assessment. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT