Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Need help in a project


    Hello everyone i'm new here seeking help for my C programming project.

    The instructor told us to make a program to decrypt an encrypted code

    this is the full text
    Process creation and control - Synchronization

    Problem statement
    You are 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.
    i'm finding trouble understanding how it will be implented, constructed and done
    i can't figure what does he mean by the XOR operator and how can i use it
    i'm not that good at programming, but it's required in in major.
    and we didn't an example like that in the course, the most we got is how to make processes using fork.
    so if anyone can help me making this, giving hints, examples,etc... i will be more appreciated the help thank you.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Why didn't you do any of your own research before running to strangers for help? The main thing that you're supposed to learn in college is how to learn (ie, to be able to do research).

    Bitwise Exclusive OR (XOR). As your instructor already told you, in C the XOR operator is ^ . The bitwise result of an XOR operation is a 1 if the two operand bits are different from each other and 0 if they are both the same. The XOR operation is also known as a "half-add", because it implements bitwise addition without the carry; to get a full-adder you basically gang together two flag-adders. This half-adder functionality of XOR is widely used in calculating checksums. I am less familiar with its use in cryptology, but then your instructions explain that.

    Now get to work and if you have any specific questions or problems with your code then we can help you further.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0
    Trust me i did, but as i said i couldn't figure out how to make the code, since we didn't use nor take the function XOR in any of the problems. i also googled some information how that kind of a program. the book isn't helping either.

    what i'm not understanding how can i make to check and analyze and look for K
    i understand the user has to put the code, then the program should analyze and search for K and output it.
    but i don't know the proper codes/functions for that,
    and we need to use pipes right ?

    sorry if i sounded like i want you to make the program for me, i just want a bit of hints/examples of similar codes so i get a high grade on it :(
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Whether you use pipes or not has nothing at all to do with finding K, but rather with the extra instructions that you are to fork processes -- for that matter, you could use any of a number of inter-process communication (IPC) techniques, but you were probably taught about pipes.

    Re-read the problem. You know that P = C XOR K and that you are given both P and its corresponding C, so there's only one unknown, which is K. All you have to do is to find a value of K that will generate the known P when given the known C.

    One thing about computers is that they can do the same operation over and over again very rapidly, so a number of problems that would have required cleverness can instead be done with brute force; eg, instead of using Gauss' elegant method for adding all the number from 1 to 100, you can instead write a program that will simply add all those numbers together (story goes that his grade-school class was given that task as a punishment, but Gauss thought about it for a few minutes and came up with a simple formula to come up with the right answer). And example of a brute force method to figure out an account's password is "throwing the dictionary at it", trying all possible passwords until one of them works; this is why you're only allowed a small number of tries to entry your password.

    You could try a brute-force method of trying all possible values for K until one works. But what does the class lectures and reading assignments have to say about that approach? Personally, from my understanding of the problem, I could probably do it in just a couple steps, but I don't know if that would be in keeping with what you had been taught.

    Think about bitwise operations. For that matter, think about the binary representation of integer numbers, which is what you're working with here. And keep in mind that that XOR you're performing is bitwise. That means that the bits in the same bit position of C and your guessed K are XOR'ed together to form the resultant bit in the same position your resultant P, which you then need to compare to the bit in the same bit position of the known P to see if it's correct.

    Do your notes say anything about corresonding bits or about bit positions? I don't dare say much more about that without giving everything away. But the requirement for multiple processes looks to me like you're expected to be doing a lot of number-crunching, which I don't see the need for. If you can see where I was leading, you might want to discuss it with your instructor.
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    If you're given the key length which is short, and correctly guess cyclic key repetition, it's then easy to try keys. Filter the decrypted text by searching some common words. Only a few texts will remain that you'll need view with human eyes. Or partition the text into words based on space character and ensure the mean word length is 5 or so.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Needed


    ZeraX please can you send me the solution of this problem??!

    Comments on this post

    • ptr2void disagrees : Great, another cheater. Please fail and go back to flipping burgers or whatever it is they serve as fast food in your country. It's obviously more your speed.
    • clifford disagrees : That would be the blind-leading-the-blind; why would you want the answer form someone who does not know the answer?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by hufa
    ZeraX please can you send me the solution of this problem??!
    It's not my project but I like the problem
    thank you, you are so sweetyyyyyyy

    Comments on this post

    • salem disagrees : If you like the problem so much, you'll enjoy it even more by trying it yourself
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    !!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0
    Hello guys

    so, i did finish the code
    and want to look it up and see if it's there's some mistakes.
    thank you

    Code:
    #include <stdio.h>
    #include<fnctl.h>
    Int C, P,K;
    Int i;
    Int fd[2];
    Pipe(k);
    
    {
    P = open(“plain.txt”,O_RDONLY);
    C= open(“cipher.txt”,O_RDONLY);
    
    Int pid = Fork();  //p2
    {
    If(pid ==0){
    
    C = open(“plain.txt”,O_RDONLY);  /* we exchange the plain text with ecnrypted text C<=>P*/ 
    P= open(“cipher.txt”,O_RDONLY);
    For(i=0; i<100000; i++)
    C[i] = P[i] ^ K[i];
    If(K == C)
    Write(fd[1],K,sizeOf(Int);
    Kill(pid,SIGKILL)
    }
    
    }
    If(pid >0)
    Pid = fork(); //p3
    If(pid == 0){
    
    C = open(“plain.txt”,O_RDONLY);  /* we exchange the plain text with ecnrypted text C<=>P*/ 
    P= open(“cipher.txt”,O_RDONLY);
    For(i=100000; i<1000000; i++)
    C[i] = P[i] ^ K[i];
    Printf(“key is:  %d”, k);
    If( K == C){
    Write(fd[1],K,sizeOf(int));}
    Kill(pid,SIGKILL)
    }
    
    If( pid >0);{
    Fork(); //p4
    If(pid == 0){
    
    C = open(“plain.txt”,O_RDONLY);  /* we exchange the plain text with ecnrypted text C<=>P*/ 
    P= open(“cipher.txt”,O_RDONLY);
    
    For(i=1000000; i<10000000; i++)
    C[i] = P[i] ^ K[i];
    P = open(“cipher.txt”,O_RDONLY);
    C= open(“plain.txt”,O_RDONLY);
    For(i=0; i<4; i++)
    C[i] = P[i] ^ K[i];
    If( K == C){
    Write(fd[1],K,sizeOf(int));}
    Kill(pid,SIGKILL)
    }
    }
    Wait(NULL);
    close(C);
    close(P);
    Read(f[0], K, SizeOf(int);
    Printf(“Key is: %d”, K);
    } return 0 }
  18. #10
  19. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    What's with all the Initial Caps Of Everything?
    It won't compile as written.

    Also, you need to indent the code if you want people to seriously look at it.
    http://sourceforge.net/apps/mediawik...le=Indentation
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0
    I'm assigned to give the code only
    no need for compiling.

    ugh is it that really hard to get help here ?
  22. #12
  23. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481

    Puzzle


    Puzzle: Find the title of the book with the following xor encrypted text. The key is five letters long. We're dealing in ASCII.
    Code:
     30   9  11  23   0 106  97  25   4  22 106  15   1 101 101  26  14  29
     22  12   8   8   2  12  17  19  97   1   3 101 106  21  15  14  12   4
      6 110 101   4 106  22  15   9  14 106  97  26  13   4  30  97  10   4
     28 100  97 110  18   0 106   9  15   1 101 106   3  11   0  11  64  22
     15  11   1  15  19   7  11   2 102  97   7  11   1  15   4  10 105 101
      3  15 110 101  17   2   4 110   9   0  11   7   2   0  22  25  97  29
     13  23  31   3  12   0  23  19  97  15  11 101   2  14  27  23 101 106
      8   0 101  17   2   4 110   8  10  24  15   7  11   2 113  75  12  16
     17 106  18   7  11   6  15  97  10  12  11   4   4  28 101 101  98  12
     28  22 107 106  19  11   0   1 102  97  25  13   0   4  97  26  13   0
     24   4 110  18   4  25  97 110  11  10 106   2   1   8  21  11  15  23
    105 101  14   8   0   0   1 106   4  15  23   9  19 104  68  17  13  15
     97  13  10   9  14  97  25  12  11  30   4  28 101  18   3  15  10 101
     13  11   5 110   7  23   5  20   9  13  17 106  97  25  12  17   2  97
      7  17 101   9  13   1  16   1  25  97  29  10 101  25  14   3   7  23
     15 109 110   4  11  14  97  15 101  23  11   8   0  79  22   5  97 110
     21   0   4   4  26  23   4  30   8   0   2 105 106  21   6   4  17 106
     97   8  16  23  30   9  11  23 101   5  20  26 104   1   5  14  28 101
    101  15  25  11  23   6   3  18  11 101  18  11  18 110 101  11   5  22
    110  10  16  30  97 110  10   3 106  21   6   0  79  27  20  11  22  17
      3  14   0 107 101 106   8 110  18   4  25  97 110   2   9  11   5 110
     10   3 106   8  26 127 101   3  97   0   0  19  15  19 110   9  12   1
      4  10 101 101   6  14   0   2 101  29   0   2  14  22 102  97  11  22
     21  15   2   7   4   9   6  24 110  10  11  64   2   6  12   9   6  24
    110 101   4  12  21  11  23  11   5  14   0  22 127 106   5  28   0   4
     14   7  27   9 101 106  21   1 101   8  15  97 110  18   4  25  97  26
     13   0 106  97  13  10   8   3  15   9 101  13   5  12  11 101 101   3
     15 110 101  17   2   4 110  23   4  29  75  26  18  12   6   8   9  13
     17 102  97  25  12  17   2  97 110  11  12  26  17  11   1 101  12   8
      0   2   0  24  18 110   4  11  14  97  26  10   0  25 109 110 101   4
      4   5 110   4 101   2   4  15  23  17 106  97  29   4   1  14   4   0
      0   1 106   3  23 101  17   2   4  68   6  13   3   5   7  11   2  25
     97   1   3 101   8   4  29  22  12  15 109 110  17  13  15  97   0  16
     23  25   4  98 101 101  11  15  10 101  13  31  12  12   9   0  14  97
     12  28 101  30   9  11 101   6   5  15  29   6  12   5  20  29  11   0
     25  18 110  10   3 106  12  23  79  21   2  24  29  12   6  11  13 110
    101  12   4   7  11  23  12   5  19   7  17  28 106  21   1 101   0   6
      8  20   4 105 106  97   4  10  13   4 109 110   4  11  14  97 110   2
      0   5  19   9  12   4   4   0 110  23   0  15   5  96 101 101 106  21
      6   0 101  25   0   7   1  79  15  13   7  31   4 102  97   4  10  13
      4 109 110   4  11  14  97   9   0  10  24   6   7   4  11  11  97  25
      0  23  15  97 110  11  10  29  97  13   9  16  25  21  11  23   0  14
     97  28  10  16   4   5 110  17  13  15   8  28 101   8  11  12  15 101
     12   4  97  26  13   0  64   5  28   4  18   3  15   9 104  23   5  14
      3 127 101  25   9  11 101   9  11  24 110  23   0   9  13   7  11   0
     14  97   1  11 101  11  97  29  10   3  11  97  12  28 101  30   9  11
    101   3   3  19  11  22  12  14   4  98 101   4   4   5 110  18  12  30
      9 110  13   0  24  75  10   4  23   6   8   0   2  22 106  97  15   7
     10  31  21 110  13   0  24  97 110 109   3   5  19 110 101  17   2   4
    110  17  12   7   4 110 101  11  15   8  26  13   0  24  97 110  20  16
     11  19  28   0   9   6   8   0   2 101   4  14  28 101 101   9  19  23
     12  11  13 104  68   9  10   5  10  11   1 101  26   4  28   3   0   9
     21   2  28 101   2   0  30  21  28 100  97   3   0 105 106  18   6   0
    101 106   9  15   1 101  14   8  29  21   0   4  18  11   1 101  12  19
      1   8 101   0  14   7  11  12   4   6 110  17  13  15  97   9  23  10
     31  17 117  79  22  11  24   7  11   2 102  97 108  22  13  15  97 110
     23   0  13  19  11  17  17  15   5 110  17  10 106   3  11 101  16   4
      5  11  23 101 106  21   6   0 101   4   4  13   0  22  25   8  26  28
    101   5   7 110  14   0  15  17   7  11   2 106  97   3   0 101  11  21
    110   4  79  14   8  29  17   4   4   2  11 126 101   8  20  26 101  17
      2   0  26 101  16   4  21   7   9 101  25   9  11 101 101   2   4  15
     23   1 106   7  28  10   8 106   3  11  22  22   3   4  98 101   4   4
      5 110   6  10  31  13  10 101   1   3  18  13  10  19  15  19 110   7
     28  64   9  11  23 101 106  14  25  11 101   5   3  29   0  23  28   0
     26  12  10   4 109 110 101  17   2   0  26 101 101   3  97 110  18   4
     25  97  11  11   1  15   0  24  10  16  24   8   0   2 101 106   8   0
    101 101  13  14   1   1 101  15   0  28  11   0  25  21 110 101  17   5
     75  15   6  20  31   8  28   0 101  11  97 110   8  10  24   4 110  22
     10   9   8  15   7   9  15  97  15  11   1 106   2   6  12   9  14  13
      7  14   0 106   5   7  22  21   5  18   7  17  12   5  15  98 101 101
     11  97   3  10  23  15  97  15  17  17  24   0  13  17  12  28   4  68
      4  11  14  97  29  21  23   3   6   6  17   9  19  97   3   4  11   4
      4  28 167 197 222  97  29  10   8  15  21   6  12  11  13  97 110   9
     12  13   9  26   0  23 102  97   8  23   4   4  10  11  23 105 106  12
      1  23   0 106  15  15  17  16  24   0   2 105 101  11  18 110  12  17
     64  22  11  23   0 168 193 218  22  13  15  97 110  23   0  11  13   2
     28 101   7  20  29  17 101 106   4  22   6   9  31   5  11 101   8  15
     97 110   3  23   5  12 110  21  23   3  23   7   9   0  13   4  29 101
    101   3  15  26   0  11  14   4  10 101 101   5  15   2  28 101  12  14
     28  79   6   5  15  26   0  11  30   4  10 105 101   2   0  30  21  28
    102  97   2  12  17  30  13  11 101   6   2   8   2   1  23  15  15  96
    103  79   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    [code]Code tags[/code] are essential for python code and Makefiles!
  24. #13
  25. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    > and want to look it up and see if it's there's some mistakes.
    ...
    > no need for compiling.
    Well if all you want is an eyeball gloss, then it looks just fine and dandy :rolleyes:
    (I didn't look at it, I just gave you some warm words to make you feel good).

    But if you want to make sure, you compile and run it on a real machine.

    > ugh is it that really hard to get help here ?
    Not really, we just have a low tolerance of lazyness.

    People who show up with code and a question get good service.

    People who just dump their assignment with no other effort get a hard time.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  26. #14
  27. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    Originally Posted by ZeraX
    I'm assigned to give the code only
    no need for compiling.

    ugh is it that really hard to get help here ?
    Do you expect to get a better grade if your program actually works? Use the compiler! Compilers are great tools.
    [code]Code tags[/code] are essential for python code and Makefiles!
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0
    Originally Posted by salem
    > and want to look it up and see if it's there's some mistakes.
    ...
    > no need for compiling.
    Well if all you want is an eyeball gloss, then it looks just fine and dandy :rolleyes:
    (I didn't look at it, I just gave you some warm words to make you feel good).

    But if you want to make sure, you compile and run it on a real machine.

    > ugh is it that really hard to get help here ?
    Not really, we just have a low tolerance of lazyness.

    People who show up with code and a question get good service.

    People who just dump their assignment with no other effort get a hard time.
    what are you talking about ?
    i posted the code.. all i asked to check if there's a wrong/mistyped function or sentence and might get some tips from so-called pros.
    since i'm new to C language and are still taking the very basics at university.
    in simple words, we are taking the course without computers. we are exercising on papers. i have no C compiler machine or software. i need to submit the code today, felt i should show it you "pros" first...

    and there's someone gives me a puzzle ??
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo