Advice on a cipher program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Advice on a cipher program

  1. #1
    Join Date
    Oct 2011
    Posts
    91

    Advice on a cipher program

    Hello,

    I am hoping someone can give me some advice on a visual studio program I need to write. (I assume this is the right place to post).

    I have to wrote a program that displays a dialog box with three edit controls where I can enter the string of ciphered text, another to see the result of the cipher string and the final to enter the cipher code. There is also to be two buttons on the dialog box to execute the encipher and decipher operations.

    We have also being given an algorithm for generating random numbers.

    Now, of course, building the dialog box is no problem, and I have been able to do a few simple things with the buttons ...you know, like adding two figures in the boxes together etc., just to make sure things are working.

    But now, I just don't know what I need to do with this algorithm. Can I use the same algorithm for cipher and decipher ...For example, if I open the code for say the Cipher button do I enter the code under 'public:' (?) and if I do, will the same code work for cipher and decipher?

    I hope I am making sense here.

    Thanks in advance for any advice you can give me.

    Seán

  2. #2
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Advice on a cipher program

    Quote Originally Posted by o.fithcheallaigh View Post
    Hello,

    I am hoping someone can give me some advice on a visual studio program I need to write. (I assume this is the right place to post).

    I have to wrote a program that displays a dialog box with three edit controls where I can enter the string of ciphered text, another to see the result of the cipher string and the final to enter the cipher code. There is also to be two buttons on the dialog box to execute the encipher and decipher operations.

    We have also being given an algorithm for generating random numbers.

    Now, of course, building the dialog box is no problem, and I have been able to do a few simple things with the buttons ...you know, like adding two figures in the boxes together etc., just to make sure things are working.

    But now, I just don't know what I need to do with this algorithm. Can I use the same algorithm for cipher and decipher ...For example, if I open the code for say the Cipher button do I enter the code under 'public:' (?) and if I do, will the same code work for cipher and decipher?

    I hope I am making sense here.

    Thanks in advance for any advice you can give me.

    Seán
    The first thing you do is decouple your UI from your business logic. There is no need to mention dialogs, buttons, etc. at all at this stage.

    You have two functions, a cipher function and a decipher function. You should implement these functions, regardless of whether the data is coming from a dialog box, keyboard, from a file, a socket, etc. In other words, the function has no idea where that string comes from. More than likely, the string(s) are passed as parameters to these functions.

    Once you have those functions working, then you can call these functions in any way you want, via a "button push", or the string is retrieved from a file(s), etc.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2011
    Posts
    91

    Re: Advice on a cipher program

    Hello,

    Thanks for the reply.

    This is my first time using Visual Studio, so it is all a bit new to me.

    Seán

  4. #4
    Join Date
    Oct 2011
    Posts
    91

    Re: Advice on a cipher program

    Hello again.

    I hope everyone is well.

    I am still having a few issues. I am still having a few issues getting this program going. I have put the encryption program below. I am just not sure how to use this program. So I'm hoping someone could give me some pointers.

    Thanks in advance.

    Code:
    double ran2(int &idum)
    {
    	const int IM1=2147483563, IM2=2147483399;
    	const int IA1=40014, IA2=40692, IQ1=53668, IQ2=52774;
    	const int IR1=12211, IR2=3791, NTAB=32, IMM1 = IM1-1;
    	const int NDIV=1+IMM1/NTAB;
    	const double EPS=3.0e-16, RNMX=1.0-EPS, AM1.0/(double)(IM1);
    	static int idum2=123456789, iy=0;
    	static int iv[NTAB];
    	int j,k;
    	double temp;
    
    	if (idum <= 0)
    	{
    		idum=(idum==0 ? 1 : -idum);
    		idum2=idum;
    		for (j=NTAB+7; j>=0; j--){
    			idum=IA1*(idum-k*IQ1)-k*IR1;
    			if (idum<0) idum += IM1;
    			if (j<NYAB) iv[j] = idum;
    		}
    		iy=iv[0];
    	}
    	k=idum/IQ1;
    	idum=IA1*(idum-k*IQ1)-k*IR1;
    	if(idum<0) idum += IM1;
    	k=idum2/IQ2;
    	idum2=IA2*(idum2-k*IQ2)-k*IR2;
    	if(idum2<0) idum2 += IM2;
    	j=iy/NDIV;
    	iy=iv[j]-idum2;
    	iv[j]=idum;
    	if(iy<1)iy += IMM1;
    	if((temp=AM*iy)>RNMX) return RNMX;
    	else return temp;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center