//#include <afxcoll.h>
//#include<algorithm>
#include <windows.h>
#include<string>
using namespace std;
void main()
{
int i=0,key[7]={4,9,6,2,8,7,3};
char ch;
string pass,text;
cout<<"請輸入明文:"<<endl;
//----------------------加密過程
for(ch;((ch=cin.get())!='\n');)
{
ch=ch+key[i++];
if(i>6||ch=='\n')
i=0;
if(ch>122||ch<32)
ch=ch%122+32;
pass=pass+ch;
}
cout<<"密文是:\n"<<pass<<endl;
//----------------------解密過程
char *strs=new char[pass.length()];//將字符串轉換為字符數組
strs[pass.length()]='\0';
pass.copy(strs,pass.length(),0);
i=0;
for(int j=0;j<pass.length();j++)
{
ch=strs[j];
ch-=key[i++];
if(i>6||ch=='\n')
i=0;
if(ch<32) // 由於妳的加密算法並不是壹壹對應,即不壹定可逆,需要擴展
{ ch=ch-32;
ch=ch+122;
}
text=text+ch;
}
cout<<"解密後是:\n"<<text<<endl;
delete[]strs;
}