简单移位加密

简单移位加密算法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;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值