0 0

求C转JAVA10

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    /*
    #include "encrypt.h"
    */

    #define  ENCRYPT 0
    #define  DECRYPT 1

    static void pack8();
    static void unpack8();
    unsigned char   KS[16][48];

    void DES_setkey( int sw,             /* type cryption: 0=encrypt,1=decrypt   */
             unsigned char *pkey          /* 64-bit key packed into 8 unsigned chars       */
                   )
    {
       register unsigned char i, j, k, t1, t2;
       static   unsigned char key[64];
       static   unsigned char CD[56];

       /* Schedule of left shifts for C and D blocks */
       unsigned short shifts[] = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1 };

       /* PERMUTED CHOICE 1 (PC1) */
       unsigned char PC1[] = {
          57, 49, 41, 33, 25, 17,  9,
           1, 58, 50, 42, 34, 26, 18,
          10,  2, 59, 51, 43, 35, 27,
          19, 11,  3, 60, 52, 44, 36,
          63, 55, 47, 39, 31, 23, 15,
          7, 62, 54, 46, 38, 30, 22,
          14,  6, 61, 53, 45, 37, 29,
          21, 13,  5, 28, 20, 12,  4
       };

       /* PERMUTED CHOICE 2 (PC2) */
       unsigned char PC2[] = {
          14, 17, 11, 24,  1,  5,
           3, 28, 15,  6, 21, 10,
          23, 19, 12,  4, 26,  8,
          16,  7, 27, 20, 13,  2,
          41, 52, 31, 37, 47, 55,
          30, 40, 51, 45, 33, 48,
          44, 49, 39, 56, 34, 53,
          46, 42, 50, 36, 29, 32
       };

       /* Assume default algorymth = crypt */
       if( sw != ENCRYPT && sw != DECRYPT )
          sw = ENCRYPT;

       /* Unpack KEY from 8 bits/unsigned char into 1 bit/unsigned char */
       unpack8( (unsigned char *)pkey, key );

       /* Permute unpacked key with PC1 to generate C and D */
       for( i = 0; i < 56; i++ )
          CD[i] = key[ PC1[i] - 1 ];

       /* Rotate and permute C and D to generate 16 subkeys */
       for( i = 0; i < 16; i++ ) {
          /* Rotate C and D */
          for( j = 0; j < shifts[i]; j++ ) {
             t1 = CD[0];
             t2 = CD[28];
             for( k = 0; k < 27; k++ ) {
                CD[k] = CD[k+1];
                CD[k+28] = CD[k+29];
             }
             CD[27] = t1;
         CD[55] = t2;
          }
          /* Set order of subkeys for type of cryption */
          j = sw ? 15-i : i;
          /* Permute C and D with PC2 to generate KS[j] */
          for( k = 0; k < 48; k++ )
             KS[j][k] = CD[ PC2[k] - 1 ];
       }
       return;
    }
    /******************************************************************************
    *  DES()                                                                     *
    ******************************************************************************/


    void DES_calcul( unsigned char *in,             /* packed 64-bit INPUT block           */
    unsigned char *out             /* packed 64-bit OUTPUT block          */
                   )
    {
       register unsigned char i, j, k, t;
       static   unsigned char block[64];            /* unpacked 64-bit input/output block  */
       static   unsigned char LR[64], f[32], preS[48];

       /* INITIAL PERMUTATION (IP) */
       unsigned char IP[] = {
          58, 50, 42, 34, 26, 18, 10,  2,
          60, 52, 44, 36, 28, 20, 12,  4,
          62, 54, 46, 38, 30, 22, 14,  6,
          64, 56, 48, 40, 32, 24, 16,  8,
          57, 49, 41, 33, 25, 17,  9,  1,
          59, 51, 43, 35, 27, 19, 11,  3,
          61, 53, 45, 37, 29, 21, 13,  5,
          63, 55, 47, 39, 31, 23, 15,  7
       };

       /* REVERSE FINAL PERMUTATION (IP-1) */
       unsigned char RFP[] = {
          8, 40, 16, 48, 24, 56, 32, 64,
          7, 39, 15, 47, 23, 55, 31, 63,
          6, 38, 14, 46, 22, 54, 30, 62,
          5, 37, 13, 45, 21, 53, 29, 61,
          4, 36, 12, 44, 20, 52, 28, 60,
          3, 35, 11, 43, 19, 51, 27, 59,
          2, 34, 10, 42, 18, 50, 26, 58,
          1, 33,  9, 41, 17, 49, 25, 57
       };

       /* E BIT-SELECTION TABLE */
       unsigned char E[] = {
          32,  1,  2,  3,  4,  5,
           4,  5,  6,  7,  8,  9,
           8,  9, 10, 11, 12, 13,
          12, 13, 14, 15, 16, 17,
          16, 17, 18, 19, 20, 21,
          20, 21, 22, 23, 24, 25,
          24, 25, 26, 27, 28, 29,
          28, 29, 30, 31, 32,  1
       };

       /* PERMUTATION FUNCTION P */
       unsigned char P[] = {
          16,  7, 20, 21,
          29, 12, 28, 17,
           1, 15, 23, 26,
           5, 18, 31, 10,
           2,  8, 24, 14,
          32, 27,  3,  9,
          19, 13, 30,  6,
          22, 11,  4, 25
       };

       /* 8 S-BOXES */
       unsigned char S[8][64] = {
          14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
           0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
           4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
          15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13,

          15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
           3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
           0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
          13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9,

          10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
          13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
          13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
           1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12,

           7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
          13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
          10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
           3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14,

           2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
          14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
           4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
          11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3,

          12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
          10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
           9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
           4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13,

           4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
          13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
           1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
           6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12,

          13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
           1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
           7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
           2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11
       };


       /* Unpack the INPUT block */
       unpack8( (unsigned char *)in, block );

       /* Permute unpacked input block with IP to generate L and R */
       for( j = 0; j < 64; j++ )
          LR[j] = block[ IP[j] - 1 ];

       /* Perform 16 rounds */
       for( i = 0; i < 16; i++ ) {
          /* Expand R to 48 bits with E and XOR with i-th subkey */
          for( j = 0; j < 48; j++ )
             preS[j] = LR[E[j]+31] ^ KS[i][j];

          /* Map 8 6-bit blocks into 8 4-bit blocks using S-Boxes */
          for( j = 0; j < 8; j++ ) {
             /* Compute index t into j-th S-box */
             k = 6 * j;
             t = preS[k];
             t = ( t << 1 ) | preS[k+5];
             t = ( t << 1 ) | preS[k+1];
             t = ( t << 1 ) | preS[k+2];
             t = ( t << 1 ) | preS[k+3];
             t = ( t << 1 ) | preS[k+4];
             /* Fetch t-th entry from j-th S-box */
             t = S[j][t];
             /* Generate 4-bit block from S-box entry */
             k = 4 * j;
             f[k]   = ( t >> 3 ) & 1;
             f[k+1] = ( t >> 2 ) & 1;
             f[k+2] = ( t >> 1 ) & 1;
             f[k+3] = t & 1;
          }

          for( j = 0; j < 32; j++ ) {
             /* Copy R */
             t = LR[j+32];
             /* Permute f w/ P and XOR w/ L to generate new R */
             LR[j+32] = LR[j] ^ f[P[j]-1];
             /* Copy original R to new L */
             LR[j] = t;
          }
       }

       /* Permute L and R with reverse IP-1 to generate output block */
       for( j = 0; j < 64; j++ )
          block[j] = LR[ RFP[j] - 1 ];

       /* Pack data into 8 bits per unsigned char */
       pack8( (unsigned char *)out, block );
    }


    /******************************************************************************
    *  PACK8()  Pack 64 unsigned chars at 1 bit/unsigned char into 8 unsigned chars at 8 bits/unsigned char          *
    ******************************************************************************/

    static void pack8(
       unsigned char *packed,               /* packed block ( 8 unsigned chars at 8 bits/unsigned char)      */
       unsigned char *binary                /* the unpacked block (64 unsigned chars at 1 bit/unsigned char) */
    )
    {
       register unsigned char i, j, k;

       for( i = 0; i < 8; i++ ) {
          k = 0;
          for( j = 0; j < 8; j++ )
             k = ( k<<1 ) + *binary++;
          *packed++ = k;
       }
    }

    /******************************************************************************
    *  UNPACK8()  Unpack 8 unsigned chars at 8 bits/unsigned char into 64 unsigned chars at 1 bit/unsigned char      *
    ******************************************************************************/

    static void unpack8(
       unsigned char *packed,             /* packed block (8 unsigned chars at 8 bits/unsigned char)         */
       unsigned char *binary              /* unpacked block (64 unsigned chars at 1 bit/unsigned char)       */
    )
    {
       register unsigned char i, j, k;

       for( i = 0; i < 8; i++ ) {
          k = *packed++;
          for( j = 0; j < 8; j++ )
             *binary++ = ( k >> (7-j) ) & 0x01;
       }
    }

    int tostring(int inlen, unsigned char *instr, char *outstr)
    {
    int i;
    char tmp[3];

    sprintf( outstr, "%02X", instr[0] );
    outstr[2] = 0;
    for (i=1;i<inlen;i++){
    sprintf( tmp, "%02X", instr[i] );
    tmp[2] = 0;
    strcat( outstr, tmp );
    }
    i = inlen * 2;
    outstr[i] = 0;

    return( i );
    }

    int tohex(int inlen, char *instr, unsigned char *outstr)
    {
    char h1,h2;
    unsigned char s1,s2;
    int i, len;

    if(inlen==0)
    inlen = strlen( instr );

    if( inlen%2 )
    len = ( inlen + 1 ) / 2;
    else
    len = inlen / 2;

    for (i=0;i<len;i++){
    h1 = instr[2*i];
    h2 = instr[2*i+1];
    s1 = toupper(h1) - 0x30;
    if (s1 > 9) s1 -= 7;
    s2 = toupper(h2) - 0x30;
    if (s2 > 9) s2 -= 7;
    outstr[i] = s1*16 + s2;
        }
    outstr[len] = 0;

    return( len );
    }

    void lydes(unsigned char *key, unsigned char *instr, unsigned char *outstr, int type)
    {
       /* Set decryption or encryption key parameter for DES calculation */
       /*----------------------------------------------------------------*/
       DES_setkey( type, key );

       /* Decrypt or Encrypt the data and replace */
       /*-----------------------------------------*/
       DES_calcul( instr, outstr );

       return;
    }

    void trilydes(unsigned char *key, unsigned char *instr, unsigned char *outstr, int type)
    {
    unsigned char Tmp1[16], Tmp2[16];

    if( type == ENCRYPT ) {
    lydes( key    , instr, Tmp1, ENCRYPT    );
    lydes( key + 8, Tmp1, Tmp2, DECRYPT    );
    lydes( key    , Tmp2, outstr, ENCRYPT  );
    }
    else {
    lydes( key    , instr, Tmp1, DECRYPT  );
    lydes( key + 8, Tmp1, Tmp2, ENCRYPT  );
    lydes( key    , Tmp2, outstr, DECRYPT);
    }
    return;
    }

    int ri_DESenc(int keylen,unsigned char *key,int inbuflen,unsigned char *inbuf,int *outbuflen,unsigned char *outbuf)
    {
    int i;
    unsigned char buf[8];
    if((keylen!=8) && (keylen!=16))
    {
    return -1;
    }
    for(i=0;i<(inbuflen/8);i++)
    {
    if(keylen ==
    lydes(key,(inbuf+i*8),(outbuf+i*8),ENCRYPT);
    else
    trilydes(key,(inbuf+i*8),(outbuf+i*8),ENCRYPT);
    }
    if((inbuflen%8) != 0)
    {
    memset( buf, 0, 8 );
    memcpy(buf,inbuf+i*8,inbuflen%8);
    buf[inbuflen%8] = '\x80';
    if(keylen ==8)
    lydes(key,buf,(outbuf+i*8),ENCRYPT);
    else
    trilydes(key,buf,(outbuf+i*8),ENCRYPT);
    i++;
    }
    *outbuflen = i*8;
    return 0;
    }

    int ri_DESdec(int keylen,unsigned char *key,int inbuflen,unsigned char *inbuf,int *outbuflen,unsigned char *outbuf)
    {
    int i;
    if((keylen!=8) && (keylen!=16))
    {
    return -1;
    }
    if(inbuflen%8 != 0)
    {
    return -1;
    }
    for(i=0;i<(inbuflen/8);i++)
    {
    if(keylen ==8)
    lydes(key,(inbuf+i*8),(outbuf+i*8),DECRYPT);
    else
    trilydes(key,(inbuf+i*8),(outbuf+i*8),DECRYPT);
    }
    *outbuflen = inbuflen;
    return 0;
    }

    /*加密/解密处理*/
    int ri_crypt(char *key, int inlen, char *data, int outlen, char *result, int type)
    {
    int i,k,keylen;
    unsigned char *pmembuf1,*pmembuf2;
    unsigned char keybuf[16];
    if((strlen(key)!=8*2) && (strlen(key)!=16*2))
    {
    return -1;
    }
    keylen = tohex(0, key, keybuf);
    pmembuf1 = (unsigned char *)malloc(inlen/2+10);
    pmembuf2 = (unsigned char *)malloc(inlen/2+10);
    if((pmembuf1==NULL) || (pmembuf2==NULL))
    {
    free(pmembuf1);
    free(pmembuf2);
    return -1;
    }
    i = tohex(inlen, data, pmembuf1);
    if( type == DECRYPT )
    {
    ri_DESdec(keylen,keybuf,i,pmembuf1,&k,pmembuf2);
    k = outlen;
    }
    else
    ri_DESenc(keylen,keybuf,i,pmembuf1,&k,pmembuf2);

    tostring(k,pmembuf2,result);

    free(pmembuf1);
    free(pmembuf2);

    return 0;
    }

    /*删除字符串尾部的空格*/
    void delspace(char flag, char *str)
    {
    int len, i;

    len = strlen( str );
    for( i = len-1; i >= 0; i-- )
    {
    if( str[i] == flag || str[i] == '\0' || str[i] == '\n' )
    str[i] = '\0';
    else
    break;
    }
    }

    /*BCD码转换为浮点数*/
    void hextofloat(unsigned char *value, int inlen, double *out)
    {
    int tmp[5], i;

    for( i=0; i<inlen; i++ )
    {
    tmp[i] = (int)value[i];
    if( tmp[i] < 0 )
    tmp[i] += 256;
    }

    switch( inlen )
    {
    case 2:
    *out = tmp[0]*2.56 + tmp[1]/100.0;
    break;
    case 3:
    *out = tmp[0]*256*2.56 + tmp[1]*2.56 + tmp[2]/100.0;
    break;
    case 4:
    *out = tmp[0]*256*256*2.56 + tmp[1]*256*2.56 + tmp[2]*2.56 + tmp[3]/100.0;
    break;
    }
    }

    /*BCD码转换为整数*/
    void hex_int(unsigned char *value, int inlen, int *out)
    {
    int tmp[5], i;

    for( i=0; i<inlen; i++ )
    {
    tmp[i] = (int)value[i];
    if( tmp[i] < 0 )
    tmp[i] += 256;
    }

    switch( inlen )
    {
    case 2:
    *out = tmp[0]*256 + tmp[1];
    break;
    case 3:
    *out = tmp[0]*256*256 + tmp[1]*256 + tmp[2];
    break;
    case 4:
    *out = tmp[0]*256*256*256 + tmp[1]*256*256 + tmp[2]*256 + tmp[3];
    break;
    }
    }

    /*整形转换为BCD*/
    void int_hex(int value, int inlen, unsigned char *out)
    {
    switch( inlen )
    {
    case 2:
    out[0] = ( value & 0xff00 ) >> 8;
    out[1] = value & 0x00ff;
    out[2] = 0;
    break;
    case 3:
    out[0] = ( value & 0xff0000 ) >> 16;
    out[1] = ( value & 0x00ff00 ) >> 8;
    out[2] = value & 0x0000ff;
    out[3] = 0;
    break;
    case 4:
    out[0] = ( value & 0xff000000 ) >> 24;
    out[1] = ( value & 0x00ff0000 ) >> 16;
    out[2] = ( value & 0x0000ff00 ) >> 8;
    out[3] = value & 0x000000ff;
    out[4] = 0;
    break;
    }
    }

    /*浮点数转换为BCD码*/
    void floattohex(double value, int inlen, unsigned char *out)
    {
    int tmp;

    tmp = (int)(( value+0.005 )*100);
    int_hex( tmp, inlen, out );
    }


    void gen_htoa(char *instr,char *outstr)
    {
    int i,len;
    char tmp[5],buf[201];

    len=strlen(instr);
    memset(buf,0,sizeof(buf));
    for(i=0;i<len;i++)
    {
    memset(tmp,0,sizeof(tmp));
    switch(instr[i])
    {
    case '0':
    strcpy(tmp,"0000");
    break;
    case '1':
    strcpy(tmp,"0001");
    break;
    case '2':
    strcpy(tmp,"0010");
    break;
    case '3':
    strcpy(tmp,"0011");
    break;
    case '4':
    strcpy(tmp,"0100");
    break;
    case '5':
    strcpy(tmp,"0101");
    break;
    case '6':
    strcpy(tmp,"0110");
    break;
    case '7':
    strcpy(tmp,"0111");
    break;
    case '8':
    strcpy(tmp,"1000");
    break;
    case '9':
    strcpy(tmp,"1001");
    break;
    case 'A':
    case 'a':
    strcpy(tmp,"1010");
    break;
    case 'B':
    case 'b':
    strcpy(tmp,"1011");
    break;
    case 'C':
    case 'c':
    strcpy(tmp,"1100");
    break;
    case 'D':
    case 'd':
    strcpy(tmp,"1101");
    break;
    case 'E':
    case 'e':
    strcpy(tmp,"1110");
    break;
    case 'F':
    case 'f':
    strcpy(tmp,"1111");
    break;
    }
    strcat(buf,tmp);
    }

    sprintf(outstr,"%s",buf);
    }

    void gen_atoh(char *instr,char *outstr)
    {
    int i,j,len;
    char tmp[5],buf[101];

    len=strlen(instr)/4;
    memset(buf,0,sizeof(buf));
    for(i=0,j=0;i<len;i++)
    {
    memset(tmp,0,sizeof(tmp));
    memcpy(tmp,instr+j,4);

    switch(atoi(tmp))
    {
    case 0:
    buf[i]='0';
    break;
    case 1:
    buf[i]='1';
    break;
    case 10:
    buf[i]='2';
    break;
    case 11:
    buf[i]='3';
    break;
    case 100:
    buf[i]='4';
    break;
    case 101:
    buf[i]='5';
    break;
    case 110:
    buf[i]='6';
    break;
    case 111:
    buf[i]='7';
    break;
    case 1000:
    buf[i]='8';
    break;
    case 1001:
    buf[i]='9';
    break;
    case 1010:
    buf[i]='A';
    break;
    case 1011:
    buf[i]='B';
    break;
    case 1100:
    buf[i]='C';
    break;
    case 1101:
    buf[i]='D';
    break;
    case 1110:
    buf[i]='E';
    break;
    case 1111:
    buf[i]='F';
    break;
    }
    j += 4;
    }
    buf[j]=0;

    sprintf(outstr,"%s",buf);
    }

    void gen_xor(char *instr1,char *instr2,int len)
    {
    int i,len1;
    char buf1[501],buf2[501],tmp[201];

    gen_htoa(instr1,buf1);
    gen_htoa(instr2,buf2);

    len1=len*4;
    for(i=0;i<len1;i++)
    {
    buf1[i] ^= buf2[i];
    buf1[i] += '0';
    }

    gen_atoh(buf1,tmp);
    sprintf(instr1,"%s",tmp);
    }




    SVC_HEX_2_DSP(hex, dsp, count)
    char *dsp, *hex;
    int count;
    {
        int i;
        char ch;
        for(i = 0; i < count; i++)
        {
        ch = (hex[i] & 0xf0) >> 4;
        dsp[i * 2] = (ch > 9) ? ch + 0x41 - 10 : ch + 0x30;
        ch = hex[i] & 0xf;
        dsp[i * 2 + 1] = (ch > 9) ? ch + 0x41 - 10 : ch + 0x30;
        }
    }


    SVC_DSP_2_HEX(dsp, hex, count)
    char *dsp, *hex;
    int count;
    {
        int i;
        for(i=0;i<count;i++)
        {
        hex[i] = ((dsp[i * 2] <= 0x39) ? dsp[i * 2] - 0x30
                                       : dsp[i * 2] - 0x41 + 10);
        hex[i] = hex[i] << 4;
        hex[i] += ((dsp[i * 2 + 1] <= 0x39) ? dsp[i * 2 + 1] - 0x30
                                        : dsp[i * 2 + 1] - 0x41 + 10);
        }
    }

    int get_pin_key(char *pinkey)
    {
        char t_fl1[33];
        char t_fl2[33];
        char t_my1[16];
        char t_my2[16];
        char t_pinkey[16];
        int  i;
    /*
        EXEC SQL select * into :wd_tdmy
            from tdmy;
        if(sqlca.sqlcode) SQLERR
        strcpy(t_fl1,wd_tdmy.fl1);
        strcpy(t_fl2,wd_tdmy.fl2);
    */

        strcpy(t_fl1,"11111111111111111111111111111111");
        strcpy(t_fl2,"22222222222222222222222222222222");

        SVC_DSP_2_HEX(t_fl1,t_my1,16);
        SVC_DSP_2_HEX(t_fl2,t_my2,16);
        for(i=0;i<16;i++)
        {
            t_pinkey[i]=t_my1[i]^t_my2[i];
        }
        memcpy(pinkey,t_pinkey,16);
        return 0;
    }

    int enc_pin(char *yzm,char *nyzm)
    {
         char dsp[17];
         char tmp[20];
         unsigned char hex[9];
         unsigned char key[16];

         memset(key,0x00,sizeof(key));
         if(get_pin_key(key)<0) return -1;

         memset(dsp,'F',sizeof(dsp));
         if(strlen(yzm)!=6)
         {
             return -1;
         }
         sprintf(tmp,"06%s",yzm);
         memcpy(dsp,tmp,strlen(tmp));
         memset(hex,0x00,sizeof(hex));
         SVC_DSP_2_HEX(dsp,hex,8);
         memset(nyzm,0x00,9);
         hex[8]=0;
         trilydes(key,hex,tmp,0);
         SVC_HEX_2_DSP(tmp,nyzm,8);
         return 0;
    }


    int dec_pin(char *yzm,char *nyzm)
    {
       char hex[21];
       char tmp[21],tmp1[21];
       unsigned char key[16];
       long yzmcd;

       memset(key,0x00,sizeof(key));
       if(get_pin_key(key)<0) return -1;
       memset(tmp,0,sizeof(tmp));
       memset(tmp1,0,sizeof(tmp1));
       memset(hex,0,sizeof(hex));
       SVC_DSP_2_HEX(yzm,hex,8);
       trilydes(key,hex,tmp,1);
       memset(nyzm,0x00,8);
       SVC_HEX_2_DSP(tmp,tmp1,8);
       memcpy(tmp,tmp1,2);
       tmp[2]=0;
       yzmcd=atoi(tmp);
       strncpy(nyzm,tmp1+2,yzmcd);
       nyzm[yzmcd]='\0';
       return 0;
    }
    帮忙转为java呢

    源:111111
    加密后:66322DAA27A95807
2012年9月14日 23:48

1个答案 按时间排序 按投票排序

0 0

找个工具转吧,贴这么长代码,鬼才给你手动转。

2012年9月19日 12:10

相关推荐

    C代码,跪求C语言转JAVA

    跪求C语言转JAVA

    C转java工具

    "C转Java工具"就是这样一个工具,它能够将大部分C语言的语法转化为等效的Java语法,使得C语言编写的程序能够在Java平台上运行或者进行进一步的Java优化。这个工具的出现,对于那些已经拥有大量C语言代码库但又希望...

    c转java工具合集

    这段时间本人能找的c或c#转java的工具都在这里。自己留个备份。下面是文件名:C++ to Java Converter、C2J、cnet2_C2J_exe、CPP-to-Java-Converter_Source、CSharp+to+Java+Converter、java转c工具Java2Cpp。没有去...

    c to java 转换工具

    该软件可以把c语言文件转换为java语言文件

    jni C结构体转JAVA实体类

    可实现将C语言中的结构体转换为JAVA类型的实体类。 目前支持基础数据类型int、long、foloat、double、const char *、bool的转换,也支持将数组装换为JAVA中的ArrayList。目前有个难点是将枚举类型直接转换为JAVA中的...

    CPlus_to_Java_Converter;C++转java工具

    本文将围绕“CPlus_to_Java_Converter”这一工具,探讨如何将C++代码转换为Java代码,并分析这一过程中涉及的关键技术和挑战。 首先,我们要明确C++到Java的转换并非简单的语法替换,因为两者的语言特性差异显著。...

    RSA加密JAVA转C# JAVA转PHP,C#转JAVA

    本工具提供了在不同编程语言间进行RSA密钥的互换,包括JAVA转C#、JAVA转PHP以及C#转JAVA的转换功能。 在JAVA中,RSA的实现主要依赖于`java.security`包,其中`KeyPairGenerator`用于生成公钥和私钥,`Cipher`用于...

    C++转Java工具

    标题中的"C++转Java工具"指的是一个程序,它能够帮助开发者将C++编写的代码转换为Java语言。这种工具在跨平台开发或者需要利用Java特性,但已有大量C++代码库的情况下尤其有用。JNI(Java Native Interface)是Java...

    一款java2c加固混淆工具 java转c 交叉编译.dll.so

    MYJ2C将编译的Java方法转换为C语言。编译生成的文件后,生成的二进制文件通过Java Native Interface 重新链接到原始程序。在此过程结束时,包含原始方法的.class文件中不会保留原始方法的信息。 Before public ...

    Java转C++代码工具 J2C

    Java转C++代码工具J2C是一个专门用于将Java源代码转换为等效C++代码的工具。这个工具对于那些需要在不支持Java或者需要利用C++特定性能特性的环境中迁移Java项目的人来说非常有用。在深入探讨J2C之前,我们先理解...

    c++ 转换 java c# 转换 java c++ 转换 c#

    `CPlus_To_CShap_Converter.zip`可能是一个专门处理这种转换的工具,它能帮助开发者把C++代码集成到.NET环境中。 在进行这些转换时,需要考虑的因素包括代码的可读性、性能、兼容性以及可能的API调整。转换器可能会...

    C++头文件转JAVA JNA接口类

    这些函数应该遵循C语言的调用约定,因为JNA主要支持C风格的接口。 2. **创建SWIG接口文件**:创建一个SWIG接口文件(.i文件),在这个文件中,你需要引用C++的头文件,并且声明哪些函数和类型需要被暴露给Java。 3...

    C#代码转java代码工具

    一个很强大的工具, 能将c#代码片段、文件甚至工程直接转换成java代码,并能彻底解决外部引用的DLL问题,最强的是支持c#工程的直接转换,生成的Java代码质量也很不错。软件已破解,去除了未注册版最多只能转换1000行的...

    C_Java_Transfer.zip

    在IT行业中,跨语言通信是常见且至关重要的任务,特别是在Android开发中,Java与C/C++的交互尤为重要。本篇文章将深入探讨如何使用JNI(Java Native Interface)来实现在C/C++结构体与Java类之间进行数据转换。通过...

    C语言实现的Java编译器

    在本项目中,"C语言实现的Java编译器"是一个独特的尝试,它将传统的编译原理理论应用于实际编程中,以C语言作为基础来构建一个能够解析和处理Java源代码的工具。这个项目主要涉及两个核心部分:词法分析器(Scanner...

    java 与C语言传递结构体数据

    描述:为了解决java与C结构通信过程中结构体解析问题。 主要功能:能友好的用java处理任何发送的C结构体对象,并且能发送java对象转换成C结构体接收的二进制。 功能说明 1、基于spring框架开发 2、对于结构体定义...

    JNA 转java接口以及指针结构体解析

    在"JNA 转java接口以及指针结构体解析"这个主题中,我们将深入探讨如何使用JNA来处理C语言中的结构体和指针。 首先,理解JNA的基本工作原理至关重要。JNA通过定义一个`Interface`,该接口中的方法对应于要调用的...

    Java转C工具

    Java转C工具是一种编程语言转换器,主要用于将Java源代码转换为C或C++源代码,以便在不支持Java虚拟机(JVM)的平台上运行。这种工具的主要目的是跨平台移植,尤其是在嵌入式系统或者对性能有严格要求的环境中,Java...

    将C头文件转为Java工具

    Java作为一种高级编程语言,虽然强大且跨平台,但有时仍需与C/C++等原生代码进行交互,这时JNA(Java Native Access)就显得尤为重要。JNA提供了一种无需编写JNI(Java Native Interface)代码就能调用原生库的方法...

    java转c++软件(代码级别)

    J2C 将 Java 代码转成 C++ 代码,这是源码级别的转换,输出的 C++ 代码是有效的代码。

Global site tag (gtag.js) - Google Analytics