void des(unsigned char *data_p,char type1,unsigned char* key_p,char type2,int type) { unsigned char tempbuf[12]; unsigned char key[7]; unsigned char i; unsigned char j; unsigned char count; void (*f)(unsigned char* data_p,char type); selectbits(data_p,type1,(unsigned char *)DesIp,PGROM,tempbuf,SRAM,64);/*????*/ movram(tempbuf,SRAM,data_p,type1,8); selectbits((unsigned char *)key_p,type2,(unsigned char *)DesPc_1,PGROM,(unsigned char *)key,SRAM,56);/*KEY?????*/ for(i = 0;i < 16;i ++) { selectbits((unsigned char *)data_p + 4,type1,(unsigned char *)DesE,PGROM,tempbuf,SRAM,48);/*????*/ if(type ==1) //jia mi { f = shlc; count = i; } else { count = 16 - i; f = shrc; } for(j = 0;j < pgm_read_byte(&DesRots[count]);j++)/*KEY ???*/ { f(key,SRAM); } selectbits(key,SRAM,(unsigned char *)DesPc_2,PGROM,tempbuf + 6,SRAM,48);/*KEY ????*/ doxor(tempbuf,SRAM,tempbuf + 6,SRAM,6); strans(tempbuf,SRAM,tempbuf + 6,SRAM); selectbits(tempbuf + 6,SRAM,(unsigned char *)DesP,PGROM,tempbuf,SRAM,32); doxor(tempbuf,SRAM,data_p,type1,4); if(i < 15) { movram(data_p + 4,type1,data_p,type1,4); movram(tempbuf,SRAM,data_p + 4,type1,4); } } movram(tempbuf,SRAM,data_p,type1,4); selectbits(data_p,type1,(unsigned char *)DesIp_1,PGROM,tempbuf,SRAM,64); movram(tempbuf,SRAM,data_p,type1,8); }
int main() { FILE *file,*file2; //int list[65536][28]; char node[65536][2]; int temp; unsigned short int move[65536][2]; std::vector<unsigned short int> list[65536][2]; //file=fopen("list.txt","w"); //file2=fopen("node.txt","w"); for (int turn=0;turn<2;turn++) { for (int fin=0;fin<65536;fin++) { list[fin][turn].clear(); for (int from=0;from<2;from++) { for (int to=0;to<2;to++) { if (!IsKilled(fin,from,turn) && !IsKilled(fin,to,turn?0:1)) { for (int shift=-3;shift<=3;shift++) { temp=doxor(fin,(bool)from,(bool)to,shift,(bool)turn); std::vector<unsigned short int>::iterator it = std::find(list[fin][turn].begin(),list[fin][turn].end(),temp); if (it == list[fin][turn].end()) list[fin][turn].push_back(temp); } } } } for ( std::vector<unsigned short int>::iterator it = list[fin][turn].begin() ; it!=list[fin][turn].end() ; ++it ) { if (it!=list[fin][turn].begin()) ;//printf(" "); //printf("%d",*it); } //printf("\n"); } } memset(node,0,sizeof(node)); memset(move,0,sizeof(move)); for (int i=0;i<65536;i++) { if (IsKilled(i,0,0) && IsKilled(i,1,0)) { node[i][0]=2; node[i][1]=2; } else if (IsKilled(i,0,1) && IsKilled(i,1,1)) { node[i][0]=1; node[i][1]=1; } } for (int i=0;i<500;i++) { bool noflag=true; for (int fin=0;fin<65536;fin++) { if (node[fin][0]==0) { bool tsumi=true; for ( std::vector<unsigned short int>::iterator it = list[fin][0].begin() ; it!=list[fin][0].end() ; ++it ) { if (node[*it][1] == 1) { node[fin][0] = 1; move[fin][0] = *it; noflag=false; break; } } } if (node[fin][1]==0) { bool tsumi=true; for ( std::vector<unsigned short int>::iterator it = list[fin][1].begin() ; it!=list[fin][1].end() ; ++it ) { if (tsumi) { if (node[*it][0] != 1) { tsumi=false; } } } if (tsumi && node[fin][1]==0) { node[fin][1]=1; move[fin][1]=list[fin][1][0]; noflag=false; } } } if (noflag) { //printf("%d\n",i); break; } } for (int fl=2;fl<100;fl++) { int win,total; for (int fin=0;fin<65536;fin++) { if (node[fin][1]==0) { bool tsumi=true; win=0; total=0; for ( std::vector<unsigned short int>::iterator it = list[fin][1].begin() ; it!=list[fin][1].end() ; ++it ) { if (node[*it][0]<fl && node[*it][0]!=0) { win++; } total++; } if ((win>5 && total-win==1) || (double)win/(double)total>=0.9) { node[fin][1]=fl; for ( std::vector<unsigned short int>::iterator it = list[fin][1].begin() ; it!=list[fin][1].end() ; ++it ) { if (node[*it][0]<fl && node[*it][0]!=0) { move[fin][1]=*it; break; } } } } } for (int fin=0;fin<65536;fin++) { if (node[fin][0]==0) { bool tsumi=true; for ( std::vector<unsigned short int>::iterator it = list[fin][0].begin() ; it!=list[fin][0].end() ; ++it ) { if (node[*it][1] == fl) { node[fin][0] = fl; move[fin][0]=*it; break; } } } } } for (int i=0;i<15000;i++) { printf("%04x",move[i][0]); } //puts("end"); //fclose(file); //fclose(file2); return 0; }