Page 1 of 1
Need C++ Help, is this even possible?
Posted: 2005-12-13 10:34pm
by darthdavid
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
Posted: 2005-12-13 11:08pm
by Beowulf
Err... put what you just said into algorithm. I can't really make heads or tails of what you just asked.
Posted: 2005-12-13 11:25pm
by Durandal
Uh ... so code it. What's the problem?
Posted: 2005-12-14 12:49am
by Solauren
I'd translate the characters into there numeric ascii value and use that as the number to multiply by. This will let you handle a wider range of characters.
Posted: 2005-12-14 03:18am
by Sarevok
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.
Posted: 2005-12-14 04:38am
by StimNeuro
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.
Posted: 2005-12-14 10:53am
by Arrow
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?
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).
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.
Posted: 2005-12-14 05:05pm
by darthdavid
Thanks everyone I think I'll be able to do this now.
Posted: 2005-12-15 10:40am
by Pu-239
Arrow Mk84 wrote: And I've used __int64 on a number of occassions; I think this one is MS specific.
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).