Decode-译码
//Decode-译码 #include<iostream> #include<cstring> #include<cstdlib> #include<cctype> using namespace std; void process(string str,char ch[],int key); int main() { string str; char ch[100]; cout<<"Input the cipher:\n"; cin>>str; for(int i = 0;i < 100;i++) { process(str,ch,i); cout<<"Key: "<<i<<" Decoded message:"<<ch<<endl; } return 0; } void process(string str,char ch[],int key) { for(int i = 0;i < str.length();i++) { if((str[i] - key) < 32) ch[i] = static_cast<char>(static_cast<int>(str[i]) - 32 + 127 -key); else ch[i] = static_cast<char>(static_cast<int>(str[i]) - key); } }
结果:
Input the cipher: Ro$ Key: 0 Decoded message:Ro$ Key: 1 Decoded message:Qn# Key: 2 Decoded message:Pm" Key: 3 Decoded message:Ol! Key: 4 Decoded message:Nk Key: 5 Decoded message:Mj~ Key: 6 Decoded message:Li} Key: 7 Decoded message:Kh| Key: 8 Decoded message:Jg{ Key: 9 Decoded message:Ifz Key: 10 Decoded message:Hey Key: 11 Decoded message:Gdx Key: 12 Decoded message:Fcw Key: 13 Decoded message:Ebv Key: 14 Decoded message:Dau Key: 15 Decoded message:C`t Key: 16 Decoded message:B_s Key: 17 Decoded message:A^r Key: 18 Decoded message:@]q Key: 19 Decoded message:?\p Key: 20 Decoded message:>[o Key: 21 Decoded message:=Zn Key: 22 Decoded message:<Ym Key: 23 Decoded message:;Xl Key: 24 Decoded message::Wk Key: 25 Decoded message:9Vj Key: 26 Decoded message:8Ui Key: 27 Decoded message:7Th Key: 28 Decoded message:6Sg Key: 29 Decoded message:5Rf Key: 30 Decoded message:4Qe Key: 31 Decoded message:3Pd Key: 32 Decoded message:2Oc Key: 33 Decoded message:1Nb Key: 34 Decoded message:0Ma Key: 35 Decoded message:/L` Key: 36 Decoded message:.K_ Key: 37 Decoded message:-J^ Key: 38 Decoded message:,I] Key: 39 Decoded message:+H\ Key: 40 Decoded message:*G[ Key: 41 Decoded message:)FZ Key: 42 Decoded message:(EY Key: 43 Decoded message:'DX Key: 44 Decoded message:&CW Key: 45 Decoded message:%BV Key: 46 Decoded message:$AU Key: 47 Decoded message:#@T Key: 48 Decoded message:"?S Key: 49 Decoded message:!>R Key: 50 Decoded message: =Q Key: 51 Decoded message:~<P Key: 52 Decoded message:};O Key: 53 Decoded message:|:N Key: 54 Decoded message:{9M Key: 55 Decoded message:z8L Key: 56 Decoded message:y7K Key: 57 Decoded message:x6J Key: 58 Decoded message:w5I Key: 59 Decoded message:v4H Key: 60 Decoded message:u3G Key: 61 Decoded message:t2F Key: 62 Decoded message:s1E Key: 63 Decoded message:r0D Key: 64 Decoded message:q/C Key: 65 Decoded message:p.B Key: 66 Decoded message:o-A Key: 67 Decoded message:n,@ Key: 68 Decoded message:m+? Key: 69 Decoded message:l*> Key: 70 Decoded message:k)= Key: 71 Decoded message:j(< Key: 72 Decoded message:i'; Key: 73 Decoded message:h&: Key: 74 Decoded message:g%9 Key: 75 Decoded message:f$8 Key: 76 Decoded message:e#7 Key: 77 Decoded message:d"6 Key: 78 Decoded message:c!5 Key: 79 Decoded message:b 4 Key: 80 Decoded message:a~3 Key: 81 Decoded message:`}2 Key: 82 Decoded message:_|1 Key: 83 Decoded message:^{0 Key: 84 Decoded message:]z/ Key: 85 Decoded message:\y. Key: 86 Decoded message:[x- Key: 87 Decoded message:Zw, Key: 88 Decoded message:Yv+ Key: 89 Decoded message:Xu* Key: 90 Decoded message:Wt) Key: 91 Decoded message:Vs( Key: 92 Decoded message:Ur' Key: 93 Decoded message:Tq& Key: 94 Decoded message:Sp% Key: 95 Decoded message:Ro$ Key: 96 Decoded message:Qn# Key: 97 Decoded message:Pm" Key: 98 Decoded message:Ol! Key: 99 Decoded message:Nk //正解:Key: 10 Decoded message:Hey
Input the cipher: :mmZ\dxZmx]Zpgy Key: 0 Decoded message::mmZ\dxZmx]Zpgy Key: 1 Decoded message:9llY[cwYlw\Yofx Key: 2 Decoded message:8kkXZbvXkv[Xnew Key: 3 Decoded message:7jjWYauWjuZWmdv Key: 4 Decoded message:6iiVX`tVitYVlcu Key: 5 Decoded message:5hhUW_sUhsXUkbt Key: 6 Decoded message:4ggTV^rTgrWTjas Key: 7 Decoded message:3ffSU]qSfqVSi`r Key: 8 Decoded message:2eeRT\pRepURh_q Key: 9 Decoded message:1ddQS[oQdoTQg^p Key: 10 Decoded message:0ccPRZnPcnSPf]o Key: 11 Decoded message:/bbOQYmObmROe\n Key: 12 Decoded message:.aaNPXlNalQNd[m Key: 13 Decoded message:-``MOWkM`kPMcZl Key: 14 Decoded message:,__LNVjL_jOLbYk Key: 15 Decoded message:+^^KMUiK^iNKaXj Key: 16 Decoded message:*]]JLThJ]hMJ`Wi Key: 17 Decoded message:)\\IKSgI\gLI_Vh Key: 18 Decoded message:([[HJRfH[fKH^Ug Key: 19 Decoded message:'ZZGIQeGZeJG]Tf Key: 20 Decoded message:&YYFHPdFYdIF\Se Key: 21 Decoded message:%XXEGOcEXcHE[Rd Key: 22 Decoded message:$WWDFNbDWbGDZQc Key: 23 Decoded message:#VVCEMaCVaFCYPb Key: 24 Decoded message:"UUBDL`BU`EBXOa Key: 25 Decoded message:!TTACK_AT_DAWN` Key: 26 Decoded message: SS@BJ^@S^C@VM_ Key: 27 Decoded message:~RR?AI]?R]B?UL^ Key: 28 Decoded message:}QQ>@H\>Q\A>TK] Key: 29 Decoded message:|PP=?G[=P[@=SJ\ Key: 30 Decoded message:{OO<>FZ<OZ?<RI[ Key: 31 Decoded message:zNN;=EY;NY>;QHZ Key: 32 Decoded message:yMM:<DX:MX=:PGY Key: 33 Decoded message:xLL9;CW9LW<9OFX Key: 34 Decoded message:wKK8:BV8KV;8NEW Key: 35 Decoded message:vJJ79AU7JU:7MDV Key: 36 Decoded message:uII68@T6IT96LCU Key: 37 Decoded message:tHH57?S5HS85KBT Key: 38 Decoded message:sGG46>R4GR74JAS Key: 39 Decoded message:rFF35=Q3FQ63I@R Key: 40 Decoded message:qEE24<P2EP52H?Q Key: 41 Decoded message:pDD13;O1DO41G>P Key: 42 Decoded message:oCC02:N0CN30F=O Key: 43 Decoded message:nBB/19M/BM2/E<N Key: 44 Decoded message:mAA.08L.AL1.D;M Key: 45 Decoded message:l@@-/7K-@K0-C:L Key: 46 Decoded message:k??,.6J,?J/,B9K Key: 47 Decoded message:j>>+-5I+>I.+A8J Key: 48 Decoded message:i==*,4H*=H-*@7I Key: 49 Decoded message:h<<)+3G)<G,)?6H Key: 50 Decoded message:g;;(*2F(;F+(>5G Key: 51 Decoded message:f::')1E':E*'=4F Key: 52 Decoded message:e99&(0D&9D)&<3E Key: 53 Decoded message:d88%'/C%8C(%;2D Key: 54 Decoded message:c77$&.B$7B'$:1C Key: 55 Decoded message:b66#%-A#6AZB Key: 56 Decoded message:a55"$,@"5@%"8/A Key: 57 Decoded message:`44!#+?!4?$!7.@ Key: 58 Decoded message:_33 "*> 3># 6-? Key: 59 Decoded message:^22~!)=~2="~5,> Key: 60 Decoded message:]11} (<}1<!}4+= Key: 61 Decoded message:\00|~';|0; |3*< Key: 62 Decoded message:[//{}&:{/:~{2); Key: 63 Decoded message:Z..z|%9z.9}z1(: Key: 64 Decoded message:Y--y{$8y-8|y0'9 Key: 65 Decoded message:X,,xz#7x,7{x/&8 Key: 66 Decoded message:W++wy"6w+6zw.%7 Key: 67 Decoded message:V**vx!5v*5yv-$6 Key: 68 Decoded message:U))uw 4u)4xu,#5 Key: 69 Decoded message:T((tv~3t(3wt+"4 Key: 70 Decoded message:S''su}2s'2vs*!3 Key: 71 Decoded message:R&&rt|1r&1ur) 2 Key: 72 Decoded message:Q%%qs{0q%0tq(~1 Key: 73 Decoded message:P$$prz/p$/sp'}0 Key: 74 Decoded message:O##oqy.o#.ro&|/ Key: 75 Decoded message:N""npx-n"-qn%{. Key: 76 Decoded message:M!!mow,m!,pm$z- Key: 77 Decoded message:L lnv+l +ol#y, Key: 78 Decoded message:K~~kmu*k~*nk"x+ Key: 79 Decoded message:J}}jlt)j})mj!w* Key: 80 Decoded message:I||iks(i|(li v) Key: 81 Decoded message:H{{hjr'h{'kh~u( Key: 82 Decoded message:Gzzgiq&gz&jg}t' Key: 83 Decoded message:Fyyfhp%fy%if|s& Key: 84 Decoded message:Exxego$ex$he{r% Key: 85 Decoded message:Dwwdfn#dw#gdzq$ Key: 86 Decoded message:Cvvcem"cv"fcyp# Key: 87 Decoded message:Buubdl!bu!ebxo" Key: 88 Decoded message:Attack at dawn! Key: 89 Decoded message:@ss`bj~`s~c`vm Key: 90 Decoded message:?rr_ai}_r}b_ul~ Key: 91 Decoded message:>qq^`h|^q|a^tk} Key: 92 Decoded message:=pp]_g{]p{`]sj| Key: 93 Decoded message:<oo\^fz\oz_\ri{ Key: 94 Decoded message:;nn[]ey[ny^[qhz Key: 95 Decoded message::mmZ\dxZmx]Zpgy Key: 96 Decoded message:9llY[cwYlw\Yofx Key: 97 Decoded message:8kkXZbvXkv[Xnew Key: 98 Decoded message:7jjWYauWjuZWmdv Key: 99 Decoded message:6iiVX`tVitYVlcu //正解:Key: 88 Decoded message:Attack at dawn!