{
"question_id": 7409321, "question_title": "如何实现凯撒密码对文本文件(.txt)的读取穷举暴力破解?", "question_content": "<p>对文本文件中凯撒密码穷举破解 并把26次结果 输出为二十六个文本文件(.txt)</p>", "difficulty": "中等", "answer_id": 53360172, "answer_content": "<p> 将输入数据放于"read.txt"文件中,编译运行程序即可。</p>\n\n<pre>\n<code class=\"language-cpp\">#include<stdio.h>\n\nint main(void){\n\tFILE *fp=NULL;\n\tchar c[200000],x;\n\tint i=0,n=0,j=0;\n\t\n\tfp=fopen("read.txt","r"); //读取txt文件数据 \n\twhile((x=fgetc(fp))!=EOF){\n\t\tc[i]=x;\n\t\ti++;\n\t}\n\tn=i;\n\tc[n]='\\0';\n\tfclose(fp);\n\t\n\tchar f[20]="write00.txt";\n\tfor(i=1;i<=26;i++){\n\t\tif(f[6]=='9'){ //将输出文件从01至26排序 \n\t\t\tf[6]='0';\n\t\t\tf[5]++;\n\t\t}\n\t\telse\n\t\t\tf[6]++;\n\t\n\t\tfor(j=0;j<n;j++){ //进行暴力破解,一次将所有字母往后移动一位 \n\t\t\tif(c[j]>='a'&&c[j]<'z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='z')\n\t\t\t\tc[j]='a';\n\t\t\tif(c[j]>='A'&&c[j]<'Z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='Z')\n\t\t\t\tc[j]='A';\n\t\t}\n\t\t\n\t\tfp=fopen(f,"w");//输出文件 \n\t\tfputs(c,fp);\n\t\tfclose(fp);\n\t}\n\treturn 0;\n}</code></pre>\n\n<p> </p>", "tag_name": "c语言", "cpp": "#include<stdio.h>\nint main(void){\n\tFILE *fp=NULL;\n\tchar c[200000],x;\n\tint i=0,n=0,j=0;\n\tfp=fopen(\"read.txt\",\"r\"); \n\twhile((x=fgetc(fp))!=EOF){\n\t\tc[i]=x;\n\t\ti++;\n\t}\n\tn=i;\n\tc[n]='\\0';\n\tfclose(fp);\n\tchar f[20]=\"write00.txt\";\n\tfor(i=1;i<=26;i++){\n\t\tif(f[6]=='9'){ \n\t\t\tf[6]='0';\n\t\t\tf[5]++;\n\t\t}\n\t\telse\n\t\t\tf[6]++;\n\t\tfor(j=0;j<n;j++){ \n\t\t\tif(c[j]>='a'&&c[j]<'z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='z')\n\t\t\t\tc[j]='a';\n\t\t\tif(c[j]>='A'&&c[j]<'Z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='Z')\n\t\t\t\tc[j]='A';\n\t\t}\n\t\tfp=fopen(f,\"w\");\n\t\tfputs(c,fp);\n\t\tfclose(fp);\n\t}\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600470256", "status": 0, "keywords": "密码破解", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/23.ipynb?type=file" }, "author": "vfengh"
}