Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Implement div algorithm in javacard

Algorithm School

Moderator: UNKNwYSHSA

User avatar
vermont
Posts: 13
Joined: Tue May 26, 2015 10:18 pm
Points :6
Contact:

Implement div algorithm in javacard

Post by vermont » Mon Aug 24, 2015 8:34 am

I am trying to develop an applet about compute operation (mul,div) with big values. But I only complete the mul operation.
I don't know how to implement div algorithm .
Can anybody help me out ?

Another question: The following codes are my mul algorithm implementation. Is there any other ways to implement mul algorithm ?

Code: Select all

private boolean mulBytes(byte[] A, byte[] B, short len, byte[] C)
   {
       short a;
      short b;
      short sumC;
      short m;
      short n ;
      short t ;
      
      clearArray(bufferCC);
      
      m= (short)(len-1); //7
      for( n=(short)(len-1); n>=0; n--)
      {
         clearArray(bufferCA);
         clearArray(bufferCB);
         
         //sumC = 0;
         t= (short)(m-n);
         for( short i=0; i<=t; i++)
         {
            a = (short)(A[m-i] & 0xFF);
            b = (short)(B[n+i] & 0xFF);
            sumC = (short)( a*b);
            bufferCB[0] = 0;
            bufferCB[1] = (byte)(sumC >> 8);
            bufferCB[2] = (byte)(sumC & 0xFF);
            
            addBytes(bufferCA, bufferCB, (short)3, bufferCA);
         }
         //sumC += (short)(bufferC[0]& 0xFF );
         //bufferC[0] = (byte)(sumC >> 8);
         //bufferC[1] = (byte)(sumC & 0xFF);
         
         addBytes(bufferCA, bufferCC, (short)3, bufferCA);
         
         C[m+n+1] = bufferCA[2];
         bufferCC[0]=0;
         bufferCC[1] =bufferCA[0];
         bufferCC[2] = bufferCA[1];
      }
      n=0;
      for( m=(short)(len-2); m>=0; m--)
      {
         clearArray(bufferCA);
         clearArray(bufferCB);
         //sumC = 0;
         t= (short)(m-n);
         for( short i=0; i<=t; i++)
         {
            a = (short)(A[m-i] & 0xFF);
            b = (short)(B[n+i] & 0xFF);
            //sumC += (short)( a*b);
            sumC = (short)( a*b);
            bufferCB[0] = 0;
            bufferCB[1] = (byte)(sumC >> 8);
            bufferCB[2] = (byte)(sumC & 0xFF);
            
            addBytes(bufferCA, bufferCB, (short)3, bufferCA);
         }
         addBytes(bufferCA, bufferCC, (short)3, bufferCA);
         
         C[m+n+1] = bufferCA[2];
         bufferCC[0]=0;
         bufferCC[1] =bufferCA[0];
         bufferCC[2] = bufferCA[1];
      }
      
      C[0] = bufferCC[2];
 
        return (bufferCC[1] != 0);
   }

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Implement div algorithm in javacard

Post by UNKNwYSHSA » Tue Aug 25, 2015 8:47 am

Why did you write this code? To study? Without the chip-level implementation, the calculation speed will be very slow.
sense and simplicity

ftsafe
Posts: 52
Joined: Fri Aug 14, 2015 4:05 am
Points :126
Contact:

Re: Implement div algorithm in javacard

Post by ftsafe » Fri Aug 28, 2015 5:30 am

Our IFD A40CR card can provide Big Number API for you according to your needs.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 18 guests

JavaCard OS : Disclaimer