2

rotr() removes the last array value and places it to array-index 0 (to the the beginning). The method does that for n times. Its rotating the array x by n.

My problem is the first XORXOR parameter is w[sh1] rotatet by 7. Okay! Thats good.

The second XORXOR parameter is rotatet by 7 + 18 and the last parameter is rotatet by 7+18+3. Thats not how i want it...

The first parameter of rotr should and must always be the same array. Why is the function changing the array globally. Its not modifying the parameter and returns a copy of that modification? With return? Always used Python... then one time a little bit JS and its completely getting on my nerves... can someone help me and explain it to me?? my whole algorithm is a failure because of that *****

const s0 = XORXOR(rotr(w[sh1], 7), rotr(w[sh1], 18), shr(w[sh1], 3))

function rotr(x, n) {
    for(let c = 0; c<n; c++) {
        x.unshift(x.pop());
    }
    return x
}
Makouru
  • 21
  • 4
  • 1
    Yes array is an object and as such, it is passed around as a pointer. You need to clone it like `var cloned = [...x]`; – IT goldman Jul 03 '22 at 23:03
  • 1
    "*Its not modifying the parameter*" - yes it is! Right there: `x.unshift()`, `x.pop()`. In fact this behaves just the same as in Python when you pass an array and call `insert` and `pop`. – Bergi Jul 03 '22 at 23:26

0 Answers0