×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Need C++ unencrypt text file (school)

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!)

RE: Need C++ unencrypt text file (school)

Scan for any characters greater than 7F hex (Del) these are not part of the standard ASCII character set. Or look for characters less than 20 Hex (space) one generally will not find too many of these in a text document.

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)

(OP)
Thanks Rich!
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)

If the text file is a large one, then it would presumably have a carriage return and linefeed 0D 0A hex in that order, beginning with the first two characters, check the value of the following letter, then each successive letter. When you find a difference of 03 hex (also account for higher ascii codes i.e. 0D + F4 = 01 and 0A + F4 = FE) When you find a match, subtract (or add) the byte value from its presumed value and apply that across the file. This should work on most files.

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)

Hi,

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)

(OP)
Thanks Guys!! Any quick code for the SCAN function and a way to isolate the value?? Remember, this is C++ 101 and I'm a Mech Eng, not a computer wiz.
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)

(OP)
Thanks to all your responses - and a few LONG nites - I used SEEKG to find last char in the file- did the offset based on either period, ! or ? (good punctuation) then WHILE looped those three iterations to COUT<<.
Not a trick as you guys could do, but a heck of a learning experience!

RE: Need C++ unencrypt text file (school)

I presume then you got your program working...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources