08 September 2010

Java Card bits, ePassporte

Java Cards the wheel turns:
each generation of devices looks like an ancient form. ie restricted memory etc
On our Java Card, we are packing data into bit arrays, NOT on byte boundaries
ie Bits into Byte Arrays


     static long extractbits (int a, int b, byte[] bin) {      // a = start bit, b = last bit(zero based)
      // extract bits from a byte array
      int byta = a >> 3; // 1st byte
      int bytb = b >> 3; // last byte
           int bytz = bytb -byta + 1; // number of bytes
        byte[] block = new byte[bytz];
        System.arraycopy(bin, byta, block,0, bytz);
        int p = 8 - (a & 7); // # of bits in mask
        block[0] = (byte) (block[0] & ((1<<p) - 1));


        return ((by2long (block)) >> (7 - (b & 7)));
    }//_________________________________________________________________________

...........................

     static byte[] insertbits (int a, int b, long g, byte[] bin) {
        //inset bits from a long into a byte array a=startbit b=lastbit zero based
        byte[] bout = new byte[bin.length];
        // how many bytes does the long require // care we assume 1..4 not 0..8
        int byta = a >> 3; // 1st byte we are altering
        int bytb = b >> 3; // last byte we are altering
        int bytz = bytb -byta + 1; // number of bytes we are working on
        System.arraycopy(bin,0,bout,0,bin.length); // make a copy
        g = g << (7 - (b&7)); // shift g left acording to b      
        byte[] b4 = longtohex(g); // 4 bytes max.. maximum is FF FF FF FF FF ???         // OR b4 onto bout... this assumes bout target area is zeros , else we need a prior NAND     
        int k = 3; // OR bytes 3..2..1..0 ..actually only 2???0     
        byte bc;
        for (int j=bytb ; j>= byta ; j--) {
            bc = b4[k--]; //why is bc needed???
            bout[j] = (byte)(bout[j] | bc);
            // ie bout[j] = (byte)(bout[j] | b4[k--]); does NOT work
        }
        return bout;
     }//_________________________


     public static long by2long (byte[] b) {
        //java.lang.Byte wrapper provides longValue(),
        long value = 0;
        for (byte byt:b)
             value = (value << 8) + (byt & 0xff);     
        return value;      }
//_________________________________________   
    public static byte[] longtohex( long g) { // long to byte array nb only 4 bytes         
// java long is 8 bytes, but our maths is 4 bytes only...       
        byte[] bout = new byte[4];    
        for (int j = 3 ; j >= 0; j--){
            bout[j] = (byte)( g & 0x00000000000000FF);
            g = g >> 8;
        }
        return bout;
     }//___________________________________________

News:
ePassporte
From the department of un-reassuring reassurances:

"The ePassporte e-Wallet program continues to be up and running, except funds cannot be transferred between your Visa account and your e-Wallet," Mallick said.
ecommerce

Customers cannot shop online and pay with their virtual debit card. Nor they can transfer their funds on the card back to their wallets. The issue is not just US-wide, it is everywhere in the world. Any user in any country who has a Visa debit card from ePassporte cannot use it and at the moment it is just a piece of plastic.

No comments:

Post a Comment