![]() |
|
#1
|
||||
|
||||
Simple Encryption AlgorithmOk, I've made a very simple encryption algorithm that encrypts text one character at a time. Here's the code for my encryption function. It uses ASCII code to convert the character to an integer. I only wanted ASCII characters greater than or equal to "!", so I subtracted 33 from the code number to make things easier.
CPP / C++ / C Code:
I made my own character references for spaces and newlines... just so I can keep track of them. My decryption algorithm is non-existent. I don't know how to convert a number back to a character based on ascii code... any ideas? |
|
#2
|
||||
|
||||
|
Considering your code, I don't understand what you are asking. Your are correctly using the 'character' value as a number in your posted code. Why can't you simply reverse the process?
Your current code uses a loop: CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#3
|
||||
|
||||
|
Because you can't increment a letter. If I have a char variable x initialized to ascii letter 'a', I can't say x++ and get 'b', can I? Argh. My brain isn't working. All I want to do is be able to take a 2 digit number from a file, add 33 to it, and turn it into a char. Uh... did I just solve the problem?
Btw, I see how your idea works and it's much more efficient. Thanks |
|
#4
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
A letter is just a display of the value of the letter. For example the letter 'A' inside the computer is the integer value 65. If you output as an int (%d), you get 65 char (%c) you get 'A' hex value (%x), 41 Do whatever math you want on it. ('A' * 2) - 'H' = ':' Expand the above code to print all the characters from 32 (space) to 255 (highest ascii value) in a chart. A very useful tool I use constantly. |
|
#5
|
||||
|
||||
|
Quote:
OK. I got the decryption algorithm to work, but Borland is giving me some really freaking weird errors that shouldn't be happening. Something keeps using the same memory space that my variables are using, because they keep getting wiped out. I have to make them static just so they don't get destroyed, which is highly unusual. |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
||||
|
||||
|
Well I'm also getting errors when the program finishes. My little box pops up and says that the decryption completed successfully, then the program gives me a write to address error. But it only happens after my last line of code is executed. I checked out my variables and they are fine. The decryption works like a charm. The program just has a huge fit at the end for some really strange reason. I think my borland installation might have been corrupted...
|
|
#8
|
||||
|
||||
|
Hi aaron. It seems strange that you would be having memory allocation problems with this. If you get a chance, try to upload what you have. If it is kind of big, just upload it as an attachment.
|
|
#9
|
||||
|
||||
|
Quote:
Do you have borland builder 6? This is a windows program built in borland builder 6. I bet I wouldn't have any problem at all if it were a console app with the same core code. |
|
#10
|
||||
|
||||
|
Hi Aaron. I am not so interesed in the interface specific stuff, but more the decryption routine and how you are calling it etc. I won't be able to build your project without some porting, but I (or someone else) may be able to see where a mem alloc error could be occuring.
|
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| 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 11:48 |
| Color scale algorithm | Ilya | C++ Forum | 0 | 28-Oct-2003 11:07 |
| algorithm question | calculus87 | C Programming Language | 1 | 11-Oct-2003 09:24 |
| simple form from generated page | zuzupus | Web Design Forum | 0 | 17-Sep-2003 09:27 |
| Generating simple URLs for search engines | jrobbio | MySQL / PHP Forum | 1 | 17-Mar-2003 11:22 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The