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

📄 古典密码学.cpp

📁 包含仿射caser算法
💻 CPP
字号:
<html><head><title>fangshe.rar fangshe.cpp</title>
<LINK href="/inc/read_style.css" type=text/css rel=stylesheet></head>
<body>
<p><a href=http://www.pudn.com>www.pudn.com</a> &gt; <a href="http://www.pudn.com/downloads62/sourcecode/crypt/detail217974.html">fangshe.rar</a> &gt fangshe.cpp</p><!-- saved from http://www.pudn.com -->
<script src="/inc/gg_read1.js"></script><BR>
<pre name="code" class="cpp">
#include<string.h> 
#include<iostream.h> 
void encode(int a, int b); 
void uncode(int a, int b); 
int getUncode(int a); 
 
int main() 
{ 
	int a, b,c,d; 
	cout<<"please input encode K(A,B)"<<endl; 
	cin>>a>>b; 
	c = getUncode(a); 
	d = -b; 
    cout<<"the uncode is K("<<c<<","<<d<<")"<<endl; 
	encode(a,b); 
	uncode(c,d); 
	return 0; 
} 
 
 
void encode(int a,int b) 
{ 
    int  len=0,i=0,j=0,temp; 
    char s[1000]; 
	char s1[1000]; 
	 
	cout<<"please input the string"<<endl; 
	cout<<"(warning the length not more than 1000 and must be small letters)"<<endl; 
    cin>>s; 
	len = strlen(s); 
    for(i = 0,j = 0;i<len;i++) 
	{    
		temp = (a*(s[i]-97)+b)%26; 
		if(temp<0) temp += 26;  
		s1[i]= temp +97; 
	} 
	s1[i]='\0'; 
	cout<<"the changed string is:"<<endl; 
	cout<<s1<<endl; 
} 
 
void uncode(int a,int b) 
{ 
	int  len=0,i=0,j=0; 
    char s[1000]; 
	char s1[1000]; 
	cout<<"please input the string"<<endl; 
	cout<<"(warning the length not more than 1000 and must be small letters)"<<endl; 
    cin>>s; 
	len = strlen(s); 
    for(i = 0,j = 0;i<len;i++) 
		s1[i]=(a*(s[i]-97)+b)%26+97; 
	s1[i]='\0'; 
	cout<<"the changed string is:"<<endl; 
	cout<<s1<<endl; 
} 
 
int getUncode(int a) 
{ 
   int i,b; 
   for(i = 1; i<a;i++) 
   { 
     b = ( 26*i + 1 )/a; 
     if(( 26*i + 1 )%a==0) 
		 return b; 
   } 
}

⌨️ 快捷键说明

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