简单移位加密算法C语言实现
//#include<stdio.h>
#include<string.h>
#include<iostream>
const int MAX=100;
//using namespace std;
class SampleReplace
{
public:
SampleReplace(){ch='/0';memset(temp,0,sizeof(temp));};
~SampleReplace(){};
void DoEncrpytograph(int index,const char *crpytograph);
private:
char ch;
char temp[MAX];
};
void SampleReplace::DoEncrpytograph (int index,const char *cryptograph)
{
int j=0;
strcpy(temp,cryptograph);
while((ch=temp[j])!='/0')
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
ch+=index;
if((ch>'Z'&&ch<='Z'+index)||ch>'z')
ch-=26;
if(ch<0)
ch=ch+230;
}
temp[j]=ch;
j++;
}
//printf("移%2d位后明文为: %s/n",index,cryptograph);
std::cout<<"移动"<<index<<"位后明文为:"<<temp<<std::endl;
//cout<<"移动"<<index<<"位后明文为:"<<cryptograph<<endl;
}
int main()
{
std::cout<<"/t----------------Welcome to use zsh program --------------"<<std::endl;
std::cout<<"please input the cryptograph content"<<std::endl;
//cout<<"/t----------------Welcome to use zsh program --------------"<<endl;
//cout<<"please input the cryptograph content"<<endl;
//printf("/t----------------Welcome to use zsh program --------------/n");
//printf("please input the cryptograph content/n");
char cryptograph[MAX];
memset(cryptograph,0,sizeof(cryptograph));
gets(cryptograph);
SampleReplace SR;
for(int i=1;i<=25;i++)
{
SR.DoEncrpytograph (i,cryptograph);
}
printf("/n");
return 0;
}
2375

被折叠的 条评论
为什么被折叠?



