#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    13
    Rep Power
    0

    Question major Problem in code in here guys


    dear readers I have done my researches and still un-able to solve this program so please I need someone to help me or even solve it but as I think we must use semaphores, forks and pipes that's what I think but no nothing else about it.can anyone solve it plz ? am not good in C language... thanks for all.

    We are requested to implement a code cracking system. The system will deploy four processes (p1,p2,p3 & p4) to try to guess the password of an encrypted code.
    For encryption, we consider that the formula is: C = P XOR K, where
    C = encrypted code
    P = plain text
    K = key
    For decryption the formula is: P = C XOR K. So, your program will try to find K using this formula. The XOR operator is ^.
    Given an encrypted code C and plain code P your program should deploy three processes to try and find the key used to encrypt the plain code. These three processes will be under the control of process P1.
    All processes will send their results to process P1 and process P1 will terminate the three processes and display the encryption key and decrypted text once any of the three processes finds the key.
    For simplicity we will consider that we have the original number P stored in a file called plain.txt and the encrypted code is stored in a file called cipher.txt. Consider that only numbers are stored in these files and they have a range between 0 and 100000000.
    So we have P and C your program should find the key K. Consider that K is a positive number between 0 and 1000000.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    13
    Rep Power
    0
    I understood that I have to fork 4 processes and write them into a buffer where they can be given to the xor operation but didn't understand what is P and K and couldn't code them even or didn't know how to write them in c language
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    13
    Rep Power
    0
    #include<stdio.h>
    #include<sys/types.h>
    #include<unistd.h>

    typedef struct decrypt
    {
    int p;
    int k;
    int c;
    c=p^k;
    }decrypt;

    int main()
    {
    decrypt s[10];
    int n,fd,i;

    fd=open("p.c",O_CREAT,777);//creates a new file
    if(fd<0)
    {
    printf("\nFailed to create file\n\n");exit(-1)
    }

    fd=open("p.c",O_RDWR,777)//open the file for read and write

    printf("Enter the number to decrypt:");

    scanf("%d",&n);

    printf("Enter the key\n");

    for(i=0;i<n;i++0
    {



    scanf("%d",&s[i].p);



    scanff("%d",&s[i].n);

    write( fd,s[i],sizeof(s) );//write to the file which the file discriptor is pointing to

    }



    return 0;//return success to kernel
    }
    didn't know if I wrote it properly or even how to use semaphores please someone help me in here

    Comments on this post

    • ptr2void disagrees : Another lying, cheating copy/paste artist.

IMN logo majestic logo threadwatch logo seochat tools logo