diff --git a/AUTHORS b/AUTHORS old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.rst b/README.rst old mode 100644 new mode 100755 diff --git a/des.c b/des.c old mode 100644 new mode 100755 index ada929c..6287b4c --- a/des.c +++ b/des.c @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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) { @@ -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; } } diff --git a/des.h b/des.h old mode 100644 new mode 100755 diff --git a/instructions.txt b/instructions.txt new file mode 100644 index 0000000..d2046cf --- /dev/null +++ b/instructions.txt @@ -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 diff --git a/run_des.c b/run_des.c old mode 100644 new mode 100755