Note that there are some explanatory texts on larger screens.

plurals
  1. POInitializing an unsigned char array with hex values in C++
    primarykey
    data
    text
    <p>I would like to initialize an unsigned char array with 16 hex values. However, I don't seem to know how to properly initialize/access those values. When I try to access them as I might want to intuitively, I'm getting no value at all. </p> <p>This is my output </p> <pre><code>The program was run with the following command: 4 Please be a value! -----&gt; p Here's some plaintext </code></pre> <p>when run with the code below - </p> <pre><code>int main(int argc, char** argv) { int n; if (argc &gt; 1) { n = std::stof(argv[1]); } else { std::cerr &lt;&lt; "Not enough arguments\n"; return 1; } char buff[100]; sprintf(buff,"The program was run with the following command: %d",n); std::cout &lt;&lt; buff &lt;&lt; std::endl; unsigned char plaintext[16] = {0x0f, 0xb0, 0xc0, 0x0f, 0xa0, 0xa0, 0xa0, 0xa0, 0x00, 0x00, 0xa0, 0xa0, 0x00, 0x00, 0x00, 0x00}; unsigned char test = plaintext[1]^plaintext[2]; std::cout &lt;&lt; "Please be a value! -----&gt; " &lt;&lt; test &lt;&lt; std::endl; std::cout &lt;&lt; "Here's some plaintext " &lt;&lt; plaintext[3] &lt;&lt; std::endl; return 0; } </code></pre> <p>By way of context, this is part of a group project for school. We are ultimately trying to implement the Serpent cipher, but keep on getting tripped up by unsigned char arrays. Our project specification says that we must have two functions that take what would be Byte arrays in Java. I assume the closest relative in C++ is an unsigned char[]. Otherwise I would use vector. Elsewhere in the code I've implemented a setKey function which takes an unsigned char array, packs its values into 4 long long ints (the key needs to be 256 bits) and performs various bit-shifting and xor operations on those ints to generate the keys necessary for the cryptographic algorithm. Hope that's enough background on what I'm looking to do. I'm guessing I'm just overlooking some basic C++ functionality here. Thanks for any and all help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload