v.c

来自「*** *** *维吉利亚密码C语言版*************简单实用」· C语言 代码 · 共 42 行

C
42
字号
void Vigenere() /*维吉利亚密码*/ 
{ 
char c[100], key[100]; 
int lenc, lenk, i=0, j=0, tmp; 
clrscr(); 

printf("********Vigenere Cipher********\nPlease input primal sentence: "); 
gets(c); 
lenc = strlen(c); 
strcpy(c, strupr(c)); 
printf("Input the key: "); 
gets(key); 
lenk = strlen(key); 
strcpy(key, strupr(key)); 
for(; i<lenc; i++) 
{ 
j = j%lenk; 
if(c[i]>64&&c[i]<91) 
{ 
c[i] = (c[i]-65+key[j]-65)%26+65; 
j++; 
} 
} 
printf("Result is: %s\n", c); 
for(i=0, j=0; i<lenc; i++) 
{ 
j = j%lenk; 
if(c[i]>64&&c[i]<91) 
{ 
tmp = c[i]-65-(key[j]-65); 
if(tmp>=0) 
c[i] = tmp%26+97; 
else 
c[i] = (tmp+26)%26+97; 
j++; 
} 
} 
printf("\nAfter translated the sentence,we can see the primal sentence as follow:\n%s\n", c); 
printf("Press any key to return..."); 
getch(); 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?