fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. void encode(int *data, int *key, int size)
  5. {
  6. for (int i{}; i<size; i++)
  7. std::swap(data[i], data[key[i]%size]);
  8. }
  9.  
  10.  
  11. int main() {
  12. static const int size = 6;
  13. int data[size]{0,1,2,3,4,5};
  14. int key[size]{rand()%255, rand()%255, rand()%255, rand()%255, rand()%255, rand()%255};
  15.  
  16. encode(data, key, size);
  17.  
  18. for (int i{}; i<size; i++) std::cout << data[i] << ' ';
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
2 3 1 0 4 5