Discuss Need help in a project in the C Programming forum on Dev Shed. Need help in a project C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Posts: 7
Time spent in forums: 1 h 27 m 50 sec
Reputation 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
Quote:
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.
Posts: 6,122
Time spent in forums: 2 Months 2 Weeks 3 Days 13 h 38 m
Reputation Power: 1949
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.
Posts: 7
Time spent in forums: 1 h 27 m 50 sec
Reputation 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
Posts: 6,122
Time spent in forums: 2 Months 2 Weeks 3 Days 13 h 38 m
Reputation Power: 1949
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.
Posts: 3,345
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 49 m 27 sec
Reputation Power: 383
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!
Posts: 3,831
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 51 m 23 sec
Reputation Power: 1774
> 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
(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.
Posts: 7
Time spent in forums: 1 h 27 m 50 sec
Reputation Power: 0
Quote:
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
(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...