23.json 2.6 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1
{
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  "question_id": 7409321,
  "question_title": "如何实现凯撒密码对文本文件(.txt)的读取穷举暴力破解?",
  "question_content": "<p>对文本文件中凯撒密码穷举破解 并把26次结果 输出为二十六个文本文件&#xff08;.txt&#xff09;</p>",
  "difficulty": "中等",
  "answer_id": 53360172,
  "answer_content": "<p> 将输入数据放于&#34;read.txt&#34;文件中&#xff0c;编译运行程序即可。</p>\n\n<pre>\n<code class=\"language-cpp\">#include&lt;stdio.h&gt;\n\nint main(void){\n\tFILE *fp&#61;NULL;\n\tchar c[200000],x;\n\tint i&#61;0,n&#61;0,j&#61;0;\n\t\n\tfp&#61;fopen(&#34;read.txt&#34;,&#34;r&#34;); //读取txt文件数据 \n\twhile((x&#61;fgetc(fp))!&#61;EOF){\n\t\tc[i]&#61;x;\n\t\ti&#43;&#43;;\n\t}\n\tn&#61;i;\n\tc[n]&#61;&#39;\\0&#39;;\n\tfclose(fp);\n\t\n\tchar f[20]&#61;&#34;write00.txt&#34;;\n\tfor(i&#61;1;i&lt;&#61;26;i&#43;&#43;){\n\t\tif(f[6]&#61;&#61;&#39;9&#39;){  //将输出文件从01至26排序 \n\t\t\tf[6]&#61;&#39;0&#39;;\n\t\t\tf[5]&#43;&#43;;\n\t\t}\n\t\telse\n\t\t\tf[6]&#43;&#43;;\n\t\n\t\tfor(j&#61;0;j&lt;n;j&#43;&#43;){  //进行暴力破解&#xff0c;一次将所有字母往后移动一位 \n\t\t\tif(c[j]&gt;&#61;&#39;a&#39;&amp;&amp;c[j]&lt;&#39;z&#39;)\n\t\t\t\tc[j]&#43;&#61;1;\n\t\t\telse if(c[j]&#61;&#61;&#39;z&#39;)\n\t\t\t\tc[j]&#61;&#39;a&#39;;\n\t\t\tif(c[j]&gt;&#61;&#39;A&#39;&amp;&amp;c[j]&lt;&#39;Z&#39;)\n\t\t\t\tc[j]&#43;&#61;1;\n\t\t\telse if(c[j]&#61;&#61;&#39;Z&#39;)\n\t\t\t\tc[j]&#61;&#39;A&#39;;\n\t\t}\n\t\t\n\t\tfp&#61;fopen(f,&#34;w&#34;);//输出文件 \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"
每日一练社区's avatar
test  
每日一练社区 已提交
18
}