I'm trying to design a relatively simple encryption program. The current function I have in mind would multiply each letter's place in the alphabet by a 2 digit int constant, add 1 to the value and then generate a random letter to show the decrypt function where each string of numbers representing a letter ends and wher the next begins. I don't want you to write my code for me, I'm doing this on my own to learn and I won't if I don't have to do the dirty work. But I need to know some things to procede
1) Is this even possible without hacking around some limitations I'm not aware of or something else that makes this more work than I could hope to do?
2) If the answer to one is favorable, what are some general directions I need to be looking in to in order to accomplish this?
Thanks for taking the time to read this,
-DarthDavid
Need C++ Help, is this even possible?
Moderator: Thanas
-
- Pathetic Attention Whore
- Posts: 5470
- Joined: 2003-02-17 12:04pm
- Location: Bat Country!
- Sarevok
- The Fearless One
- Posts: 10681
- Joined: 2002-12-24 07:29am
- Location: The Covenants last and final line of defense
You are introducing complexity where none are needed. Just walk through the string and multiply each character’s ASCII value with a key value int supplied by the user. After that if someone tries to load the string all they can read is garbled text. When decrypting the program asks for the key and that key value is used to divide each characters value and recover the original string. The algorithm is very simple I am sure you could spice it up to make it harder to crack. If you are still clueless ask me to write it in code for you.
I have to tell you something everything I wrote above is a lie.
So you want to turn "help" into "17112533" with 4 random letters showing the decrypt program that the numbers are 17, 11, 25, and 33?
You'll need to store the generated numbers as a String if you want any message to be longer than whatever the maximum value of an int(double?float?) is in C++. What this means is that the above message will go from being a char[4] array to a char[12] array. Even in a best case where the message is "aaaa" -> "3333" with 4 letters, you've still got a char[8] array. For transmission purposes, you've just doubled to tripled the amount of work needed to send a message.
Side note: I'm a Java guy instead of C++, though I do know that C++ stores it's Strings in char arrays(right?). Question is, what's the max number value you can store in C++? Is there an equivalent to the Double or Float class in Java?
Like Solauren said, use the ascii value instead of the place in the alphabet. That will allow you to encrypt punctuation and spacing, which can be very useful in cracking a message.
One thing I'm confused about is this random letter generation. Anytime you generate a random on the encrypt end without passing it to the decrypt end(i.e. storing it in the message and defeating the point of having a random number), you run into problems.
You'll need to store the generated numbers as a String if you want any message to be longer than whatever the maximum value of an int(double?float?) is in C++. What this means is that the above message will go from being a char[4] array to a char[12] array. Even in a best case where the message is "aaaa" -> "3333" with 4 letters, you've still got a char[8] array. For transmission purposes, you've just doubled to tripled the amount of work needed to send a message.
Side note: I'm a Java guy instead of C++, though I do know that C++ stores it's Strings in char arrays(right?). Question is, what's the max number value you can store in C++? Is there an equivalent to the Double or Float class in Java?
Like Solauren said, use the ascii value instead of the place in the alphabet. That will allow you to encrypt punctuation and spacing, which can be very useful in cracking a message.
One thing I'm confused about is this random letter generation. Anytime you generate a random on the encrypt end without passing it to the decrypt end(i.e. storing it in the message and defeating the point of having a random number), you run into problems.
"Well, it's too bad that thread pilots aren't allow to carry pistols.
Otherwise they would have stopped you." - Pablo Sanchez
Otherwise they would have stopped you." - Pablo Sanchez
Char arrays is the most basic way of storing string data. There's also STL strings, which are similar to Java's strings (IIRC, its been a couple of years since I've done any Java), and there are other string classes, such as Microsoft's MFC CString class. For the encryption program, char array's are probably the easiest way to go (or using a std::string with the [] operator for a little extra typing).StimNeuro wrote: Side note: I'm a Java guy instead of C++, though I do know that C++ stores it's Strings in char arrays(right?). Question is, what's the max number value you can store in C++? Is there an equivalent to the Double or Float class in Java?
Double and float primatives exist in C/C++, and while I'm not aware of any STL Double or Float class, you can easily manipulate them with operators and various C conversion functions (atof() turns your string into a float, fcvt() will convert the float back to a string). Also, there isn't a max number value that C/C++ is limited to, so long as you typedef it. I've seen long doubles (16 byte instead ot 8 byte) and complex number data types. And I've used __int64 on a number of occassions; I think this one is MS specific.
Artillery. Its what's for dinner.
-
- Pathetic Attention Whore
- Posts: 5470
- Joined: 2003-02-17 12:04pm
- Location: Bat Country!
You can use "long long int" on gcc/g++ (I think it's part of the C99 standard but not C++, but it works anyway).Arrow Mk84 wrote: And I've used __int64 on a number of occassions; I think this one is MS specific.
ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer
George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor