Question

Project 2: The Inverse Modulo n [MOD] Textbook Section: 7.37 Directions: The user will input the modulus п they want to work
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN C++

#include<iostream>

using namespace std;

int GCD(int a, int b, int *x, int *y)

{

  if (a == 0)

  {

    *x = 0, *y = 1;

    return b;

  }

  int x1, y1;

  int gcd = GCD(b%a, a, &x1, &y1);

  *x = y1 - (b/a) * x1;

  *y = x1;

  return gcd;

}

void modInverse(int a, int m)

{

  int x, y;

  int g = GCD(a, m, &x, &y);

  if (g != 1)

    cout << "Inverse does nOt exist!!";

  else

  {

    int res = (x%m + m) % m;

    cout << "Modular inverse is " << res;

  }

}

// Driver Program

int main()

{

  int a, n;

cout << "Enter the value of n: ";

cin >> n;

cout << "Enter the value of a (>= 0): ";

cin >> a;

  modInverse(a, n);

  return 0;

}

Add a comment
Know the answer?
Add Answer to:
Project 2: The Inverse Modulo n [MOD] Textbook Section: 7.37 Directions: The user will input the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT