void enc_0(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
)
{
a1[i]
+
=
16
;
a2[i] ^
=
a1[i];
}
}
void enc_0_dec(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
)
{
a2[i] ^
=
a1[i];
}
}
void enc_1(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
) {
a1[i]
=
a1[i]
-
80
;
a2[i] ^
=
(a1[i] <<
4
);
}
}
void enc_1_dec(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
) {
u_char k
=
(a1[i] <<
4
) | (a1[i] >>
4
);
a2[i] ^
=
k;
}
}
void enc_2(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
) {
a2[i] ^
=
a1[i];
}
}
void enc_2_dec(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
) {
a2[i] ^
=
a1[i];
}
}
void enc_3(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
32
; i
+
+
) {
a1[i]
-
=
80
;
}
for
(
int
i
=
0
; i <
16
;
+
+
i) {
a2[i
*
2
+
0
] ^
=
a1[i
*
2
] <<
4
;
a2[i
*
2
+
1
] ^
=
a1[i
*
2
] >>
4
;
}
}
void enc_3_dec(unsigned char
*
a1, unsigned char
*
a2) {
for
(
int
i
=
0
; i <
16
;
+
+
i) {
a2[i
*
2
+
0
] ^
=
a1[i
*
2
] <<
4
;
a2[i
*
2
+
1
] ^
=
a1[i
*
2
] >>
4
;
}
}
void enc_4(unsigned char
*
data1, unsigned char
*
data2) {
for
(
int
i
=
0
; i <
16
;
+
+
i) {
u_char v11
=
data1[i];
/
/
v11
=
*
v9;
data1[i]
=
data1[
31
-
i];
/
/
*
v9
+
+
=
*
v10;
data1[
31
-
i]
=
v11;
}
for
(
int
i
=
0
; i <
16
; i
+
+
) {
u_char v15
=
data1[i];
data1[i]
=
data1[
15
-
i];
data1[
15
-
i]
=
v15;
}
for
(
int
i
=
0
; i <
16
; i
+
+
) {
/
/
三个
for
循环交换之后相当于没变
u_char v19
=
data1[
16
+
i];
data1[
16
+
i]
=
data1[
15
-
i];
data1[
15
-
i]
=
v19;
}
for
(
int
i
=
0
; i <
32
;
+
+
i) {
data2[i] ^
=
data1[i];
}
}
void enc_4_dec(unsigned char
*
data1, unsigned char
*
data2) {
for
(
int
i
=
0
; i <
32
;
+
+
i) {
data2[i] ^
=
data1[i];
}
}
void enc_5(unsigned char
*
data1, unsigned char
*
data2) {
for
(
int
i
=
0
; i <
32
; i
+
+
) {
u_char v5
=
data1[i];
u_char v8;
if
((unsigned char)(v5
-
33
) >
0x2E
) {
if
((unsigned char)(v5
-
81
) >
0x2e
) {
if
(v5 >
128
) {
v8
=
v5
-
48
;
data1[i]
=
v8;
data2[i]
-
=
v8;
}
}
else
{
v8
=
v5
-
48
;
data1[i]
=
v8;
data2[i] ^
=
(v8 >>
4
);
};
}
else
{
v8
=
v5
-
80
;
data1[i]
=
v8;
data2[i]
+
=
v8;
}
}
}
void enc_5_dec(unsigned char
*
data1, unsigned char
*
data2) {
/
/
要上一层的key,以便进行
if
else
判断
for
(
int
i
=
0
; i <
32
; i
+
+
) {
u_char v5
=
data1[i];
u_char v8;
if
((unsigned char)(v5
-
33
) >
0x2E
) {
if
((unsigned char)(v5
-
81
) >
0x2e
) {
if
(v5 >
128
) {
v8
=
v5
-
48
;
data2[i]
+
=
v8;
}
}
else
{
v8
=
v5
-
48
;
data2[i] ^
=
(v8 >>
4
);
};
}
else
{
v8
=
v5
-
80
;
data2[i]
-
=
v8;
}
}
}
unsigned char target[
32
]
=
{
0x57
,
0xC5
,
0x38
,
0x1B
,
0x3A
,
0xA8
,
0x34
,
0x2F
,
0x39
,
0x97
,
0xC6
,
0xE4
,
0x04
,
0x2F
,
0x8F
,
0xEE
,
0x5E
,
0x51
,
0x80
,
0x67
,
0x24
,
0xC9
,
0x6F
,
0x48
,
0x5B
,
0x7F
,
0xBD
,
0xC7
,
0xB0
,
0xC2
,
0xC2
,
0xEB
};
unsigned char initkey[
32
]
=
{
0xA5
,
0x6A
,
0xA7
,
0x71
,
0xB4
,
0x77
,
0xC6
,
0x03
,
0xD1
,
0x08
,
0xDF
,
0x18
,
0xCE
,
0x03
,
0xD7
,
0x0F
,
0xCC
,
0x77
,
0xBA
,
0x62
,
0xAE
,
0x6D
,
0xDD
,
0x18
,
0xC0
,
0x09
,
0xD5
,
0xD5
,
0xD5
,
0xD5
,
0xD5
,
0xD5
};
char seq[]
=
{
5
,
5
,
4
,
4
,
5
,
4
,
0
,
0
,
4
,
2
,
5
,
5
,
1
,
3
,
1
,
5
,
1
,
2
,
3
,
0
,
3
,
0
,
2
,
3
,
4
,
4
,
3
,
2
,
2
,
5
,
5
,
0
};
unsigned char subkey[
32
][
32
]
=
{
0
};
unsigned char nulldata[
32
]
=
{
0
};
int
main() {
memcpy(subkey[
0
], initkey,
32
);
for
(
int
i
=
0
; i <
32
; i
+
+
) {
switch (seq[i]) {
case
0
:
enc_0(&subkey[i][
0
], nulldata);
break
;
case
1
:
enc_1(&subkey[i][
0
], nulldata);
break
;
case
2
:
enc_2(&subkey[i][
0
], nulldata);
break
;
case
3
:
enc_3(&subkey[i][
0
], nulldata);
break
;
case
4
:
enc_4(&subkey[i][
0
], nulldata);
break
;
case
5
:
enc_5(&subkey[i][
0
], nulldata);
break
;
}
for
(
int
j
=
0
;j<
32
;j
+
+
)
{
printf(
"%x "
,subkey[i][j]);
}
printf(
"\n"
);
memcpy(subkey[i
+
1
], subkey[i],
32
);
}
for
(
int
i
=
31
; i >
=
0
; i
-
-
) {
switch (seq[i]) {
case
0
:
enc_0_dec(&subkey[i][
0
], target);
break
;
case
1
:
enc_1_dec(&subkey[i][
0
], target);
break
;
case
2
:
enc_2_dec(&subkey[i][
0
], target);
break
;
case
3
:
enc_3_dec(&subkey[i][
0
], target);
break
;
case
4
:
enc_4_dec(&subkey[i][
0
], target);
break
;
case
5
:
unsigned char tmp[
32
];
if
(i !
=
0
)
memcpy(tmp,&subkey[i
-
1
][
0
] ,
32
);
else
if
(i
=
=
0
)
memcpy(tmp,initkey ,
32
);
enc_5_dec(tmp, target);
break
;
}
}
printf(
"%s"
, target);
return
0
;
}