From 14ead82af92bf83e279e850f3f46e81fae9ae1ff Mon Sep 17 00:00:00 2001 From: pos3ym7vj <1226255226@qq.com> Date: Fri, 16 Dec 2022 11:04:51 +0800 Subject: [PATCH] ADD file via upload --- windows.cpp | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 windows.cpp diff --git a/windows.cpp b/windows.cpp new file mode 100644 index 0000000..5e66837 --- /dev/null +++ b/windows.cpp @@ -0,0 +1,139 @@ +#include +#include +#include +#include +#include +#include +#include"analysis table.h" +#include "des.h" +#include "hack.h" +#include "key table.h" +#include +#include +#include +#include +using namespace std; + + +int main() { + + int chooseNum; + int q; + + printf(" \n\n\n\n\n\n\n \n"); + printf(" ################################################################\n"); + printf(" ## ##\n"); + printf(" ## ##\n"); + printf(" ## DES差分分析 ##\n"); + printf(" ## ##\n"); + printf(" ## ##\n"); + printf(" ## ##\n"); + printf(" ################################################################\n\n"); + printf(" 请按任何键以继续 ,, "); + getchar(); + system("cls"); + + printf("\n\n\n\n\n\n\n 请选择任务序号:\n"); + printf(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + printf(" @ @\n"); + printf(" @ ** 1=任务1 差分分析统计表 ** @\n"); + printf(" @ ** 2=任务2 输出密钥集合 ** @\n"); + printf(" @ ** 3=任务3 三轮差分攻击 ** @\n"); + printf(" @ ** 4=任务4 六轮差分攻击 ** @\n"); + printf(" @ ** ** @\n"); + printf(" @ ** 5= 退出 ** @\n"); + printf(" @ @\n"); + printf(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + printf(" 请输入您的选择:"); + scanf("%d", &chooseNum); + getchar(); + + while (chooseNum != 5) + { + switch (chooseNum) + { + case 1: + printf("请输入6位差分:"); + char intput[6]; + scanf("%s", intput); + //gets_s(intput); + int intputchafen[6]; + for (q = 0; q < 6; q++) { + if (intput[q] == '0') + intputchafen[q] = 0; + else intputchafen[q] = 1; //防止用户输入了些奇奇怪怪的数字 + } + printf("\n"); + mainFuntion(intputchafen); + system("PAUSE"); + break; + + case 2: + char E[6]; + char ee[6]; //E* + char hello[4]; //输出差分 + + printf("s盒的输入E:(6位)"); + + scanf("%s",E); + printf("s盒的输入e:(6位)"); + scanf("%s",ee); + + printf("s盒的输出差分hello:(4位)"); + scanf("%s",hello); + mainFuntion4(E, ee, hello); + system("PAUSE"); + break; + + case 3: + system("3rnd.exe"); + break; + + case 4: + ull inA = 0, inB = 0, outA = 0, outB = 0; + ull inC = 0, inD = 0, outC = 0, outD = 0; + ull key; + printf("请输入初始64位密钥(十六进制以0x开头):\n"); + cin >> hex >> key; + //ull key = 0xF0F0F0F0F0F0F0F0; + /* ull key = 0xF1F2F3F4F5F6F7F8;*/ + + DesHacker hacker; + for (int i = 0; i < 2; i++) { + constructCipherPlaintexts(key, 1, inA, inB, outA, outB); // 随机生成满足第一种差分特征的两个明密文对 + hacker.addCipherPlaintexts(inA, inB, outA, outB); // 将构造好的明密文对传入DesHacker中 + } + for (int i = 0; i < 2; i++) { + constructCipherPlaintexts(key, 2, inC, inD, outC, outD); // 随机生成满足第二种差分特征的两个明密文对 + hacker.addCipherPlaintexts(inC, inD, outC, outD); + } + + if (hacker.hack()) { // 差分分析 + ull result_key = hacker.getKey(); + printf("Success\n"); + print_long_hex(result_key); + } + else { + printf("Failed...\n"); + } + system("PAUSE"); + break; + } + system("cls"); + printf("\n\n\n\n\n\n\n 请选择任务序号:\n"); + printf(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + printf(" @ @\n"); + printf(" @ ** 1=任务1 差分分析统计表 ** @\n"); + printf(" @ ** 2=任务2 输出密钥集合 ** @\n"); + printf(" @ ** 3=任务3 三轮差分攻击 ** @\n"); + printf(" @ ** 4=任务4 六轮差分攻击 ** @\n"); + printf(" @ ** ** @\n"); + printf(" @ ** 5= 退出 ** @\n"); + printf(" @ @\n"); + printf(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + printf(" 请输入您的选择:"); + scanf("%d", &chooseNum); + getchar(); + } + return 0; +}