Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified AUTHORS
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.rst
100644 → 100755
Empty file.
20 changes: 11 additions & 9 deletions des.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int initial_key_permutaion[] = {57, 49, 41, 33, 25, 17, 9,
63, 55, 47, 39, 31, 23, 15,
7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4};
21, 13, 5, 28, 20, 12, 4};//选择置换PC-1,密钥置换64-56

int initial_message_permutation[] = {58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
Expand All @@ -20,9 +20,9 @@ int initial_message_permutation[] = {58, 50, 42, 34, 26, 18, 10, 2,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7};
63, 55, 47, 39, 31, 23, 15, 7};//初始置换IP,明文代换,64-64,分两块

int key_shift_sizes[] = {-1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1};
int key_shift_sizes[] = {-1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1};//左移位数,16次

int sub_key_permutation[] = {14, 17, 11, 24, 1, 5,
3, 28, 15, 6, 21, 10,
Expand All @@ -31,7 +31,7 @@ int sub_key_permutation[] = {14, 17, 11, 24, 1, 5,
41, 52, 31, 37, 47, 55,
30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53,
46, 42, 50, 36, 29, 32};
46, 42, 50, 36, 29, 32};//选择置换PC-2,56-48,得子密钥

int message_expansion[] = {32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
Expand All @@ -40,7 +40,7 @@ int message_expansion[] = {32, 1, 2, 3, 4, 5,
16, 17, 18, 19, 20, 21,
20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29,
28, 29, 30, 31, 32, 1};
28, 29, 30, 31, 32, 1};//扩展变换E,R扩展,32-48

int S1[] = {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,
Expand Down Expand Up @@ -80,7 +80,7 @@ int S7[] = { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
int S8[] = {13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11};
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11};//八个S盒,替换异或后的8组

int right_sub_message_permutation[] = {16, 7, 20, 21,
29, 12, 28, 17,
Expand All @@ -89,7 +89,7 @@ int right_sub_message_permutation[] = {16, 7, 20, 21,
2, 8, 24, 14,
32, 27, 3, 9,
19, 13, 30, 6,
22, 11, 4, 25};
22, 11, 4, 25};//P置换,S盒后的32位代换

int final_message_permutation[] = {40, 8, 48, 16, 56, 24, 64, 32,
39, 7, 47, 15, 55, 23, 63, 31,
Expand All @@ -98,7 +98,7 @@ int final_message_permutation[] = {40, 8, 48, 16, 56, 24, 64, 32,
36, 4, 44, 12, 52, 20, 60, 28,
35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26,
33, 1, 41, 9, 49, 17, 57, 25};
33, 1, 41, 9, 49, 17, 57, 25};//初始逆置换IP


void print_char_as_binary(char input) {
Expand All @@ -115,8 +115,10 @@ void print_char_as_binary(char input) {

void generate_key(unsigned char* key) {
int i;
printf("Please input your key(less than 8 bytes)\n");
for (i=0; i<8; i++) {
key[i] = rand()%255;
scanf("%c",&key[i]);
//key[i] = rand()%255;
}
}

Expand Down
Empty file modified des.h
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gcc -O3 des.c run_des.c -o run_des.o

./run_des.o -g keyfile.key

./run_des.o -e keyfile.key sample.txt sample.enc

./run_des.o -d keyfile.key sample.enc sample_decrypted.txt
Empty file modified run_des.c
100644 → 100755
Empty file.