#P11105. BASE23 Encryption and Decryption

    ID: 13163 Type: Default 1000ms 256MiB

BASE23 Encryption and Decryption

BASE23 Encryption and Decryption

Help Alesya and Boris design and implement the BASE23 encryption and decryption algorithms.

Your task is to implement two functions Encode and Decode (do not write a main function):

std::vector<int> Encode(int n, int k, std::vector<int> T){
    // Encryption process
    return R;
}

std::vector<int> Decode(int n, int k, std::vector<int> R){ // Decryption process return T; }

</p>

In the above, the function Encode acts on behalf of Alesya to encrypt a sorted (in non-decreasing order) array T, while Decode acts on behalf of Boris to retrieve the original array from the encrypted array R (which is also sorted in non-decreasing order).

The interactive library will call your Encode function on multiple test cases using the original T (with given n and encryption key k) and check whether the encryption is valid. Then, it will call your Decode function (with the corresponding R) in random order to verify that the decrypted result exactly matches the original array T.

You are free to design your own reversible encryption algorithm. For instance, one valid approach is to compute for each element:

\[ R[i] = T[i] \times 23 + k, \]

and then in Decode to retrieve:

\[ T[i] = \frac{R[i] - k}{23}. \]

This approach guarantees that the encryption is reversible and maintains the non-decreasing order of the arrays.

inputFormat

The functions will receive three parameters:

  • int n: the number of elements in the array.
  • int k: the encryption key.
  • vector<int> T (or equivalent in other languages): a sorted array that needs to be encrypted (for Encode) or the encrypted array (for Decode).

Note: You do not need to handle input from stdin or produce output to stdout; only implement the two functions.

outputFormat

The Encode function should return a sorted array R representing the encrypted result. The Decode function should return the original sorted array T after decrypting the provided array R.

It is expected that for any valid test case, Decode(n, k, Encode(n, k, T)) returns the original array T.

sample

Encode: n = 3, k = 5, T = [1, 2, 3]
Decode: n = 3, k = 5, R = [28, 51, 74]
Encode Output: [28, 51, 74]

Decode Output: [1, 2, 3]

</p>