⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.c

📁 caesar cipher 分析 能够分析单个替代的caesar cipher
💻 C
字号:
#include <stdio.h>
#include <stdlib.h> 
#include <string.h> 
void toUPPER (char s[]);
void todecode (char s[]);

int main() 
{ 
	
	FILE *fp1; 
	FILE *fp2; 
	char buf[1024]; 
	char ch;
	
		if( (fp1=fopen("d:\\abc.txt","r"))==NULL ) 
		{ 
			printf("open file failed  or no abc.txt! @ d:\n\n"); 
			
			 system("pause");
			exit(0);
		} 
		
	 fp2=fopen("d:\\out.txt","w"); 
	printf("         Here is a caesar cipher encoder & decoder\n");
	printf("Your file was loaded\n ");
while(1)
   {
   	printf("\n\nEncode press 'e'\nDecode press 'd'\n");
   	
  scanf("%c",&ch);
  
  
   if (ch == 'e'){
  
   break;
   }
   else if (ch == 'd'){ 
  
   	break;
   }
   else {
   printf("\nerror input, input again\n");
   continue;
   }
   
   }

while(!feof(fp1))  
 { 
   memset(buf, 0, 1024); 
   fgets(buf, 1024, fp1); 
   
   
  
   if (ch == 'e'){
   toUPPER (buf);
  
   }
   else if (ch == 'd'){ 
   	todecode (buf);
   
   }
   fputs(buf,fp2);
 }
 
 printf("done!");
fclose(fp1); 

 system("pause");
 
return 0; 

}

//decode function
void todecode (char s[])
{
 	int i = 0;
    while (s[i]!='\0')
    {
    	if (s[i]>='D' && s[i]<='Z')
    	{
    		s[i]=s[i]-3;
    	}
    	else if (s[i]>='d' && s[i]<='z')
    	{
    		s[i]=s[i]-3;
    	}
    	else if (s[i]=='A'||s[i]=='B'||s[i]=='c'||s[i]=='a'||s[i]=='b'||s[i]=='c')
    	{
    		s[i]=s[i]+23;
    	}
    
    	i++;
    }

}

//encode function
void toUPPER (char s[])
{
 	int i = 0;
    while (s[i]!='\0')
    {
    	if (s[i]>='A' && s[i]<='W')
    	{
    		s[i]=s[i]+3;
    	}
    	else if (s[i]>='a' && s[i]<='w')
    	{
    		s[i]=s[i]+3;
    	}
    	else if (s[i]=='X'||s[i]=='Y'||s[i]=='Z'||s[i]=='x'||s[i]=='y'||s[i]=='z')
    	{
    		s[i]=s[i]-23;
    	}
    
    	i++;
    }
 	}










⌨️ 快捷键说明

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