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

Write a java program MyCalendar that outputs a monthly calendar for a given month and year....
Write a java program MyCalendar that outputs a monthly calendar for a given month and year. the output should be looks like this one at the bottom:( I don't know why it doesn't show right but the first day of the month is not Sunday it starts from Wednesday) F. Last’s My Calendar Enter month year? 10 2019 10/2019 Sun Mon Tue Wed Thu Fri Sat --------------------------------- 1 2 3 4 5 6 7 8 9 10  11 12 13 14...
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 'Rectangle-Area.c' that inputs the length and width of a rectangle and outputs its...
Write a program 'Rectangle-Area.c' that inputs the length and width of a rectangle and outputs its area. The program consists of two functions: the main function and a function that computes and returns the area of a rectangle. The output of the program should be in the main program, not in the function.      Sample Input: 5 8   Sample Output: The area of a 5 by 8 rectangle is 40.
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...
Write a program in Java that reads in a set of positive integers and outputs how...
Write a program in Java that reads in a set of positive integers and outputs how many times a particular number appears in the list. You may assume that the data set has at most 100 numbers and -999 marks the end of the input data. The numbers must be output in increasing order. For example, for the data 15 40 28 62 95 15 28 13 62 65 48 95 65 62 65 95 95 -999 The output is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT