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 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...
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;...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your own words)
JAVA ONLY. Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source...
JAVA ONLY. Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs. Note: for C++, #include and then...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack that implements a stack using the fact that you have access to a queue data structure with operations enqueue(), dequeue(), isEmpty(). Remember that every stack should have the operations push() and pop(). Hint: use two queues, one of which is the main one and one is temporary. Please note that you won’t be able to implement both push() and pop() in constant time. One...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT