Question

In: Computer Science

This is an Intro to Java Question, Please respond with code and pseudocode. Problem 3: RSA...

This is an Intro to Java Question, Please respond with code and pseudocode.

Problem 3: RSA Private Key (10 points) (Cyber Security)

In the RSA algorithm, encrypting and decrypting a message is done using a pair of numbers that are multiplicative inverses with respect to a carefully selected modulus. In this task, you must calculate the modular multiplicative inverse for given set of values. What is the Modular Multiplicative Inverse? In mathematics, each operation typically has an inverse. For example, the inverse of multiplication is division and the inverse of addition is subtraction. Likewise, modulus has an inverse expression. The basic expression given is: Solve for x, Given an integer a and modulo m where ax % m = 1 . However, solving for x is not a trivial task. One naive approach is to bruteforce a solution for x by simply trying each number starting at 1 until a solution is found that makes the expression true.

Facts

● Solve for x, when (a*x) % m == 1 and where a and m are given.

● Use a Brute force approach: First try 1 for x, and check for validity. if invalid then continue to increase x until you find a valid value for x that makes the expression true.

● Consider using long data types instead of int

Input

first line of input is the number of test cases. Each line thereafter, consists of two positive long integer inputs. The first represents the integer a, the second represents the modulo m.

Output Your program should print the value of x that makes the Modular Multiplicative Inverse expression true.

Sample Input

3

17 20

3 7

131101 524269

Sample Output

13

5

229125

Solutions

Expert Solution

PseudoCode:

Input t

Input a,m

Initialize x=1

while loop(infinite)

if a*x % m==1

break the loop

store x in an array ans

for i in ans

print i

Solution:

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
       System.out.print("Enter number of test cases:");
      
       //Scanning input
       int t=in.nextInt();
       long ans[]=new long[t];
       int j=0;
      
       while(t!=0)
       {
       long a=in.nextLong();
       long m=in.nextLong();
      
       int x=1;
       while(true)
       {
       //Checking for condition
       if((a*x)%m==1)
       break;
       x++;
       }
       //Storing x
       ans[j]=x;
       j=j+1;
       t--;
       }
       System.out.println();
       //Printing x for each case
       for(long i:ans)
       System.out.println(i);
      
   }
}

Output:


Related Solutions

This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA Public Key (10 points) (Cyber Security) RSA is an asymmetric encryption scheme, where a public key is used to encrypt data and a different, private key decrypts that data. RSA public/private keys are generated from two prime numbers, typically very large ones. The idea behind RSA is based on the fact that its difficult to factorize very large integers. RSA public key generation is...
This is an intro to java question. Please post with pseudocode and java code. Problem should...
This is an intro to java question. Please post with pseudocode and java code. Problem should be completed using repetition statements like while and selection statements. Geometry (10 points) Make API (API design) Java is an extensible language, which means you can expand the programming language with new functionality by adding new classes. You are tasked to implement a Geometry class for Java that includes the following API (Application Programming Interface): Geometry Method API: Modifier and Type Method and Description...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem 4: Player Move Overworld (10 points) (Game Development) You're the lead programmer for an indie game studio making a retro-style game called Zeldar. You've been tasked to implement the player movement. The game is top-down, with the overworld modeled as a 2d grid. The player's location is tracked by x,y values correlating to its row and column positions within that grid. Given the current...
Intro to java Problem, Please provide code and Pseudocode. Not able to compile correct numbers. Problem...
Intro to java Problem, Please provide code and Pseudocode. Not able to compile correct numbers. Problem 7: Simple Calculator (10 points) (General) Calculators represent the most basic, general-purpose of computing machines. Your task is to reduce your highly capable computer down into a simple calculator. You will have to parse a given mathematical expression, and display its result. Your calculator must support addition (+), subtraction (-), multiplication (*), division (/), modulus(%), and exponentiation (**). Facts ● Mathematical expressions in the...
Intro to Java Question. Please Provide code and pseudocode for understanding. Not receiving correct results currently....
Intro to Java Question. Please Provide code and pseudocode for understanding. Not receiving correct results currently. Problem 5: Player Move Dungeon (10 points) (Game Development) You're the lead programmer at a AAA studio making a sequel to the big hit game, Zeldar 2. You've been challenged to implement player movement in dungeons. The game is top-down, with dungeons modeled as a 2d grid with walls at the edges. The player's location is tracked by x,y values correlating to its row...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better understanding. We are mainly using basic in and out declarations and are focusing on API for method invocations. Any help would be very appreciated :) Problem 7: Distance (10 points) Use API (Data Science) Data Science is an emergent field from Computer Science with applications in almost every domain including finances, medical research, entertainment, retail, advertising, and insurance. The role of a data analyst...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a method to test if a LinkedList<Long> has Long values that form a Fibonacci sequence from the beginning to the end and return true if it is and false otherwise. A sequence of values is Fibonnaci if every third value is equal to sum of the previous two. Eg., 3,4,7,11,18,29 is a Fibonacci sequence whereas 1,2,3,4 is not, because 2+3 is not equal to 4....
(I AM IN A INTRO TO PROGRAMMING, PLEASE USE SIMPLE PSEUDOCODE IF POSSIBLE) Create pseudocode for...
(I AM IN A INTRO TO PROGRAMMING, PLEASE USE SIMPLE PSEUDOCODE IF POSSIBLE) Create pseudocode for a program for Hansel's Housecleaning Service. The program prompts the user for a customer's last name only. While the last name is not “zzz” your program will ask for the number of bathrooms and the number of other rooms to be cleaned and display the cleaning charge. You should use a sentinel-controlled while loop in your main loop logic. A customer name of “zzz”...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import the required classes import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BirthdayReminder {       public static void main(String[] args) throws IOException {        // declare the required variables String sName = null; String names[] = new String[10]; String birthDates[] = new String[10]; int count = 0; boolean flag = false; // to read values from the console BufferedReader dataIn = new BufferedReader(new...
Please can I get a flowchart and pseudocode for this java code. Thank you. TestScore.java import...
Please can I get a flowchart and pseudocode for this java code. Thank you. TestScore.java import java.util.Scanner; ;//import Scanner to take input from user public class TestScore {    @SuppressWarnings("resource")    public static void main(String[] args) throws ScoreException {//main method may throw Score exception        int [] arr = new int [5]; //creating an integer array for student id        arr[0] = 20025; //assigning id for each student        arr[1] = 20026;        arr[2] = 20027;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT