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.
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str = s.nextLine(); // read the string
String st = ""; // declare empty string
for(int i = 0; i < str.length(); i++)
{
st = st + String.valueOf((int)str.charAt(i) - 65) + " "; //
converting character into ASCII and subtract it by 65
}
System.out.println(st); // print the string
}
}
OUPTUT:
Get Answers For Free
Most questions answered within 1 hours.