Help to create a DLL on BC 5.0++ 95

Could you tell me what i must declare to create a DLL on Borland C++ 5.0 32 bits
for Win 95 ?


I know i must declare something like VOID FAR PASCAL (DWORD ... ) but i
don"t know exactly what.

This for the function : pc3init, pc3saltinit, pc3encode, pc3decode in the
source below.

Please answer by mail

thanks



*********************************************************


#include <stdio.h>
#include <stdlib.h>
unsigned long a,b[128],index;
unsigned int r,cle;

/* PC3 Cipher (c) Alexandre PUKALL 1997 */
/* end on July 7, 1997 */
/* can be freely use */
/* but the name of the author must be included in the final software */
/* optimised for 32 bits computers */
/* if the key is bigger, the algorithm is slower */
/* a 20 characters key : 160 bits is enough for security */
/* can go up to 256 charcters key : 2048 bits key */

/* some explanations in english at the end of the source code */

stream(unsigned int *r,unsigned long *index,unsigned long *a,unsigned long
*b)
{
  b[*index] = ( b[*index] * (*a) ) + 1;
  *r = _rotl( (*r + (( b[*index] >> 16 ) & 0x7fff)), ((*r)%16) );
}

unsigned char pc3encode(unsigned char byte)
{
  unsigned short d;

     for (index=0;index<=(cle-1);index++)
     {
       stream(&r,&index,&a,b);
     }
   d=byte;
   byte=byte^(r&255);
   r=r+d;                  /* PC3 in PFB mode PFB ( Plaintext FeedBack ) */
   b[cle-1]=b[cle-1]+d;    /* each plaintext byte modify the encoding */
   return(byte);
}

unsigned char pc3decode(unsigned char byte)
{
  unsigned short d;

     for (index=0;index<=(cle-1);index++)
     {
       stream(&r,&index,&a,b);
     }
   byte=byte^(r&255);
   d=byte;
   r=r+d;                  /* PC3 in PFB mode ( Plaintext FeedBack ) */
   b[cle-1]=b[cle-1]+d;    /* each plaintext byte modify the encoding */
   return(byte);
}


pc3init(unsigned int lngkey,unsigned char key[258])
{
   unsigned int z,y,x,i;
   unsigned char tab[258],plain;
   div_t reste;
   if (lngkey>256) lngkey=256;
   if (lngkey<1)
   {
     lngkey=1;
     strcpy(key,"a");
   }

   x=lngkey;

   for (i=0;i<x;i++)
   {
     tab[i]=key[i];
   }

   reste=div(lngkey,2);
   cle=reste.quot;
   if (reste.rem!=0) cle=cle+1;   /* length of the key : must always be
even between 5 and 128 */
                          /* each on 16 bits */
   printf("%d\n",cle);
   for (z=0;z<128;z++)    /* clear the matrix of keys */
   {
    b[z]=0;
   }

   y=0;
   for (z=0;z<=(cle-1);z++)    /* create the key */
   {
    if ( (z==(cle-1))&&(reste.rem!=0) )
     {
       b[z]=key[y]*256;
     }
    else
     {
       b[z]=(key[y]*256)+key[y+1];
       y=y+1;
     }
    y=y+1;
   }

   r=0;
   a=0x015a4e35;

     for (index=0;index<=(cle-1);index++)
     {                                     /* init the keys */
       for(z=0;z<=index;z++)
       {
       stream(&r,&index,&a,b);
       }
     }

   for (i=0;i<x;i++)
   {
       plain=pc3encode(tab[i]);
       tab[i]=tab[i]^plain;
   }
  i=i-1;
   for (z=1;z<=((x+1)*10);z++)
   {
       plain=pc3encode(tab[i]);
       tab[i]=tab[i]^plain;
       i=i+1;
       if (i>=x) i=0;
   }

   reste=div(lngkey,2);
   cle=reste.quot;
   if (reste.rem!=0) cle=cle+1;

   for (z=0;z<128;z++)
   {
    b[z]=0;
   }

   y=0;
   for (z=0;z<=(cle-1);z++)
   {
    if ( (z==(cle-1))&&(reste.rem!=0) )
     {
       b[z]=tab[y]*256;
     }
    else
     {
       b[z]=(tab[y]*256)+tab[y+1];
       y=y+1;
     }
    y=y+1;
   }

   for (z=0;z<x;z++)
   {
     key[z]=0;
     tab[z]=0;
   }

   r=0;
   a=0x015a4e35;

     for (index=0;index<=(cle-1);index++)
     {
       for(z=0;z<=index;z++)
       {
       stream(&r,&index,&a,b);
       }
     }
}

pc3saltinit(unsigned int lngkey,unsigned char key[258],unsigned int
lngsalt,unsigned char salt[258])
{
   unsigned int z,y,x,i;
   unsigned char tab[516],plain;
   div_t reste;
   if (lngkey>256) lngkey=256;
   if (lngkey<1)
   {
     lngkey=1;
     strcpy(key,"a");
   }
   if (lngsalt>256) lngsalt=256;
   if (lngsalt<1)
   {
     lngsalt=1;
     strcpy(salt,"a");
   }

   x=lngkey;

   for (i=0;i<x;i++)
   {
     tab[i]=key[i];
   }

   for (i=x;i<(lngkey+lngsalt);i++)
   {
     tab[i]=salt[i-lngkey];
   }

   reste=div(lngkey,2);
   cle=reste.quot;
   if (reste.rem!=0) cle=cle+1;

   for (z=0;z<128;z++)
   {
    b[z]=0;
   }

   y=0;
   for (z=0;z<=(cle-1);z++)
   {
    if ( (z==(cle-1))&&(reste.rem!=0) )
     {
       b[z]=key[y]*256;
     }
    else
     {
       b[z]=(key[y]*256)+key[y+1];
       y=y+1;
     }
    y=y+1;
   }

   r=0;
   a=0x015a4e35;

     for (index=0;index<=(cle-1);index++)
     {
       for(z=0;z<=index;z++)
       {
       stream(&r,&index,&a,b);
       }
     }

   for (i=0;i<(lngkey+lngsalt);i++)
   {
       plain=pc3encode(tab[i]);
       tab[i]=tab[i]^plain;
   }
  i=i-1;
   for (z=1;z<=((lngkey+lngsalt+1)*10);z++)
   {
       plain=pc3encode(tab[i]);
       tab[i]=tab[i]^plain;
       i=i+1;
       if (i>=(lngkey+lngsalt)) i=0;
   }

   reste=div(lngkey,2);
   cle=reste.quot;
   if (reste.rem!=0) cle=cle+1;

   for (z=0;z<128;z++)
   {
    b[z]=0;
   }

   y=0;
   for (z=0;z<=(cle-1);z++)
   {
    if ( (z==(cle-1))&&(reste.rem!=0) )
     {
       b[z]=tab[y]*256;
     }
    else
     {
       b[z]=(tab[y]*256)+tab[y+1];
       y=y+1;
     }
    y=y+1;
   }

   for (z=0;z<x;z++)
   {
     key[z]=0;
   }
   for(z=0;z<(lngkey+lngsalt);z++)
   {
     tab[z]=0;
   }

   r=0;
   a=0x015a4e35;

     for (index=0;index<=(cle-1);index++)
     {
       for(z=0;z<=index;z++)
       {
       stream(&r,&index,&a,b);
       }
     }
}

***************************************************************
   NOT INCLUDED IN THE DLL
***************************************************************

main()
{
  unsigned int longueur,y,lngsalt;
  unsigned char code[21]="abcdefghijklmnopqrst";   /* user key can be
code[0]=0x25; code[1]=0xf7; ... */
  unsigned char salt[3]; /* length of the salt + 1 */
  FILE *in,*out;
  short c;
  longueur=20; /* length of the key up to 256 characters */
  lngsalt=2;
  salt[0]=0x47;
  salt[1]=0xf5;

  pc3saltinit(longueur,code,lngsalt,salt);

  /* the 2 is the length of the salt, the 0x47f5 is the salt on 16 bits =
2* 8 bits */
  /* the salt is a random value, like the time of the computer you give in
addition of the key */
  /* to change the result key, the salt must be write in a non encoded form
in the output file */
  /* to allow to decode the file with the user key */
  /* the salt value can go up to 256 characters */
  /* the PSCHF function in included when you run pc3salinit() */
  /* it give a random 8 bits keys even a 7 bits is given */
  /* for example you use pc3salinit() with the user key */
  /* and for the salt you give the time of the computer's clock + a counter
*/
  /* 1 for first message, 2 for second ... */
  /* you send the time and the counter in plaintext ( not encrypted ) */
  /* and after the message encrypted */
  /* the two users must have a secret share key */
   /* pc3init(longueur,code) has a PSCHF function too but not a salt
function */


  if ((in=fopen("essai.txt","rb"))==NULL) {printf("Error file ESSAI.TXT not
found !\n");exit(-1);}
  if ((out=fopen("sortie.Txt","wb"))==NULL) {printf("Error writing file
SORTIE.TXT !\n");exit(-1);}

  while ( (c=fgetc(in)) !=EOF )
  {
   fputc(pc3encode(c),out);
  }

  fclose(in);
  fclose(out);

  /* to decode use : */
  /* in=fopen("sortie.Txt","rb"); */
  /* out=fopen("essai.Txt","rb"); */
  /* while .... */
  /* fputc(pc3decode(c),out); */

}

*************************************************************
klimtAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ylCommented:
You shoud include <windows.h> in your source and declare the functions APIENTRY _export.
0
klimtAuthor Commented:
i would like to know what is must declare in the function , example :

pc3code(unsigned char byte) give me
pc3code(DWORD ... ) or something like this ?

0
ylCommented:
The following function prototype was successfuly compiled using BC 5:

extern "C" unsigned char APIENTRY _export pc3code(unsigned char byte)
{
}

What do you mean by: pc3code(unsigned char byte) give me pc3code(DWORD ... )?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
klimtAuthor Commented:
What do you mean by: pc3code(unsigned char byte) give me pc3code(DWORD ... )?

i have seen that some declaration uses
LPRST, DWORD, FAR PASCAL as definition ?

What is used for ?


0
ylCommented:
1. FAR PASCAL was used to declare exported functions in Win16. This declaration is no longer needed in Win32.
2. LPSTR and DWORD are typedefs defined in the windows include files, where LPSTR stands for FAR char* and DWORD for unsigned long. You can look them up in the include directory. They are used to declare parameter types for Windows API functions (you don't have to use them for your own functions).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.