Need C++ unencrypt text file (school)
Need C++ unencrypt text file (school)
(OP)
Taking c++ class at nite. Program encrypts text file by offsetting char by some integer. 2nd program reverses by same value to original text. Runs fine. Instructor (another engineer) wants to decode a text file w/ unknown integer value offset. I did one that searches +/- 30 integers with cout<< for user to review.
Assuming its predominately letters (cap and lower case) could you count the occurences of each char, take the ASCII value of the one with max value, set it to 'e'. This offset value would then be applied to the text file and cout<< the text for user approval? There's a letter use hierarchy in English that would apply. Seems like a LOT of Code.
Anybody have a shortcut? Thanks!! (this is an extra credit and boy, do I need it!)
Assuming its predominately letters (cap and lower case) could you count the occurences of each char, take the ASCII value of the one with max value, set it to 'e'. This offset value would then be applied to the text file and cout<< the text for user approval? There's a letter use hierarchy in English that would apply. Seems like a LOT of Code.
Anybody have a shortcut? Thanks!! (this is an extra credit and boy, do I need it!)





RE: Need C++ unencrypt text file (school)
One aproach worth investigating:
1. Scan the document find the lowest value.
2. Subtract 20 hex from this value this. (This is probally your offset.)
Rich
RE: Need C++ unencrypt text file (school)
you could probably write this in your sleep. We haven't gotten to hex conversion, but I think its in the book. I'll give this a try.
I did find a lot of resource at www.howtos.nl
RE: Need C++ unencrypt text file (school)
Another tidbit, most text editors append a carriage return and linefeed ( 0D 0A ) as the last 2 bytes of a file, occasionally you will find one that has appended ( 0D 0A 1A ), but those are rare. Wordpad and Notepad all append the 0D 0A combination.
Hope this helps....
RE: Need C++ unencrypt text file (school)
A couple of thoughts.
1. Regarding the post above. It is possible the text will contain Carriage Returns (ASCII 13) and Line Feeds (10)
If it does, scan the whole text for the lowest value, then subtract 10 away from it then you probably have the difference.
If not then as the previous post stated look for spaces. i.e. scan the text, find the lowest and subtract 32 (the ASCII for SPACE) the result being the difference from which you subtract from the rest of the characters.
2. If the above doesn't work the the word 'the' is pretty common, and it usually is prefixed and ends with a space. If you are looking for the ASCII of the word ' the ' then it would be 32 116 104 101 32.
Now in the simplest of coding (adding an offset) the difference between each letter would be the same if all letters were added an offset to. So what you could search for is the difference between succesive characters ie
84 12 3 69 and make sure that the first and last caharcters are equal. Then to find the difference just subtract 32 from the first character value in the ' the ' string.
Any help ?, yes no let me know.
Regards
RE: Need C++ unencrypt text file (school)
Looking at the above ideas, I've been finding a lot of things in the text that the instructor hasn't even gotten close to. I got searching for the scan syntax until 2:30 this morning without a result.
This instructor thinks He's the answer to c++
RE: Need C++ unencrypt text file (school)
Not a trick as you guys could do, but a heck of a learning experience!
RE: Need C++ unencrypt text file (school)