自己写的一个破解凯撒密码的工具,主要原理呢就是把所有可能结果列出来,然后与关键词相对比,最后快速找出可能的答案。

加上人工判断,基本上就没问题了。
另外本工具还会把结果输出到txt文件中,并自动用记事本打开。方便复制。

直接编译就可以运行了,我就不提供exe执行文件咯。

感谢你的使用,(*^__^*)…嘻嘻。

 
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "windows.h"
#define TITLE       SetConsoleTextAttribute(consolehwnd,10);printf("************************************************************                    凯撒密码破解器 v1.03         舒俊杰制作 ************************************************************");
char Caesar[200];
main()
{
      HANDLE consolehwnd; 
      consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);      
      FILE *in,*out;
      out=fopen("out.txt","w");
      char key[30],orgCaesar[200];
      system("color 2f");
      SetConsoleTitle("凯撒密码破解器");
      system("mode con cols=60 lines=16");   
      system("CLS");
      TITLE;
      SetConsoleTextAttribute(consolehwnd,47);
      int n,i,j=0,x;
      if ((in=fopen("in.txt","r"))==NULL)
       {   printf("没有找到输入文件in.txt,请手动输入。\n密文:");
           gets(orgCaesar);
       }
      else 
       {
           fgets(orgCaesar,200,in);
           fclose(in);
           printf("从文件in.txt中输入了密文。\n");
       }
      printf("关键字:");
      gets(key);
      printf("\n破解结果为:\n");
 
      for (n=0;n<26;n++)
       {
         for (i=0;orgCaesar[i]!=0;i++) 
           {
                  if (orgCaesar[i]>='A'&&orgCaesar[i]<='Z') {Caesar[i]='A'+(orgCaesar[i]-'A'+n)%26;continue;}
                  if (orgCaesar[i]>='a'&&orgCaesar[i]<='z') {Caesar[i]='a'+(orgCaesar[i]-'a'+n)%26;continue;}
                  Caesar[i]=orgCaesar[i];
           }
         if (strstr(Caesar,key)!=0)
           {  
                  puts(Caesar);
                  fputs(Caesar,out);
                  fputc('\n',out);
                  j++;
           }
        }
       fclose(out); 
       j==0?(printf("没有找到任何记录!",j),remove("out.txt")):(printf("共找到%d条记录,请自行寻找合适记录。\n\n输出记录已经保存到out.txt中。",j),system("notepad out.txt"));
       getch();
}

原创文章,转载请注明: 转载自耍下
本文链接地址: 凯撒密码破解器