You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
the_difference_analysis_of_des/key table.h

180 lines
5.5 KiB

#ifndef TASK4_H_INCLUDED
#define TASK4_H_INCLUDED
#include<stdio.h>
#include<stdlib.h>
void CharToInt6(char a[6], int b[6]); //6λ<36>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
void CharToInt4(char a[4], int b[4]); //4λ<34>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
int mainFuntion4(char E[6], char ee[6], char hello[4]) {
int EInt[6];
int eeInt[6];
int helloInt[4];
CharToInt6(E, EInt);
CharToInt6(ee, eeInt);
CharToInt4(hello, helloInt);
void happy(int EInt[6], int eeInt[6], int helloInt[4]); //ʵ<><CAB5>P138<33><38>4-2<>ĺ<EFBFBD><C4BA><EFBFBD>
// void s_box(int array[6],int brray[4],int crray[4][16]); //<2F><><EFBFBD><EFBFBD>des<65>ѽ<EFBFBD><D1BD><EFBFBD>д<EFBFBD><D0B4>8<EFBFBD><38>6<EFBFBD><36><EFBFBD>ش<EFBFBD><D8B4>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF><D2BB>s<EFBFBD>а<EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD>ӳ<EFBFBD>䵽4<E4B5BD><34><EFBFBD><EFBFBD>
//<2F><>array<61><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>6λ brray<61><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><34><CEBB>crray<61><79>s<EFBFBD><73>4X16
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
happy(EInt, eeInt, helloInt);
return 0;
}
void happy(int EInt[6], int eeInt[6], int helloInt[4])
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD><73>
int s[4][16] = { {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 b[6]; //<2F><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD>
int d[6];
int e[4], f[4], Out[4];
int flag;
int l, k;
int i, j;
int g, h;
int p, q;
int u, v; //l,k,i,j,g,h,p,q<><71>Ϊѭ<CEAA><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
int count; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int in[13][6];
int test[13][6];
// void s_box(int array[6],int brray[4],int crray[4][16]);
// void CharToInt6(char a[6],int b[6]);//6λ<36>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
// void CharToInt4(char a[4],int b[4]);//4λ<34>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
int a[6];
for (i = 0; i < 6; i++) {
a[i] = EInt[i] ^ eeInt[i]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
count = 0; //<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>ʼ<EFBFBD><CABC>Ϊ0<CEAA><30>
for (j = 0; j <= 63; j++) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
{
{ int t; //b[]Ϊ<><CEAA><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD>
t = j;
b[5] = t % 2; t = t / 2;
b[4] = t % 2; t = t / 2;
b[3] = t % 2; t = t / 2;
b[2] = t % 2; t = t / 2;
b[1] = t % 2; t = t / 2;
b[0] = t % 2;
}
for (l = 0; l < 6; l++)
d[l] = b[l] ^ a[l]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>x<EFBFBD><78>Ӧ<EFBFBD><D3A6>x*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>d[]<5D><> InΪ<6E><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
s_box(b, e, s); //b<><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD>x <20><>e<EFBFBD><65>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊbʱ<62><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
s_box(d, f, s); //d<><64>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊin[l]<5D><>Ӧ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>x*<2A><>f<EFBFBD><66>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊbʱ<62><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (k = 0; k < 4; k++)
Out[k] = e[k] ^ f[k]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD>Out<75><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
flag = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ<D6BE><CEBB>1<EFBFBD><31>
for (k = 0; k < 4; k++)
{
if (Out[k] != helloInt[k]) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD>ƥ<EFBFBD><C6A5>
{
flag = 0;
break;
}
}
if (flag == 1) {//<2F><><EFBFBD>ϵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ʱ<EFBFBD>򣬵<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵļ<D6B5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ
count = count + 1;
if (count > 0) {
for (int z = 0; z < 6; z++) {
//int r=count-1;
in[count - 1][z] = b[z];
}
}
}
}
in[count][0] = 2; //<2F><><EFBFBD><EFBFBD>count<6E>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>п<EFBFBD>ͷ<EFBFBD><CDB7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD>ɸѡ
printf("<EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>\n");
if (count == 0)printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD>ϡ<EFBFBD>");
else {
for (g = 0; g < 13; g++) {
if (in[g][0] > 1)
break;
else {
for (h = 0; h < 6; h++)
{
printf(" %d ", in[g][h]);
if ((h + 1) % 6 == 0)
printf("\n");
}
}
}
}
for (p = 0; p < 13; p++) {
for (q = 0; q < 6; q++)
{
test[p][q] = in[p][q] ^ EInt[q];
}
}
printf("<EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>\n");
if (count == 0)printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD>ϡ<EFBFBD>");
else {
for (u = 0; u < 13; u++) {
if (in[u][0] > 1)
break;
else {
for (v = 0; v < 6; v++)
{
printf(" %d ", test[u][v]);
if ((v + 1) % 6 == 0)
printf("\n");
}
}
}
}
}
// void s_box(int array[6],int brray[4],int crray[4][16])
// {
// int p,q,t;
// p=2*array[0]+array[5]; //<2F><>b1b6<62><36><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>s<EFBFBD>е<EFBFBD><D0B5><EFBFBD>ȡֵΪp
// q=2*2*2*array[1]+2*2*array[2]+2*array[3]+array[4]; //<2F><>b2b3b4b5<62><35><EFBFBD><EFBFBD>s<EFBFBD>е<EFBFBD><D0B5><EFBFBD>ȡֵΪq
// t=crray[p][q]; //t<><74><EFBFBD><EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊarray[6]ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// brray[3]=t%2;
// t=t/2;
// brray[2]=t%2;
// t=t/2;
// brray[1]=t%2;
// t=t/2;
// brray[0]=t%2; //<2F><><74><D7AA><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2>brray<61><79>
// }
void CharToInt6(char a[6], int b[6]) {
for (int q = 0; q < 6; q++) {
if (a[q] == '0')
b[q] = 0;
else b[q] = 1; //<2F><>ֹ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD>ֵֹ<D6B9><D6B5><EFBFBD><EFBFBD><EFBFBD>
}
}
void CharToInt4(char a[4], int b[4]) {
for (int q = 0; q < 4; q++) {
if (a[q] == '0')
b[q] = 0;
else b[q] = 1; //<2F><>ֹ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD>ֵֹ<D6B9><D6B5><EFBFBD><EFBFBD><EFBFBD>
}
}
#endif // TASK4_H_INCLUDED
#pragma once