Question: Problem Overview: You need to write a POSIX - compliant C program that: Reads an NxN matrix of strings from shared memory. Decodes all strings
Problem Overview:
You need to write a POSIXcompliant C program that:
Reads an NxN matrix of strings from shared memory.
Decodes all strings except the one in the very first cell using a Caesar Cipher.
Counts how many times each string in the matrix occurs in a text file wordsttxt
Caesar Cipher keys are obtained via a message queue by sending sums of string occurrences from the matrixs diagonals to a helper process. The key ranges from to
The matrix and text file details are provided via an input file inputttxt
You will communicate with both shared memory and a message queue.
Input Files:
Your program will receive one commandline argument: a number t maximum digits, ie This number determines the names of two files:
Text file: wordsttxt contains a large number of strings separated by spaces
Input file: inputttxt provides the following:
Size of the matrix N
Maximum length of a word in the words file
Key for connecting to the shared memory to access the matrix
Key for connecting to the message queue to communicate with the helper process
Example inputttxt:
Matrix in Shared Memory:
The NxN matrix of strings is stored in shared memory, and you must connect to it using the key from the input file.
The matrix is a D array of strings each string is a character array
Connect to the shared memory using the following function signatures:
char shmptrNstringSize;
shmgetkeyt key, sizet sizeofcharNNstringSize int shmflg;
shmatshmId NULL, ;
Here, N is the side length of the matrix, and stringSize refers to the maximum word length given in the input file.
Once connected, you can access matrix elements as shmptrijwhere i j N
Caesar Cipher:
All strings in the matrix except the one in the very first cell, ie shmptr are encoded with a Caesar Cipher.
The same key is used to decode all strings in a given right diagonal of the matrix.
The key for the next diagonal is obtained by sending the sum of the occurrences of all the strings in the previous diagonal to a helper process via a message queue.
The helper process already running will respond with an integer representing the Caesar Cipher key for the next diagonal. The key will be between and
Once you have the key, use it to decode the strings before counting their occurrences in the text file.
Counting Occurrences:
The program should count how many times each decoded string from the matrix appears exactly in the text file wordsttxt
Note: Strings that appear as substrings in other words should not be counted. For example, if the word abc is in the matrix, it should not be counted within a word like hbabcp.
A function wordFindFileOpenFunction should be implemented that:
Opens the text file.
Checks if each word is found.
Returns if a word is found and if its not.
Message Queue and Helper Process:
Your program will communicate with the helper process via a message queue, using the key from the input file.
Message Protocol:
Your program sends a message of type with the sum of occurrences of words in each diagonal of the matrix.
The helper process will respond with a message of type which contains the Caesar Cipher key for the next diagonal.
For each right diagonal there are N right diagonals in an NxN matrix send the sum of occurrences and receive the key for the next diagonal.
Once all diagonals are processed, the helper process will:
Send if the final sum is correct.
Send if theres an error eg an incorrect sum and the process will exit early.
Diagonals and Key Communication:
A matrix has N right diagonals. The right diagonal starts from any cell in the first row or last column and goes diagonally downwards.
For example, in a x matrix:
Diagonal :
Diagonal : and
Diagonal : and
Diagonal : and
Diagonal :
For each diagonal, count the number of occurrences of its strings, send the sum to the helper process, and receive the Caesar Cipher key for the next diagonal.
Word Matching:
Both the matrix and wordsttxt contain only lowercase English letters.
Ensure that only exact matches are counted substrings should not be included
Cleanup:
When done, detach from the shared memory and message queue.
Do not delete the shared memory or message queue shmctl and msgctl are not to be used for deletion Please dont use any ChatGPT or any other AI tools
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
