本文主要是介绍简单移位加密,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
简单移位加密算法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;
}
这篇关于简单移位加密的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!