📄 fangshe.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 + -