#包含“stdio.h“
#包含“string.h“
#包含“stdlib.h“
#定義x 50
字符姚蜜【x】,密碼【x】,添加通行證【x】,表【5】【5】,映射【25】;
bool Visit【27】= { false };
char English【27】=“abcdefghijklmnopqrstuvwxyz“;
void輸入()
{
Printf(“請輸入密鑰:\ t“);scanf(“% s“,姚蜜);
Printf(“請輸入要加密的密碼:\ t“);scanf(“% s“,密碼);
}
void Fun_5x5()
{
int count = 0,V = 0;
/*令牌密鑰中的字符為:true*/
for(int I = 0;姚蜜【我】='\0';i++)
if(strchr(英語,姚蜜【I】)!=NULL)
visit【strchr(英語,姚蜜【I】)-英語】= true
/*執行關鍵矩陣運算並標記使用的字符:true*/
for(int I = 0;我& lt5;i++)
for(int j = 0;j & lt5;j++)
{
if(count & lt;斯特蘭(姚蜜))
表【I】【j】=姚蜜【count++】;
其他
{
while(訪問【V】!= false)v++;
表【I】【j】=英文【V】;
visit【v++】= true;
}
}
puts(“∞∞∞鍵矩陣是∞∞∞”);
for(int I = 0;我& lt5;i++)
{ for(int j = 0;j & lt5;j++)
printf(“% 3c“,Table【I】【j】);
puts(“”);
}
看跌期權(“∞奇葩說“);
}
int被訪問(char ch)
{
回訪【strchr(英語,中文)-英語】;//false沒有出現。
}
void TabletoMap()
{ int count = 0;
for(int I = 0;我& lt5;i++)
for(int j = 0;j & lt5;j++)
map【count ++】= Table【I】【j】;
map【count】=‘\ 0‘;
}
無效判斷()
{
int len = strlen(PassWord),I,j,k;
memset(add pass,0,sizeof(char));
/*刪除壹對字母,單個字母不變,直接放入加密字符串。*/
if(len % 2 ){
add pass【len-1】= PassWord【len-1】;
len-= 1;
}
/*在壹對關鍵矩陣中有壹個矩陣eg.ab。先輸出A對等頂點,再輸出B對等頂點*/
int row1,low1,row2,low2,a1,a2。
for(I = 0;我& ltleni+=2)
{
char c1,C2;
c1 =密碼【I】;
c2 =密碼【I+1】;
/*壹對中的兩個字母相同且不變*/
/*字母對中有不在關鍵字矩陣中的字母*/
if(c 1 = = C2 | |(!is visited(c 1)| |!IsVisited(C2))
{ add pass【I】= c 1;
add pass【I+1】= C2;
}否則{
a 1 = strchr(Map,c 1)-Map;
row 1 = a 1/5;low 1 = a 1% 5;
a2 = strchr(Map,C2)-Map;
row 2 = a2/5;low 2 = a2 % 5;
/*壹對漢字出現在同壹行或同壹列中。簡單交換字符*/
if(row 1 = = row 2 | | low 1 = = low 2)
{
add pass【I】= C2;
add pass【I+1】= c 1;
}否則{
add pass【I】= Table【row 1】【low 2】;
add pass【I+1】= Table【row 2】【low 1】;
}
}
} add pass【len+1】=‘\ 0‘;
Puts(“加密字符串:“);
puts(add pass);
Puts(“原字符串為:“);
puts(密碼);
}
int main()
{
input();
fun _ 5x 5();
table to map();
judge();
返回0;
}