private KnotHash ( IEnumerable input, int rounds ) : int[] | ||
input | IEnumerable | |
rounds | int | |
return | int[] |
int[] KnotHash(IEnumerable<int> input, int rounds) {
var output = Enumerable.Range(0, 256).ToArray();
var current = 0;
var skip = 0;
for (var round = 0; round < rounds; round++) {
foreach (var len in input) {
for (int i = 0; i < len / 2; i++) {
var from = (current + i) % output.Length;
var to = (current + len - 1 - i) % output.Length;
(output[from], output[to]) = (output[to], output[from]);
}
current += len + skip;
skip++;
}
}
return output;
}
}