#include <iostream> //STDIN, STDOUT
usingnamespace std;
constint MAX_STR = 100;
int length(constchar input[]);
/*
* Description:
* Calculates and returns the number of characters in the array input.
*
* Inputs:
* char input[]
* An array containing an input string.
*
* Return:
* This returns an int, giving the number of characters in input[].
*/
void encrypt(constchar original[], char encrypted[]);
/*
* Description:
* This function uses a while loop to read the original string forwards and backwards, stopping in the middle and
* making sure not to cross over each other. It then shuffles the c-string characters and stores the encrypted result
* into the array encrypted.
*
* Inputs:
* char original[]
* An array containing the original user string.
* char encrypted[]
* An array containing the encrypted version of the original string.
*
* Return:
* This is a void function so it returns nothing.
*/
int main()
{
char original[MAX_STR];
char encrypted[MAX_STR];
cout << "Enter string for encryption: ";
cin.getline(original, MAX_STR);
cout << "Your encrypted string: ";
encrypt(original, encrypted);
cout << endl;
cout << endl;
return 0;
}
int length(constchar input[])
{
int strLength = 0;
while (input[strLength])
{
strLength++;
}
return strLength;
}
void encrypt(constchar original[], char encrypted[])
{
int i = 0;
int last = (length(original)-1);
int first = 0;
while (i < length(original))
{
encrypted[i] = original[last];
i++;
encrypted[i] = original[first];
i++;
last--;
first++;
}
cout << encrypted;
}