You could create two functions, one for the P-box and one for the S-box. Then pass the string first to the P-box and then to the S-box for encoding.
For the decoding you need to write functions for inverse P-box and inverse S-box. First you send the encrypted string to the inverse S-box and then to the inverse P-box.
An S-box could be implemented like this:
Code:
char original_str [4];
char s_box_str [4];
int index;
for (index = 0; index < 4; index++)
{
switch (original_str [index])
{
case 'a':
s_box_str [index] = 'd';
break;
case 'b':
s_box_str [index] = 'p';
etc.
}
}
And a P-box could look like something like this:
Code:
char original_str [4];
char p_box_str [4];
p_box_str [0] = original_str [1];
p_box_str [1] = original_str [3];
p_box_str [2] = original_str [2];
p_box_str [3] = original_str [0];
}