#include "stdafx.h"<br />#include <iostream><br />using std::cout;<br />using std::endl;<br />//密碼編譯演算法<br />static unsigned short buffer = 0xd971;<br />static unsigned long startup = 0xac7252f3; /* 00000000or whatever you want */<br />int _tmain(int argc, char* argv[])<br />{<br />unsigned char input;<br />unsigned char output;<br />int init = 4;<br />int i;<br />int result;<br />FILE *infile,*outfile;</p><p>infile=fopen("c://888.txt","r");<br />outfile=fopen("c://999.txt","w");<br />//sscanf(argv[1],"%lx",&startup);<br />fprintf(outfile,"%08lx",startup);<br />for (i=0;i<4;++i)<br />{<br />input = (startup >> ((3-i)*8));<br />buffer = (input + buffer) * 0xce6d + 0x58bf;<br />}<br />for(;;)<br />{<br />for (i=0;i<(32-init);++i)<br />{<br />input = result = fgetc(infile);<br />if ((int)result == EOF)<br />break;<br />output = (input ^ (buffer>>8));<br />buffer = (output + buffer) * 0xce6d + 0x58bf;<br />fprintf(outfile,"%02.2x",output);<br />}<br />init = 0;<br />fprintf(outfile,"/n");<br />if ((int) result == EOF)<br />break;<br />}<br />fclose(infile);<br />fclose(outfile);<br />}
// Decrpt.cpp : Defines the entry point for the console application.<br />//<br />#include "stdafx.h"<br />//解密演算法<br />int _tmain(int argc, _TCHAR* argv[])<br />{<br />int first =4;<br />int state=0xD971;<br />int c;<br />char decrptd;<br />FILE* infile=fopen("c://456.txt","r");<br />FILE* outfile=fopen("c://345.txt","w");<br />while(fscanf(infile,"%2x",&c)>0)<br />{<br />decrptd= c ^ (state >>8);<br />if(first !=0)<br />{<br />first--;<br />}<br />else<br />{<br />fputc(decrptd,outfile);<br />}<br />state=state + c;<br />state=state * 0xCE6D;<br />state=state + 0x58BF;</p><p>}<br />fclose(infile);<br />fclose(outfile);<br />return 0;<br />}<br />