Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modInverse needed #219

Open
mccoysc opened this issue Feb 5, 2019 · 1 comment
Open

modInverse needed #219

mccoysc opened this issue Feb 5, 2019 · 1 comment

Comments

@mccoysc
Copy link

mccoysc commented Feb 5, 2019

as the title

@Light-Wizzard
Copy link

Light-Wizzard commented Apr 8, 2019

Take a look at this:
Without BigNumber:

function modInverse(thisNumber, thisMod) {
    let thatNumber = thisNumber % thisMod;
    let x = 0;
    for (x = 1; x < thisMod; x++) {
       if ((thatNumber * x) % thisMod === 1) {
          return x;
       }
    }
    // FIXME: should never get here, in this case I do not know what to return
    return 0;
}

I tested the function, it works, it is just a matter of adding BigNumber into the function which I did below and also tested it.

function modInverse(thisNumber, thisMod) {
    let thatNumber = new BigNumberJs.BigNumber(thisNumber);
    thatNumber = thatNumber.modulo(thisMod);
    let x = 0;
    for (x = 1; x < thisMod; x++) {
       if (thatNumber.times(x).modulo(thisMod).toString() === "1") {
          return x;
       }
    }
    // FIXME: should never get here, in this case I do not know what to return
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Light-Wizzard @mccoysc and others