3 ms·
Something like this: def sattolo(a, key): n = len(a) keylength = len(key) j = 0 for i in range(n - 1): j = (j + a[i] + key[
by UncleEntity 6y ago
Something like this:
def sattolo(a, key):
n = len(a)
keylength = len(key)
j = 0
for i in range(n - 1):
j = (j + a[i] + key[i % keylength]) % n
a[i], a[j] = a[j], a[i]
(key needs to be a byte string because it's easier that way)
--edit--
Doesn't work for producing a singlar path:
>>> x = [0,1,2,3,4,5,6,7,8,9]
>>> sattolo(x, b'zanzibar')
>>> x
[0, 2, 1, 5, 4, 3, 8, 6, 9, 7]