#include <iostream>
#include <cstdlib>
void encode(int *data, int *key, int size)
{
for (int i{}; i<size; i++)
std::swap(data[i], data[key[i]%size]);
}
int main() {
static const int size = 6;
int data[size]{0,1,2,3,4,5};
int key[size]{rand()%255, rand()%255, rand()%255, rand()%255, rand()%255, rand()%255};
encode(data, key, size);
for (int i{}; i<size; i++) std::cout << data[i] << ' ';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KCnZvaWQgZW5jb2RlKGludCAqZGF0YSwgaW50ICprZXksIGludCBzaXplKQp7Cglmb3IgKGludCBpe307IGk8c2l6ZTsgaSsrKQoJCXN0ZDo6c3dhcChkYXRhW2ldLCBkYXRhW2tleVtpXSVzaXplXSk7Cn0KCgppbnQgbWFpbigpIHsKCXN0YXRpYyBjb25zdCBpbnQgc2l6ZSA9IDY7CglpbnQgZGF0YVtzaXplXXswLDEsMiwzLDQsNX07CglpbnQga2V5W3NpemVde3JhbmQoKSUyNTUsIHJhbmQoKSUyNTUsIHJhbmQoKSUyNTUsIHJhbmQoKSUyNTUsIHJhbmQoKSUyNTUsIHJhbmQoKSUyNTV9OwoJCgllbmNvZGUoZGF0YSwga2V5LCBzaXplKTsKCQoJZm9yIChpbnQgaXt9OyBpPHNpemU7IGkrKykgc3RkOjpjb3V0IDw8IGRhdGFbaV0gPDwgJyAnOwoJCglyZXR1cm4gMDsKfQ==