某公司数据库密码规定为5位组成的字符串,存储之前,需要将其加密,加密算法为:依次将每个字符依次将每个字符的ASC码值乘以2,再加上10,若计算到的新字符的值等于128,则继续将其除以3,否则不进行除法运算。最后将该得到的新字符串中所有字符前后互换(第一位和最后一位,第二位和倒数第二位交换,依次交换),编程求字符串“abcde”加密后的字符串。
void Encryption(char *str)
{
vector<int> pStr(str,str+strlen(str));
vector<int>::reverse_iterator it = pStr.rbegin();
for(;it!=pStr.rend();it++)
{
*it=(*it)*2+10;
if(*it>128)
*it /=3;
}
copy(pStr.rbegin(),pStr.rend(),str);
}
int main()
{
char s[6]="abcde";
cout<<s<<endl;
Encryption(s);
cout<<s;
return 0;
}