这是我程序的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;
}


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

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

当nk = 4时,则x = nk * 4 = 16
但它显示10。

最佳答案

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


这将使默认输出格式十六进制为任何其他输出

07-25 20:30