Here is another example, m = 17, 4 x 13 = 52 = 17 x 3 + 1, so the remainder when 52 is divided by 17 is 1, and thus 13 is the inverse of 4 modulo 17. You are to write a method modularInverse() which accepts as input the two integers x and m,

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Question

In java pls! Thank you!

 

In many cryptographic applications the Modular Inverse is a key operation. This programming problem involves finding the modular inverse of a number.

Given 0 < x < m, where x and m are integers, the modular inverse of x is the unique integer n, 0 < n < m, such that the remainder upon dividing x × n by m is 1. That is, x × n mod m  = 1.

Modular inverse is a concept that extends the arithmetic inverse. For example, the inverse of 2 is ½ because 2 x ½ = 1 with decimal operation. Here the inverse number can be a fraction. 

In modular inverse, we only allow integers, no fraction. So not all integer has an inverse.

For example, m = 26, x = 3, the modular inverse of 3 is 9 because  3 x 9 mod 26 = 1. 

However, m = 26, x = 2, the modular inverse of 2 does not exist because you cannot find a number y so that 2 x y mod 26 = 1.

Here is another example, m = 17, 4 x 13 = 52 = 17 x 3 + 1, so the remainder when 52 is divided by 17 is 1, and thus 13 is the inverse of 4 modulo 17.

You are to write a method modularInverse() which accepts as input the two integers x and m, and outputs either the modular inverse n, or -1 to indicate "No such integer exists." if there is no such integer n.

You may assume that m ≤ 100, x and m non-negative.

public class ModInverse {

    public static void main(String[] args) {

        int m = 26;

        for (int x = 0; x < m; x++) {

            int n = modularInverse(x, m);

            if (n == -1) {

                System.out.println("The modular inverse of x " + x + " does not exit.");

            } else {

                System.out.println("The modular inverse of x " + x + " is: " + n + "for mod " + m);

            }

        }

        //Expect: the mod inverse with mod 26 as follows

        // 1 3 5  7  9 11 15 17 19 21 23 25

        // 1 9 21 15 3 19  7 23 11 5  17 25

    }

 

    public static int modularInverse(int x, int m) {

        //your code

 

        return -1;

    }

}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY