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

📄 ttt.cpp

📁 利用VC的控制台主要实现了放射加密和解密算法
💻 CPP
字号:
// ttt.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream.h"
#include "string.h"
#include "process.h"
/*功能:求a对b的逆元*/
int niyuan(int a,int b)
{
	int x1=1,x2=0,x3=b,y1=0,y2=1,y3=a,t1=0,t2=0,t3=0,temp=0;

	while(1)
	{
		if(y3==0)
		{
			cout<<"无逆元";
			exit(1);
			return 0;
		}
		if(y3==1)
		{
			if(y2<=0)
				return b+y2;
			else
				return y2;
		}
		temp=x3/y3;
		t1=x1-temp*y1;
		t2=x2-temp*y2;
		t3=x3-temp*y3;
		x1=y1;
		x2=y2;
		x3=y3;
		y1=t1;
		y2=t2;
		y3=t3;
	}
}
/*功能:利用k1,k2对明文str加密*/
void jiami(int k1,int k2,char*  str)
{
	int i=strlen(str);
	char *temp=new char[i+1];
	for(int j=0;j<i;j++)
		temp[j]=(k1*(str[j]-33)+k2)%94+33;
	temp[j]='\0';
	cout<<"密文是:"<<temp<<endl;
}
/*功能:利用k1,k2对密文str解密*/
void jiemi(int k1,int k2,char*  str)
{
	int i=strlen(str);
	char *temp=new char[i+1];
	for(int j=0;j<i;j++)
		temp[j]=(niyuan(k1,94)*(str[j]-33-k2))%94+33;
	temp[j]='\0';
	cout<<"明文是:"<<temp<<endl;
}
int main(int argc, char* argv[])
{
	char *str1=new char[20];
	char *str2=new char[20];
	int k1=0,k2=0;
	cout<<"输入明文"<<endl;
	cin>>str1;
	cout<<"密钥1:";
	cin>>k1;
	cout<<"密钥2:";
	cin>>k2;
	jiami(k1,k2,str1);
	cout<<"输入密文"<<endl;
	cin>>str2;
	cout<<"密钥1:";
	cin>>k1;
	cout<<"密钥2:";
	cin>>k2;
	jiemi(k1,k2,str2);
	return 0;
}

⌨️ 快捷键说明

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