Question

In: Computer Science

Write a Java program for RSA encryption that has the following inputs and outputs: Given a...

Write a Java program for RSA encryption that has the following inputs and outputs: Given a message and an integer n = pq where p and q are odd primes and an integer e > 1 relatively prime to (p − 1)(q − 1), encrypt the message using the RSA cryptosystem with key (n, e).

Solutions

Expert Solution

Answer : Given data

* Step 1

Actually, the given a message and an integer n=pq

Where p and q are odd primes and an integer e>1 relatively prime to (p-1) (q-1)

So, the code has given below:

* Step 2

import java.io.*;
import java.util.*;
class RSATest
{
public static void main(String args[])
{
Scanner ip=new Scanner(System.in);
int p,q,n,e=1,j;
int d=1,msglen;
int t1,t2;
int pt[]= new int[10]; //plain text array
int ct[]= new int[10]; //cipher text array
int rt[]= new int[10]; //unecrypted received text array
String msg=new String();
System.out.println("Enter value of p & q number: ");
p=ip.nextInt();
q=ip.nextInt();
System.out.println("Enter the message: ");
msg=ip.next();
msglen=msg.length();
for(j=0;j<msglen;j++)
{
pt[j]=(msg.charAt(j))-96;
}
n=p*q;
t1=p-1;
t2=q-1;
while((t1*t2)%e==0)
{
e++;
}
for(j=0;j<msglen;j++)
{
ct[j]=((int)Math.pow(pt[j],e))%n;
}
System.out.println("Plaintext Message:");
System.out.println("----------------------");
System.out.println("Public Key(e)= "+e);
for(j=0;j<msglen;j++)
{
System.out.println("Cipher Text= "+ct[j]);
}
System.out.println("Plaintext Message:");
System.out.println("----------------------");
while((d*e)%(t1*t2)!=1)
{
d++;
}
System.out.println("Private Key(d)= "+d);
for(j=0;j<msglen;j++)
{
rt[j]=((int)Math.pow(ct[j],d))%n;
System.out.println("Plaintext Message= "+rt[j]);
}
System.out.print("Decrypted Message:");
for(j=0;j<msglen;j++)
{
rt[j]=rt[j]+96;
System.out.print((char)rt[j]);
}
}
}

* Step 3

* Step 4

__________THE END____________


Related Solutions

in Java Write a function that inputs a 4 digit year and outputs the ROMAN numeral...
in Java Write a function that inputs a 4 digit year and outputs the ROMAN numeral year M is 1,000 C is 100 L is 50 X is 10 I is 1 Test with 2016 and 1989
Write C program for RSA encryption and decryptin, where: p = 11,q = 5, e =...
Write C program for RSA encryption and decryptin, where: p = 11,q = 5, e = 7
Write a program in java that can perform encryption/decryption. In the following let the alphabet A...
Write a program in java that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm:...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9...
CORAL LANGUAGE ONLY Write a program whose inputs are three integers, and whose outputs are the...
CORAL LANGUAGE ONLY Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum The function LargestNumber should return the largest number of the...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
Please perform encryption and decryption given the following values of an RSA public key cryptosystem; p=17,...
Please perform encryption and decryption given the following values of an RSA public key cryptosystem; p=17, q=31, e=7 and M=2
Write a Java program that prompts a user for 10 integers. When completed it outputs the...
Write a Java program that prompts a user for 10 integers. When completed it outputs the highest number, the lowest number, the number of odd number, and the average of the numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT