写基础Applet,试图测试加解密正确性

This commit is contained in:
zcy
2025-09-05 22:47:16 +08:00
parent a74ab6f212
commit ed52d849a4
9 changed files with 177 additions and 96 deletions

View File

@@ -49,13 +49,50 @@ public final class Zuc256Tables {
0x64,0xbe,0x85,0x9b,0x2f,0x59,0x8a,0xd7,0xb0,0x25,0xac,0xaf,0x12,0x03,0xe2,0xf2
};
/**
* 常量数组 D16bit short二维数组适配
*/
public static final short[][] ZUC256_D = {
{0x22,0x2F,0x24,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30},
{0x22,0x2F,0x25,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30},
{0x23,0x2F,0x24,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30},
{0x23,0x2F,0x25,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30}
};
// /**
// * 常量数组 D16bit short二维数组适配
// */
// public static final short[][] ZUC256_D = {
// {0x22,0x2F,0x24,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30},
// {0x22,0x2F,0x25,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30},
// {0x23,0x2F,0x24,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30},
// {0x23,0x2F,0x25,0x2A,0x6D,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30}
// };
public static final short D_COLS = 16;
/**
* 常量数组 D16bit short二维数组适配
*/
public static final short[] ZUC256_D_FLAT = new short[] {
// row 0
0x22,0x2F,0x24,0x2A,0x6D,0x40,0x40,0x40,
0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30,
// row 1
0x22,0x2F,0x25,0x2A,0x6D,0x40,0x40,0x40,
0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30,
// row 2
0x23,0x2F,0x24,0x2A,0x6D,0x40,0x40,0x40,
0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30,
// row 3
0x23,0x2F,0x25,0x2A,0x6D,0x40,0x40,0x40,
0x40,0x40,0x40,0x40,0x40,0x52,0x10,0x30
};
/** 读取 D[row][col],返回无符号值 0..255 */
public static short getD(short row, short col) {
// idx = row * 16 + col
short idx = (short)(row * D_COLS + col);
return (short)(ZUC256_D_FLAT[idx] & 0xFF);
}
/** 取一行 (返回一段16个short) */
public static void getDRow(short row, short[] out, short outOff) {
short base = (short)(row * D_COLS);
for (short i = 0; i < D_COLS; i++) {
out[(short)(outOff + i)] = ZUC256_D_FLAT[(short)(base + i)];
}
}
}