猫史档案馆


我也不知道为什么发这个帖子

用户:AlanTuringAlanTuring查看:2 回复:2 评论:2 创建时间:2020-08-19T12:53:30


C++制作,凯撒密码生成/破译器(选项1和2弄反了)

附代码:

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
void tips()
{
	cout<<"##############################"<<endl;
	cout<<"########1.左移获取密码########"<<endl;
	cout<<"########2.右移获取密码########"<<endl;
	cout<<"########3.左移破译密码########"<<endl;
	cout<<"########4.右移破译密码########"<<endl;
	cout<<"########5.退出凯撒密码########"<<endl;
	cout<<"##############################"<<endl;
}

void PasswordLeft(string &mcode)
{
	for(int i=0;i<mcode.size();i++)
	{
		if(mcode[i]!='z')
		{
			mcode[i]++;
		}
		else
		{
			mcode[i]=97;
		}
	}
}
void PasswordRight(string &mcode)
{
	for(int i=0;i<mcode.size();i++)
	{
		if(mcode[i]!='a')
		{
			mcode[i]--;
		}
		else
		{
			mcode[i]=122;
		}
	}
}

void CodeLeft(string &mcode)
{
	for(int i=0;i<mcode.size();i++)
	{
		if(mcode[i]!='a')
		{
			mcode[i]--;
		}
		else
		{
			mcode[i]=122;
		}
	}
}
void CodeRight(string &mcode)
{
	for(int i=0;i<mcode.size();i++)
	{
		if(mcode[i]!='z')
		{
			mcode[i]++;
		}
		else
		{
			mcode[i]=97;
		}
	}	
}
int main()
{
	string password,code;
	
	int choice=1;
	while(choice==1 or choice==2 or choice==3 or choice==4)
	{
		tips();
		cout<<"请输入选择";
		cin>>choice;

		if(choice==1)
		{
			cout<<"请输入密码";
			cin>>code;
			cout<<"正在转换!"<<endl;
			
			PasswordLeft(code);
			cout<<code<<endl;
			cout<<"转换成功!"<<endl;
		}
		else if(choice==2)
		{
			cout<<"请输入密码";
			cin>>code;
			cout<<"正在转换!"<<endl;
			
			PasswordRight(code);
			cout<<code<<endl;
			cout<<"转换成功!"<<endl;
		}
		else if(choice==3)
		{
			cout<<"请输入密码";
			cin>>code;
			cout<<"正在破译!"<<endl;
			
			CodeLeft(code);
			cout<<code<<endl;
			cout<<"破译成功!"<<endl;
		}
		else if(choice==4)
		{
			cout<<"请输入密码";
			cin>>code;
			cout<<"正在破译!"<<endl;
			
			CodeRight(code);
			cout<<code<<endl;
			cout<<"破译成功!"<<endl;
		}
		else
		{}

		
		system("pause");
		system("cls");
	}
	cout<<"退出成功"<<endl;
	
	system("pause");
	return 0;
}


回复

上一页1 页 / 共 1下一页
TafiTafi

好厉害的样子

点赞0


评论


如虎添翼2007如虎添翼2007

还有C++编辑器吗?我咋不知道?

 

点赞0


评论