在"byte array"位置访问字节数组


我想

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

我想用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 位无符号整数)组成。

我想为位位做的只是用常量0x00...1"和"字节数组 r,如果结果是 1,我继续在 f[1] 处使用字节数组,否则在 f[0] 处使用byte[]

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

我认为您可以像这样指定 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;
}

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

最新更新