求解用C语言编写Playfair加密算法问题
提示: 作者被禁止或删除 内容自动屏蔽
#include <stdio.h> #include <stdlib.h> #include<string.h> char p[6][6]={{'C','I','P','H','E','C'}, {'R','A','B','D','F','R'}, {'G','K','L','M','N','G'}, {'O','Q','S','T','U','O'}, {'V','W','X','Y','Z','V'}, {'C','I','P','H','E','C'}}; int main() { char str[100]; int i,j,n; int len='a'-'A'; printf("Please input a word!\n"); scanf("%s",str); for(i=0;i<strlen(str);i++)/////////// { if(str[i]>'Z') str[i]=str[i]-len; if(str[i]=='J')/////////// str[i]='I'; } for(i=0;i<strlen(str);i=i+2)/////// { if(str[i]==str[i+1]) ///////////// { for(j=strlen(str)+1;j>i+1;j--) str[j+1]=str[j]; str[i+1]='X'; } } n=strlen(str); /* for(i=0;i<n;)/////// { printf("%c ",str[i]); i++; if(i%5==0) printf("\n"); }*/ if(n%2==1) { n++; str[n+1]='X'; } char temp1,temp2; int k=0,s=0,l=0,r=0,t;////////// for(t=0;t<n;t=t+2)//////// { temp1=str[t]; temp2=str[t+1]; for(i=0;i<5;i++) { for(j=0;j<5;j++) { if(p[i][j]==temp1) { k=i; s=j; } if(p[i][j]==temp2) { l=i; r=j; } } } if(k==l) //////////// printf("%c,%c ",p[k][(s+1)%5],p[l][(r+1)%5]);////////// else if(s==r) ////////////// printf("%c,%c ",p[(k+1)%5][s],p[(l+1)%5][r]);////////// else printf("%c,%c ",p[k][r],p[l][s]); } return 0; }