?? 古典密碼學.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> > <a href="http://www.pudn.com/downloads62/sourcecode/crypt/detail217974.html">fangshe.rar</a> > 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 + -