用c++打印的多路复用值错误

Wrong mltiplication value printed in c++

本文关键字:复用 错误 多路 c++ 打印      更新时间:2023-10-16

这是我的程序的main():-只是试着调试它。

int main()
{
    cout<<"in main()";
    int i,x;
    while(nr!=128 && nr!=192 && nr!=256)
    {
        //cout<<"Enter the lenghth of the key(128,192 or 256 only) : ";
        //cin>>nr;
    nr=128;
    }
    cout<<"after while when the value of nr is : "<<nr;
    nk = nr / 32;
    nr = nk + 6;
    cout<<endl<<"now the value of nr = "<<nr<<" and nk = "<<nk; 
    int ascii_table[26]={
            0x61,
            0x62,
            0x63,
            0x64,
            0x65,
            0x66,
            0x67,
            0x68,
            0x69,
            0x6A,
            0x6B,
            0x6C,
            0x6D,
            0x6E,
            0x6F,
            0x70,
            0x71,
            0x72,
            0x73,
            0x74,
            0x75,
            0x76,
            0x77,
            0x78,
            0x79,
            0x7A
        };
        string characters="abcdefghijklmnopqrstuvwxyz";
            //   string bla="0x";
            cout<<"Enter plain text :";
            string str="disha";
            char msg[32];
           // string message[32];
            //cin>>str;
            cout<<str;
                for(int i=0;i<str.length();i++){
                int find=0;
                while(1){
                    if(str[i]==characters[find])break;
                    find++;
                }
                    msg[i]=ascii_table[find];
            }
            for(int i=0;i<str.length();i++)
            {int h=msg[i];
                cout<<std::hex<<h<<"t";}

            char temp[32] = {0x00  ,0x01  ,0x02  ,0x03  ,0x04  ,0x05  ,0x06  ,0x07  ,0x08  ,0x09  ,0x0a  ,0x0b  ,0x0c  ,0x0d  ,0x0e  ,0x0f};
            cout<<endl;
            x=nk*4;
            cout<<"before for loop nk = "<<nk<<" and nk*4 = "<<x;
            /*for(i=0;i<x;i++)
            {
                cout<<"   inside for loop "; 
                Key[i]=temp[i];
                in[i]=msg[i];
                cout<<in[i]<<'t';
            }
            (cout<<endl<<"after for loop";
                KeyExpansion();
    // The next function call encrypts the PlainText with the Key using AES algorithm.
    Cipher();
    cout<<"nText after encryption:n";
    for(i=0;i<nb*4;i++)
    {
        cout<<out[i];
    }
    cout<<endl;*/
    return 0;
}

运行后,我得到了意外的输出这是的输出

当nr的值为:128 enter code here时,在main()中现在nr=10和nk=4的值输入纯文本:disha64 69 73 68 61
循环之前nk=4和nk*4=10

当nk=4时,则x=nk*4=16但它打印10。如何???

cout<<std::hex<<h<<"t";

这使得任何附加输出的默认输出格式为hexidecmial

该值以十六进制显示,因为您以前在代码中使用过cout<<std::hex。在此cout<<"before for loop nk = "<<nk<<" and nk*4 = "<<x;行之前添加cout<<std::dec,将输出格式更改为十进制。