In modern operating systems, kernel processes messages are communicated securely by using several encryption mechanisms such as Zig-Zag cipher which divides the message into two parts: the first part contains the odd-positions characters, while the second part contains the even-positions characters. Eventually, the cipher is constructed by concatenating the first part with second part. Using traditional pipes, write a program to produce a full duplex parent/child relationship in which processes can send/receive user data encrypted with Zig-Zag cipher. The communication should cease if either process sends the message “Bye
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define VAL(PTR) (*PTR)
typedef char* STRING;
typedef char** STRING_REF;
void flush_stdin()
{
while(fgetc(stdin) != '\n');
}
void rail_fence_encrypt(STRING_REF str, int depth)
{
STRING old_str = VAL(str);
int len_str = strlen(old_str), itr_str, rows, cols;
STRING res_str = (STRING)malloc(sizeof(char)*len_str);
for(rows = 0, itr_str = 0 ; rows < depth ; ++rows)
{
for(cols = rows ; cols < len_str ; cols += depth)
{
res_str[itr_str] = old_str[cols];
++itr_str;
}
}
res_str[itr_str] = '\0';
free(VAL(str));
VAL(str) = res_str;
}
void rail_fence_decrypt(STRING_REF str, int depth)
{
STRING old_str = VAL(str);
int len_str = strlen(old_str), itr_str, rows, counter;
STRING res_str = (STRING)malloc(sizeof(char)*len_str);
for(counter = 0, itr_str = 0 ; counter < len_str/depth ; ++counter)
{
for(rows = counter ; rows < len_str ; rows+=(len_str/depth))
{
res_str[itr_str] = old_str[rows];
++itr_str;
}
}
free(VAL(str));
VAL(str) = res_str;
}
int main(void)
{
STRING str;
int txt_length, key;
printf("Enter the depth: ");
scanf("%d",&key);
printf("Enter the length of the text: ");
scanf("%d",&txt_length);
printf("Input the string you want to encrypt: ");
flush_stdin();
str = (char*)malloc((txt_length+1)*sizeof(char));
fgets(str,txt_length+1,stdin);
if(&str == "Bye" || &str =="bye")
return 0;
else
rail_fence_encrypt(&str,key);
printf("\nThe encrypted text is: %s",str);
rail_fence_decrypt(&str,key);
printf("\nThe decrypted text is: %s",str);
return 0;
}
In modern operating systems, kernel processes messages are communicated securely by using several encryption mechanisms such...