• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/index.php
Line: 315
Function: require_once

So I have an assignment, in which we were told to make something that operates like a chat. From process P1 you write something and process P2 ouputs what you wrote on P1. There are actually more than 2 processes involved though. Process P1 sends the message to process Enc1 which finds the checksum of the message and sends both to process Chan via their shared memory. Chan, based on a probability inserted from the user, changes or doesn't change the message and finally sends the message to process Enc2. Enc2 checks the message that was sent from Chan and computes its checksum (hash value when MD5() was used) and compares the two hash values. If they are the same it sends the message to P2 for output, else it outputs a message for process P1 to re-enter the message. There are 4 different shared memory segments between P1-Enc1, Enc1-Chan, Chan-Enc2, Enc2-P2. So as stated before, we were advised to use MD5() for hashing, but when its time for Enc2 process to run, if the message was changed or wasn't changed in process Chan, the hash that MD5() produces is always different from the one produced in process Enc2.

process Enc1 code:

  int main(int argc, char* argv[]){   key_t key1 = ftok("process", SH_MEM1);  //key for shared_memory between p1-enc1   int shmid1;   if((shmid1 = shmget(key1, MAX_LENGTH, 0666 | IPC_CREAT)) < 0){     printf("Error finding/creating shared_memory(p1-enc1), exiting...
");     exit(1);   }    key_t key2 = ftok("process", SH_MEM2); // key for shared_memory between enc1-chan   int shmid2;   if((shmid2 = shmget(key2, MAX_LENGTH, 0666 | IPC_CREAT)) < 0){     printf("Error finding/creating shared_memory(enc1-chan), exiting...
");     exit(1);   }    char *message1 = (char*) shmat(shmid1,0,0);   char hash[MD5_DIGEST_LENGTH];   int mess_len = strlen(message1);   if (message1[mess_len-1] == '
') message1[mess_len-1] = '';  //getting rid of '
 character'   printf("message is: %s
", message1);   MD5(message1, sizeof(message1), hash);   printf("hash is %s
", hash);   strcat(message1, hash);   printf("After strcat: %s
", message1);    char *message2 = (char*) shmat(shmid2,0,0);   strcpy(message2, message1);   printf("message2 is %s
", message2);     shmdt(message1);   shmdt(message2);   // shmctl(shmid1,IPC_RMID,NULL);   // shmctl(shmid2,IPC_RMID,NULL);   exit(1);  } 

process Enc2 code:

int main(int argc, char* argv[]){   key_t key1 = ftok("process", SH_MEM3); // key for shared_memory between chan-enc2   int shmid1;   if((shmid1 = shmget(key1, MAX_LENGTH, 0666 | IPC_CREAT)) < 0){     printf("Error finding/creating shared_memory(enc1-chan), exiting...
");     exit(1);   }    key_t key2 = ftok("process", SH_MEM4); // key for shared_memory between enc2-p2   int shmid2;   if((shmid2 = shmget(key2, MAX_LENGTH, 0666 | IPC_CREAT)) < 0){     printf("Error finding/creating shared_memory(enc1-chan), exiting...
");     exit(1);   }    char *message1 = (char*) shmat(shmid1,0,0); //message in shared_memory between chan-enc2   printf("message is %s
", message1);   int len = 5; //testing for strings with len 5   char tmp1[strlen(message1)]; //contains message+hash (without the +)   strcpy(tmp1,message1);   char og_message[len]; //will contain the original message with the changes it had, if any   char og_hash[strlen(message1)-len];  //will contain the original hash   strncpy(og_message,tmp1,len); //gets original message   int n;   for (n=5; n<=strlen(message1); n++)     og_hash[n-len] = tmp1[n];   printf("Original message is %s
", og_message);   printf("Original hash is %s
", og_hash);   char hash[MD5_DIGEST_LENGTH];   MD5(og_message, sizeof(og_message), hash);   printf("New generated hash is %s
", hash);   if (strcmp(hash, og_hash) == 0){     printf("Hashes are the same, message was transmitted without any changes!
");   } else{     printf("Hashes are not the same, please send the message again
");   } } 

SH_MEM1, SH_MEM2, SH_MEM3, SH_MEM4 are defined with the values 10,20,30,40 respectively. I don't think the code for Chan process is needed here but if asked I will put it in the comments. Process Enc2 is able to see the message sent to it from process Chan but using MD5() on this process doesn't produce the same hash as before. Does anyone have an idea on how to fix this?

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]
c