用c++打印的多路复用值错误
Wrong mltiplication value printed in c++
这是我的程序的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
,将输出格式更改为十进制。
相关文章:
- 使用 avcodec_decode_subtitle2 (FFmpeg) 提取(解复用)字幕
- 使用 Select 多路复用未命名的管道和其他文件描述符
- FFMPEG:具有不同持续时间的多路复用流
- 不推荐使用 AVStream.codec.time_base 作为复用器的时基提示.改为设置AVStream.time_
- 我是用错误的方式编译吗?
- 用错误的标志顺序编译后,是否删除*.cpp文件
- 输入复用的c++设计模式
- connect() 似乎用错误的命名空间作为信号的前缀
- 搜索具有多路复用的C/C 网络库
- C++IO/多路复用TCP服务器和POSIX线程
- 我可以用错误的签名调用用dlsym()导入的函数,为什么
- C++I/O多路复用服务器过早关闭连接
- 用c++打印的多路复用值错误
- 编译器弃用错误与类型定义
- 用错误的“”调用构造函数;这个“;指针.这是堆栈损坏吗
- VLC libx264流复用为FLV
- 使用select()、read()、write()进行I/O多路复用
- 每个会话连接或通过一个连接复用多个会话
- 如何使用boost::statechart在固定数量的线程上复用许多异步状态机
- 用错误检查初始化ifstream的类成员初始化器