     /**************************************************************************

     *

     * This code is only for demo and educational use only

     *

     * The HASP(R)codegenerator and its documentation are copyrighted by //UCL.

     * All rights reserved.

     *

     *This is *completely* HASP seed code generator for NetHASP(TM), MacHASP(TM),

     *DataHASP(TM), TimeHASP(TM), SerialHASP(TM), HASP36(TM), MemoHASP36(TM),

     *NetHASP36(TM), OpenHASP(TM), HASPCard(TM) of Aladdin Knowledge Systems Ltd.

     *

     * (c)1998 by MeteO, Fixit

     * e-mail us: meteo@null.net

     * admin@fixit.spb.ru

     *************************************************************************/



     #include 



     long pwd;

     char al_buf[8];

     static unsigned char ch[10];

     unsigned int tab[64];

     unsigned int seed,j,k;



     HASP_rows[8][8]={

     {0,0,0,0,0,0,0,0},

     {0,1,0,1,0,1,0,1},

     {1,0,1,0,1,0,1,0},

     {0,0,1,1,0,0,1,1},

     {1,1,0,0,1,1,0,0},

     {0,0,0,0,1,1,1,1},

     {1,1,1,1,0,0,0,0},

     {1,1,1,1,1,1,1,1}

     };



     /***************************************

     The table is represented as triads

     ***************************************/



     void xor_pwd(void)

     {

     int i;



     pwd^=0x09071966; /* Maybe birthday of president of US? ;)*/



     for(i=0;i<8;i++)

     {

     al_buf[i]= pwd & 7;

     pwd = pwd >> 3;

     }

     };



     /***************************************

     Main function (HASP_seed)

     Original code by bajunny

     ****************************************/



     void emulate_func2( unsigned short seed)

     {

     int i, j;



     for(i=0;i<8;i++)

     {

     ch[i] = 0;

     for(j=0;j<8;j++)

     {

     seed *= 0x1989;

     seed += 5;

     ch[i] |= (tab[(seed>>9)&0x3f]) << (7-j);

     }

     }

     }





     void main(void)

     {

     int i;

     printf(" Input 1st HASP password:");

     scanf("%4X",(int*) &j);

     printf("Input 2nd HASP password:");

     scanf("%4X",(int*) &k);



     pwd=(long) k*0x10000+j;

     printf(" Input HASP seedcode:");

     scanf("%x",&seed);



     xor_pwd();



     /************************************

     Compute universal secret table

     *************************************/



     for(i=0;i<8;i++){

     for(j=0;j<8;j++){tab[i+j*8]=HASP_rows[al_buf[i]][j];}

     }



     for(i=0;i<8;i++){

     for(j=0;j<8;j++){printf("%1.1d",tab[i*8+j]);}

     printf(" ");

     }



     emulate_func2(seed);



     for(i=0;i<4;i++)

     {printf("%2.2X%2.2X ", ch[i*2+1],ch[i*2]);}



     }