Bug report: Utils.modInv assumes modulus of 26
- Dominant language
- JavaScript
- Stars
- 35.8k
- Forks
- 4.1k
- Avg merge
- 2d 26m
- Merged PRs (30d)
- 33
Description
**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`.
Contributor guide
Research direction
Locate Utils.modInv in the JavaScript source and inspect its use by the Affine Decode operation. Confirm how the modulus argument is intended to work, then replace the hard-coded modulus with y or evaluate the proposed Extended Euclidean Algorithm; done means modular inverses use the supplied modulus without changing Affine Decode behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100