Arrays 在“字节数组”位置访问字节数组

Arrays 在“字节数组”位置访问字节数组,arrays,javacard,bitwise-and,Arrays,Javacard,Bitwise And,我想这个问题听起来令人困惑,只是想把它弄清楚 我想用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

我想这个问题听起来令人困惑,只是想把它弄清楚

我想用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;
final byte[] f1 = new byte[] {(byte) 0x35, (byte) 0xB0,(byte) 0x88,(byte) 0xCC,(byte) 0xE1,(byte) 0x73}; 
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;
}
基本上,JCArrayInt充当二维数组,由大小为6 48位无符号整数的两个字节数组组成

我只想对按位and和字节数组r执行常量0x00…1,如果结果为1,则继续执行f[1]处的bytearray,否则继续执行f[0]处的bytearray


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

我想您可以这样指定f1:

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;
final byte[] f1 = new byte[] {(byte) 0x35, (byte) 0xB0,(byte) 0x88,(byte) 0xCC,(byte) 0xE1,(byte) 0x73}; 
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;
}
您可以这样指定6字节常量:

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;
final byte[] f1 = new byte[] {(byte) 0x35, (byte) 0xB0,(byte) 0x88,(byte) 0xCC,(byte) 0xE1,(byte) 0x73}; 
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;
}
你可以像这样向左旋转:

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;
final byte[] f1 = new byte[] {(byte) 0x35, (byte) 0xB0,(byte) 0x88,(byte) 0xCC,(byte) 0xE1,(byte) 0x73}; 
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;
}

不知道这是否适用于您,但这一个适用于我

您的阵列f的类型是什么。是uint8吗?它的大小总是两个元素吗?你在乎持久性吗?r是位数组,还是始终是数字1?我对你的问题有点困惑,你可以告诉我…你可以把所有的零放在面具上。如果你真的喜欢基数16,那么比特1或0x1。f只是一个字节[],不必在意尾数!r是一个与0x0大小相同的随机位数组…1在执行位和r 0x000000000001时,您需要注意尾数,因为我不清楚要比较r中的哪个字节。。。您使用的常量必须是8字节的常量,它大于4,但r只有6字节长。您可能正在查看r[0],或者您可能正在查看不存在的r[7]?我是否遗漏了bit_的实现方式?我可能会建议你决定你真正关心的是r的哪个元素,然后测试它的LSB:f[r[0]&1==0?0:1]或者类似的东西。我的按位_和是以一种方式实现的,我总是处理48位无符号整数,所以6字节的大小,我循环通过它们r和常量,以及它的每个元素