測試輸出結果顯示在代碼的後面。有些題目是不需要解密的。我會在改進後把它們貼在我的空間裏。
附言
四樓anon_的翻譯太差了...不會是汽巴貼的吧?
我測試了五樓nekitarc的課,結果正確,思路不清晰,公式看著頭疼...並且對參數值區間沒有限制。
完整代碼:
# include & lt字符串& gt
# include & ltiostream & gt
使用命名空間std
t循環循環分類{
公共:
靜態字符串加密(int firstSize,int firstRotate,int secondRotate,string message);
};
string twrotationcypher::encrypt(int first size,int firstRotate,int secondRotate,string message)
{
firstSize % = 26
firstRotate % = firstSize
second rotate % = 25-first size+1;
字符串結果=消息;
int len = message . length();
/*
for(int j = 0;j & ltlenj++)
result . at(I)= to lower(result . at(I))。
*/
for(int I = 0;我& ltleni++)
{
int c = message . at(I);
if(c & gt;= ' a ' & amp& ampc & lt= 'z' ) //是小寫字母
{
if(c-' a '-first size+1 & lt;= 0 ) //在第壹組
{
c+= first rotate;
if(c-' a ' & gt;= first size)c-= first size;
} else { //在第二組中
c+= second rotate;
if(c & gt;z’)c-=(26-first size);
}
}
result . at(I)= c;
}
返回結果;
}
void main()
{
cout & lt& lttwrotationcypher::encrypt(6,3,4," abcdef ")& lt;& ltendl
cout & lt& lttwrotationcypher::encrypt(6,3,4," ghijklmnopqrstuvwxyz ")& lt;& ltendl
cout & lt& lttwrotationcypher::encrypt(13,0,0,“這個字符串根本不會改變”)& lt& ltendl
//返回:“這個字符串根本不會改變”
cout & lt& lttwrotationcypher::encrypt(13,7,0,“只有這個字符串中的字母a到m發生變化”)& lt& ltendl
//返回:" onfy TBL flttlls h to g cn TBCs strcna jbhnal "
cout & lt& lttwrotationcypher::encrypt(9,0,16,“j到z在這裏會變”)& lt& ltendl
//返回:" z sn y vikk chamge heqe "
cout & lt& lttwrotationcypher::encrypt(17,9,5,“敏捷的棕色狐貍跳過了懶狗”)& lt& ltendl
//返回:" yqn izalc kwgsf ogt bzehnm grnw yqn djvu mgp "
cout & lt& lttwrotationcypher::encrypt(3,1,2,“小心奇怪的間距”)& lt& ltendl
//返回:" ybvaj qwv hqt uvtbpig urbakpi "
}
輸出結果:
defabc
klmnopqrstuvwxyzghij
這個字符串根本不會改變
onfy TBL flttrs h to g cn TBCs str CNA jbnal
z sn y vikk chamge heqe
yqn iz ALC kwgsf ogt bzehnm grnw yqn djvu mgp
ybvaj qwv hqt uvtbpig urbakpi
按任意鍵繼續