Convert hex array into the dec array
907439Jan 16 2012 — edited Jan 18 2012There is a method that tries to convert an hex-array into dec-array (for example AA BB CCh - 11 18 91 96d). I know that exists the class BCDUtil (since jc2.2.2), but it is absent on the card, so I had to convert manually.
my Code (i know that it is bad)
private void calc(byte [] src, byte [] out){
byte b1=(byte) 0xAA;
byte b2=(byte) 0xbb;
byte b3=(byte) 0xcc;
byte pbR1=0;
byte pbL1=0;
byte pbR2=0;
byte pbL2=0;
byte pbR3=0;
byte pbL3=0;
b1=src[ISO7816.OFFSET_CDATA];
pbR1 =(byte) (b1&0x0F);;
pbL1 =(byte) (b1>>4&0x0F);
//b2=src[ISO7816.OFFSET_CDATA+1];
pbR2 =(byte) (b2&0x0F);
pbL2 =(byte) (b2>>4&0x0F);
//b3=src[ISO7816.OFFSET_CDATA+2];
pbR3 =(byte) (b3&0x0F);
pbL3 =(byte) (b3>>4&0x0F);
//out[0] = (byte) ((b1<<16 + b2 * 256 +b3 )% 10);
//out[1] = (byte) ((b1<<16 + b2 * 256 +b3 )/10 % 10);
out[0]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1)) % 10);
out[1]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1)) /10 % 10);
out[2]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1)) /100 % 10);
out[3]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1))/1000%10);
out[4]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1))/10000%10);
out[5]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1))/10000/10%10);
out[6]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1))/10000/100%10);
out[7]=(byte)(((pbL1*16<<16)+(pbR1*16<<12)+(pbL2*16<<8)+(pbR2*16<<4)+(pbL3*16<<0)+(pbR3*1))/10000/1000%10);
}
after this card answers - <= 00 FA FC F9 FF 00 00 00 90 00
BUT if a write:
0xA(nibble) instead pbL1 and pbR1
0x0B instead pbL2 and pbR2
and 0x0C instead pbL3 and pbR3
then card answers correctly - <= 06 09 01 09 08 01 01 01 90 00
i.e. operations are correct when operands are constant. It is possible to solve this problem?