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

Bug report: Utils.modInv assumes modulus of 26 #1835

Open
profbbrown opened this issue Jun 13, 2024 · 1 comment
Open

Bug report: Utils.modInv assumes modulus of 26 #1835

profbbrown opened this issue Jun 13, 2024 · 1 comment
Labels

Comments

@profbbrown
Copy link

Describe the bug
The Utils.modInv function internally uses 26 as the modulus rather than the argument y. The bug is not externally visible because it's used in the Affine Decode operation, which uses an alphabet with 26 letters.

Source code

static modInv(x, y) {
    x %= y;
    for (let i = 1; i < y; i++) {
        if ((x * i) % 26 === 1) {
            return i;
        }
    }
}

Remedy
Replace 26 with y.

Better still: replace the entire function with one that uses the Extended Euclidean Algorithm to compute the modular multiplicative inverse. It will be faster than a brute-force loop for large values of y.

@profbbrown profbbrown added the bug label Jun 13, 2024
@profbbrown
Copy link
Author

Pull request #1836

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

No branches or pull requests

1 participant