![]() |
|
#11
|
||||
|
||||
|
Here you go. Main source code is in the file CryptSource.cpp. I changed everything back to the way it was before I tried to fix the problem... making the variable 'line' in the DecryptBtnClick function static helped, because it seems to get mangled whenever the function is not in control. Same with the ifstream variable. I think it was getting mangled too. I put in a bunch of quick comments to make the code a little easier to read. Thanks for your help!
|
||||
|
#12
|
||||
|
||||
|
I think you may be having a memory problem here.
CPP / C++ / C Code:
Your string is going to be at least 3 digits long (remember the string terminator). So you are defining a string to be 2 charecters and then cramming in 3 charecters. The *problem* with C is that it allows you to do this, which means you could be overwriting anything. Also as far as I can tell, this: CPP / C++ / C Code:
CPP / C++ / C Code:
Last edited by dsmith : 17-Feb-2004 at 14:25.
Reason: Made small syntax error (+ instead of -)
|
|
#13
|
||||
|
||||
|
Yeah, as you can see, I'm not a very experienced coder at all. Thanks for the help. I really should've spotted the problem with intString, but I just am not experienced enough to reduce things quite so easily as far as the other stuff goes.
edit: re-wrote things to match your advice. works great now. although i feel pretty stupid for not being able to reduce such a simple encryption/decryption algorithm. Thanks for all of your help! Apparently my algorithm still needs a little work, because it spits out some weird stuff when I start putting more than one line of text into it :-P edit again: ok well i figured that i was getting garbled text because i hadn't counted on encrypting a character that would be 3 digits long. so i just said screw it all and added a space each time i encrypt a character. now i just read an int of any length, since that doesn't include whitespace, and cast it as a char. viola. much easier, and no headaches. |
|
#14
|
||||
|
||||
|
I think you are doing a fine job. Little things like this can always get you, especially in C. C is such a powerful language, because it really exposes the underneath workings to the coder. That is why it is so easy to tromp all over your memory.
Another thing to remember about C is that the types are really quite basic. On most modern compilers there is absolutely no difference between a char and an int and all any type comes down to is how big of memory allocation does it need. (Earlier compilers used 8-bit chars & 16-bit ints). Expanding on Walts code a bit, try: CPP / C++ / C Code:
Anyway, I will take another look at your code and see if I can see why it doesn't work after the first line... |
|
#15
|
||||
|
||||
|
Actually it starts garbling after a space. I don't know why the bias would cause it, so I'm going to say the bias isn't causing it. I'm pretty sure there are only 127 basic ascii values that i'm dealing with... and since 127 - 33 leaves me with a number less than 100, I shouldn't be dealing with any numbers greater than 2 digits... it's weird though, because if I typed it out, some of it would come out ok, but it would be all garbled up. Kind of like a burnt letter. Some parts survive, but most of it's crap. Usually starts getting garbled after a space is entered.
Ok got it to accept spaces and newlines, changed the test in the encryption algorithm from a-33 > 0 to a-33 >= 0, and changed the return 0; at the end of my encryption algorithm to return 00; It won't take a newline unless i have an exclamation point at the end. I'm running through debug to see what the heck is going on. |
|
#16
|
|||
|
|||
|
Hi, Aaron. If I understand your problem, I think the attached code
is an abstraction of your problem. Note that this illegal activity in memory may not cause obvious problems in the small test case, but could be disastrous in the context of a larger application. Bottom line: you can't prove a program is correct by testing (!) Or, as one of my old math professors might put it, "Testing is a necessary, but not sufficient condition to have full confidence in your code." Regards, Dave CPP / C++ / C Code:
|
|
#17
|
||||
|
||||
|
Thank you. I am fully aware of buffer overflow and how to keep it from happening. I designed that program just to see if I could successfully convert a file full of numbers into some readable text. I didn't really go through it very logically, and I ended up tossing it out. Thanks again for the input, though!
|
|
#18
|
|||
|
|||
|
Quote:
My final word: If you printf() with %c rather than %d, you may get closer to what you were attempting. Cheers! Dave |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help.... SLR * algorithm | tay | C Programming Language | 4 | 10-Sep-2004 12:48 |
| Color scale algorithm | Ilya | C++ Forum | 0 | 28-Oct-2003 12:07 |
| algorithm question | calculus87 | C Programming Language | 1 | 11-Oct-2003 10:24 |
| simple form from generated page | zuzupus | Web Design Forum | 0 | 17-Sep-2003 10:27 |
| Generating simple URLs for search engines | jrobbio | MySQL / PHP Forum | 1 | 17-Mar-2003 12:22 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The