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
}
You can use the spread operator (...)
const s0 = [1, 2, 3, 4];
function rotr(x, n) {
const copy = [...x];
for (let c = 0; c < n; c++)
copy.unshift(copy.pop());
console.log(`original array: ${x} and changed array: ${copy}`)
return copy
}
rotr(s0, 2)