0

So essentially I'm trying to make a function that takes an ASCII value and multiplies it by the remainder of the previous multiplication in the iteration.

So for the first iteration (i = 0), the remainder just gets set as the initial asc value. The second iteration (i = 1), the calculation is something like rem = (rem * ascVal)%N, where rem in rem * ascVal is the rem (remainder) from the previous iteration. This continues until i = e where the last value of rem is returned.

This is what i have so far:

function newVal(ascVal) {
    var i = 0;
    var rem = ascVal;
    while (i < e) {
        rem = (rem * ascVal) % N;
        i++;
        if (i == e) {
            return rem;
        }
    }
    newVal(rem);
}
The thing is it always returns 55 if the input is a single value every time. All i need it to do is find the remainder after e iterations. Any help would be great and i can post the entire script if needed (includes all calculations etc.)

P.S. This script is a small prototype elliptic curve encrypter.

Brayden
  • 147
  • 1
  • 10

1 Answers1

0

Ok so I solved it by using a while loop.

function newVal(ascVal) {
var num = Number(ascVal);
var rem = num;
var i = 0;
while (i < e) {
    i++;
    rem = (rem*num)%N;
}
return rem;

}

This iterates the correct value each time.

Brayden
  • 147
  • 1
  • 10