c++ programming and ns2

This is a discussion on c++ programming and ns2 within the C++ Programming forums, part of the General Programming Boards category; hi; i wrote a c++ code rsa.cpp and rsa.h in order to make a new agent in ns2 called and ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    Post c++ programming and ns2

    hi;
    i wrote a c++ code rsa.cpp and rsa.h in order to make a new agent in ns2 called and my project consist that all packet in the traffic are crypted with rsa and this is my code :

    Code:
    /* C program for the Implementation Of RSA Algorithm */
    
    #include <stdio.h>
    #include <ncurses.h>
    #include <stdlib.h>
    #include <math.h>
    #include <packet.h>
    #include <agent.h>
    #include <tclcl.h>
    #include "rsa.h"
    
    using namespace std;
    
    int TCL_OK,phi,M,n,e,d,C,FLAG,i,p,q,s;
    
    static class rsaClass:public TclClass{
     public:
             rsaClass(): TclClass("Agent/rsa"){
    
             }
             TclObject* create(int argc,const char*const argv)
             {
    
             return (new rsa());
    
              }
    }Class_rsa;
    
    
    
    rsa::rsa(): Agent(PT_RSA)
    /*binding the tcl variable - c++ vraiable*/
    {
    
      bind("phi_otcl",&phi);
      bind("M_otcl",&M);
      bind("C_otcl",&C);
      bind("n_otcl",&n);
      bind("e_otcl",&e);
      bind("d_otcl",&d);
      bind("FLAG_otcl",&FLAG);
      bind("i_otcl",&i);
      bind("p_otcl",&p);
      bind("q_otcl",q);
      bind("s_otcl",s);
    
     };
    
    
    //le code rsa en c++//
    int
    rsa::check()
    {
    	int i;
    	for(i=3;e%i==0 && phi%i==0;i+2)
    	{
    	FLAG = 1;
    	return 0;
    	}
    	FLAG = 0;
    }
    void
    rsa::encrypt()
    {
    	int i;
    	C = 1;
    	for(i=0;i< e;i++)
    	C=C*M%n;
    	C = C%n;
    	printf("\n\tEncrypted keyword : %d",C);
    }
    void
    rsa::decrypt()
    {
    	int i;
    	M = 1;
    	for(i=0;i< d;i++)
    	M=M*C%n;
    	M = M%n;
    	printf("\n\tDecrypted keyword : %d",M);
    }
    int
    rsa::main()
    {
    	int p,q,s;
    
    	printf("Enter Two Relatively Prime Numbers\t: ");
    	scanf("%d%d",&p,&q);
    	n = p*q;
    	phi=(p-1)*(q-1);
    	printf("\n\tF(n)\t= %d",phi);
    	do
    	{
    	printf("\n\nEnter e\t: ");
    	scanf("%d",&e);
    	check();
    	}while(FLAG==1);
    	d = 1;
    	do
    	{
    	s = (d*e)%phi;
    	d++;
    	}while(s!=1);
    	d = d-1;
    	printf("\n\tPublic Key\t: {%d,%d}",e,n);
    	printf("\n\tPrivate Key\t: {%d,%d}",d,n);
    	printf("\n\nEnter The Plain Text\t: ");
    	scanf("%d",&M);
    	encrypt();
    }
    
    
    /*command*/
    
    int
    rsa::command(int argc,const char*const*argv)
    {
    if (argc==2){
    if (strcmp(argv[1],"encrypt")==0){
      encrypt();
      return (TCL_OK);};
    }
    return (Agent::command(argc,argv));
    }



    and when i try to compile the whole project it say that there is an error in rsa.cpp
    and the error is
    cannot convert rsa to tclobjet in return????
    pleasse i neeed really help .????

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,681
    Is it that line below?
    Code:
    static class rsaClass:public TclClass{
     public:
             rsaClass(): TclClass("Agent/rsa"){
    
             }
             TclObject* create(int argc,const char*const argv)
             {
    
             return (new rsa());
    
              }
    }Class_rsa;
    Is an rsa object built off of a TclObject?
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    yahh the line "return (new rsa());" it says cannot convert rsa* to tclObject*.
    i figured out how the tcp application is implemented and i see that it is like i did for rsa.
    so i really cant see where is the problem.
    thanks.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21