0

我想这个问题听起来很混乱,试图让它更清楚。

我想用java卡实现一个指定的不泄漏地图,根据我拥有的伪代码,我应该实现这样的东西:

JCArrayInt[] f = new JCArrayInt[2];
f[0] = new JCArrayInt(size);
f[1] = new JCArrayInt(size);
byte[] r = new byte[6];
byte[] help = new byte[6];

help = bit_and(r, 0x000000000001);
return f[help[5]].jcint;

基本上 JCArrayInt 充当二维数组,由两个大小为 6 的字节数组(48 位无符号整数)组成。

我想要按位做的就是将字节数组 r 与常量“和” 0x00...1,如果结果为 1,我将继续使用字节数组 at f[1],否则使用byte[]at f[0]

我目前所做的是,对于返回值,我只需执行上面显示的步骤。但由于这是“硬编码”,我有一种不好的感觉,f[help[5]].jcint想知道一种更顺畅的方式。

4

1 回答 1

0

我认为您可以像这样指定 f1:

final byte[] f1 = new byte[] {(byte) 0x35, (byte) 0xB0,(byte) 0x88,(byte) 0xCC,(byte) 0xE1,(byte) 0x73}; 

您可以像这样指定 6 字节常量:

final byte[] constant = new byte[] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01};

你可以像这样向左旋转:

public static byte[] ROTL48 (byte[] data) {
    byte  x = (byte)((data[0] >>> 7) & 0x001);
    short len = (short) (data.length - 1);
    for (short i = 0; i < len; ++i) {
        data[i] = (byte)(((data[i] << 1) & 0x0FE) | ((data[i + 1] >>> 7) & 0x001));
    }
    data[len] = (byte)(((data[len] << 1) & 0x0FE) | x);
    return data;
}

然后你可以按位使用:

for (short i = 1; i < 47; i++) {
    R  = ROTL48(R);
    R1 = Utils.AND(R, constant);
    R  = Utils.XOR(R, Red[R1[5]].jcint);
    Y  = ROTL48(Y);
    Y1 = Utils.AND(Y, constant);
    R  = Utils.XOR(R, Mul[Y1[5]].jcint);}
    return R;
}

不知道这是否适合你,但这个适合我

于 2015-03-02T08:14:08.300 回答