Need C++ Help, is this even possible?

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
darthdavid
Pathetic Attention Whore
Posts: 5470
Joined: 2003-02-17 12:04pm
Location: Bat Country!

Need C++ Help, is this even possible?

Post 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
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Post by Beowulf »

Err... put what you just said into algorithm. I can't really make heads or tails of what you just asked.
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
User avatar
Durandal
Bile-Driven Hate Machine
Posts: 17927
Joined: 2002-07-03 06:26pm
Location: Silicon Valley, CA
Contact:

Post by Durandal »

Uh ... so code it. What's the problem?
Damien Sorresso

"Ever see what them computa bitchez do to numbas? It ain't natural. Numbas ain't supposed to be code, they supposed to quantify shit."
- The Onion
User avatar
Solauren
Emperor's Hand
Posts: 10392
Joined: 2003-05-11 09:41pm

Post 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.
User avatar
Sarevok
The Fearless One
Posts: 10681
Joined: 2002-12-24 07:29am
Location: The Covenants last and final line of defense

Post 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. 8)
I have to tell you something everything I wrote above is a lie.
User avatar
StimNeuro
Padawan Learner
Posts: 444
Joined: 2002-11-11 02:58pm
Location: Marietta, GA

Post 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.
"Well, it's too bad that thread pilots aren't allow to carry pistols.
Otherwise they would have stopped you." - Pablo Sanchez
User avatar
Arrow
Jedi Council Member
Posts: 2283
Joined: 2003-01-12 09:14pm

Post 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.
Artillery. Its what's for dinner.
darthdavid
Pathetic Attention Whore
Posts: 5470
Joined: 2003-02-17 12:04pm
Location: Bat Country!

Post by darthdavid »

Thanks everyone I think I'll be able to do this now. :D
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post 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).

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
Post Reply