|
So one day about a week ago i decided that i wanted to write simple encryption program. Being that im new to writing C++ code, and also a newb to VS 6 i decided that i would pick up a number theory book and use my C++ books as a reference to help me along the way to cyrptographic blissfulness, but this is not the case. I have and equations ( E = M^s (mod r) ) where M is the message, s and r are two coprime numbers and E is the encrypted output for the whole equation. Using numbers it works great, but (again beening a newb) I have run into the problem of how do i convert the input of text into and int that the computer can use in the equation? I also ran into the problem of really large numbers that are over 64-bits in length, but i solved that problem with a large number class ( CLargeNumbers ). So here I am stuck with text that i cant convert to an int. I also will need to convert the int back into text after i run the inverse equation to decrypt it. Please can anyone help me?
|
|
|
|
|
atoi (integer)
atof (double)
strtol (long)
are usefull functions to convert strings to numbers
and the operators
% is mod
^ is ^
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
isn't ^ pow here?
Don't try it, just do it!
|
|
|
|
|
|
Text is numbers. Or rather it's all a matter of how you look at it. A string inside the PC is just a sequence of numbers stored consecutively in memory. You should be able to operate directly on them. Unless you want the output to be printable?
How about posting a code snippet?
Paul
|
|
|
|
|
but in an equation (in a literal one i heard), we don't want letters to be interpreted as number otherwise the result wouldn't be function of the unknown...
TOXCCT >>> GEII power
|
|
|
|
|
Hi all;
I have recently downloaded SkinMagic in order to build skins rapidly for my educational application which is running out of schedule. I managed to make the skin and export the ".h" file. However, i really don't know what to do next to skin my SDI application. Can somebody please help me.
Thank you
Krugger
Build tomorrow today cos' tomorrow will be too late
|
|
|
|
|
call InitSkinMagicLib(...) and then LoadSkinFile(...) in your initinstance of your application.
check for more details in the samples that they have provided....
God is Real, unless declared Integer.
|
|
|
|
|
I'm considering an building a c++ application that I'd like to have the ability to update itself periodically. Patch software seems like overkill so I was wondering what mechanisms people have used?
My thought was to have a launcher exe (app_launcher.exe) which is the .exe launched by shortcuts and etc. It would query a reg path for the "true" exe (mainapp_ver1.exe) and launch that.
The main app, could then download a cab file when an update was available, unzip the contents (so we'd have mainapp_ver2.exe downloaded) and then update the reg string so the new exe is launched next time. I use different file names to prevent problems in trying to overwrite a currently running exe.
That's the basic concept but it just feels like an ugly architecture. Anyone have experience with this sort of thing and have any better ideas?
DJScrib.
|
|
|
|
|
scrib wrote:
I use different file names to prevent problems in trying to overwrite a currently running exe.
MoveFileEx(..., MOVEFILE_DELAY_UNTIL_REBOOT) will help here.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
An alternative would be a separate app that performs the updating and terminates the 'parent' app prior to performing the update. Many games use this tactic.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Hi,
Can anyone tell me if the VC++ Memory debug window displays memory LSB->MSB?
I have a buffer that should be :
80 00 00 00 40 00 00 00 00 00 00 00 80 00 00 00 20 00 00 00
but is displaying as
00 00 00 80 00 00 00 40 00 00 00 00 00 00 00 80 00 00 00 20
If I change the view to long hex format, it looks better but still isnt correct.
It also seem that if I write two consecutive U16s, then the first is in the lower 2 bytes and the second is in the uppoer to bytes for a 4 byte sequence.
I simply need to confirm that my memory buffer contains the correct order of bytes. If the VC++ memory window displays is LSB-MSB, I just want to confirm that.
Thanks.
-C
PS - Can anyone tell me why I'm getting a memory access violation for the last line of the following statement
msgBuffer = new char [100] ;
memset (&msgBuffer,0, 100);
memcpy (&msgBuffer,(char *) &ui , sizeof (ui));
msgBuffer [99] = '\0';
|
|
|
|
|
The memory window displays data sequentially. On Intel-style machines that would mean that it is LSB first.
On your memset calls, lose the the & on msgBuffer. It should be :
memset( msgBuffer, 0, sizeof( msgBuffer ) );
This is because the & means use the address of the pointer. You want just the pointer.
The point of all of this is to remove usage of literal constants. The reason is that if you need to bump that size to 200 then you would have to make changes in three places to accomodate that. That is a bad thing.
Also note that this is not ready for Unicode. That requires a different set of macros that calculate the size in characters, not bytes.
[edited - all wet]
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Rick York wrote:
memset( msgBuffer, 0, sizeof( msgBuffer ) );
I guess you made a small unknown mistake, msgBuffer is a pointer so sizeof(pointer) will return 4 .
God is Real, unless declared Integer.
|
|
|
|
|
Quite right ! That'll teach me to answer questions on a Monday morning.
Never mind.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
So my buffer will be displayed LSB first in the memory window, if I print it out, it should show how I want it to be right?
But when I try to do
for (int i=0, i< 100; i++)
printf ("%X", msgBuffer[i]);
I keep getting memory access errors.
If I cant look in the memory window or print it out, how can I verify my buffer. Any ideas?
-C
|
|
|
|
|
msgBuffer = new char [100] ;
Sets msgBuffer to the address of a an array of 100 characters. Fine.
memset (&msgBuffer,0, 100);
Overwrites the value of msgBuffer from the address of the array to 0, and then overwrites another 96 bytes with 0. Very wrong.
After that almost everything will fail sooner or later.
If you display in 'bytes' then the memory window will show a value of 0x04030201 as
01 02 03 04
IOW LSB first.
Paul
|
|
|
|
|
why are you bothering to allocate a new msgBuffer ?
Why not use a stack variable for this ?
or a declared member variable ?
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Regardless if I use a stack variable or a member variable, I have to create it, initialize it, and copy my data into it. I'm at the beginning stages of writing a device driver sending msgs back/forth serially. So I'd like to verify now, early in the development, that I"m creating my buffers correctly.
I've realized that I need to byte swap my shorts and longs so that the buffer is properly sent.
Thanks for all the assistance and corrections.
-C
|
|
|
|
|
Hello. When I write something like:
---
class test{
public:
CBrush f;
};
int main()
{
test t;
vector<test> hej;
hej.push_back(t);
}
---
I get an error in <vector>: ...\include\vector(575): error C2440: 'initializing' : cannot convert from 'const test' to 'test'
But if I replace CBrush with one of my own classes, i everything works fine! What is it with those MFC classes?
|
|
|
|
|
I would say the copy constructor
anyway its better to store a pointer to your class
try:
vector<test*> hej;
hej.push_back(&t);
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
How smart is it to store a pointer if the object you added to the vector goes out of scope?
I know that isn't the case right here, but generally speaking...
|
|
|
|
|
if it will goes out of scope just new it first
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Why did you want to use a pointer in the first place? What is the advantage?
|
|
|
|
|
For various reasons:
Parameter passing to a function of objects is always better by pointer or by reference, the copy time is smaller and faster.
and the allocator of your vector is faster too because you wouldn't reallocate data or allocate chunks often.
and much more too like copy modifications ...
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|