gpt4 book ai didi

c++ - SBox 的线性近似表计算

转载 作者:太空狗 更新时间:2023-10-29 23:49:47 25 4
gpt4 key购买 nike

我有一个密码学作业,要求计算大量 4*4 s-box 的 LAT 表。为此,我编写了一个简单的 C++ 程序。我将问题文本作为图像附加。不知道老师给的公式是LAT表计算的通用公式还是他自己做的。我的问题是我准备的软件给出了一个全为零的 LAT 表。我没有这个公式的测试 vector 。我将在下面附上代码。如果知道线性近似表的人可以检查程序并告诉我问题出在哪里,我将非常高兴。 (我检查了位转换部分它工作正常!)提前致谢..

费尔达

enter image description here

最佳答案

这是计算 DES s-box 的线性近似表的伪代码。

int x_i =0, y_i = 0, y_j=0,x_j =0, parity_11=0;
int temp=0;
for(x_i=0;x_i<64;x_i++){
for(y_i=0;y_i<16;y_i++){
for(x_j=0;x_j<64;x_j++){
y_j=sbox_1[x_j];
y_j=y_j&y_i;
temp=x_j&x_i;
parity_11=(parity(temp)+parity(y_j))%2;
parity_x_y[x_i][y_i]+=parity_11;
}
}
}

完整代码如下:

static const char   sbox_1[] = {
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
};
int parity(unsigned int x){
unsigned int count = 0, i, b = 1;

for(i = 0; i < 8; i++){
if( x & (b << i) ){count++;}
}

if( (count % 2) ){return 1;}

return 0;
}
int parity_x_y[64][16] ={};
void print_xor(){
int i=0,j=0;
for(i=0;i<64;i++){
j=0;
for(j=0;j<16;j++){
printf("%d ",parity_x_y[i][j]);
}
printf("\n");
}

}

void print_LAT(){
int x_i =0, y_i = 0, y_j=0,x_j =0, parity_11=0;

int temp=0;
print_xor();
for(x_i=0;x_i<64;x_i++){
for(y_i=0;y_i<16;y_i++){
for(x_j=0;x_j<64;x_j++){
y_j=sbox_1[x_j];
y_j=y_j&y_i;
temp=x_j&x_i;
parity_11=(parity(temp)+parity(y_j))%2;
parity_x_y[x_i][y_i]+=parity_11;
}
}
}
int j=0;
print_xor();
}

int main(){
print_LAT();
return 0;
}

希望对你有帮助

关于c++ - SBox 的线性近似表计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36952769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com