Write your question here.
Setting value for id.d[0],id.d[1]....id.d[7] via sscanf,
since its union other member which is a struct (len and s[]) should have garbage value but in below program it is set correctly.
Need to understand how id.p.len and id.p.s[] are correctly set
What is the "correct" value? When I run this (after fixing compilation errors and warnings) I get
Value of id.p.s: XWJGBNWJ470
on a little-endian host and
Value of id.p.s: SMARTNA_DEV
on a big-endian host.
I'm guessing that the big-endian version is what you're looking for. It works because the compiler just happened to lay out the union in the way that the code expects.
The important thing to realize is that it works by accident. This isn't portable code and it relies on undefined behavior.
Converting the numbers to hex you get 0b1e0f15 0f16000c 0e190848.
If the union is laid out with p.len occupying the same location as the first byte of d[0], then that value is 0xb (11 decimal), which is what it ends up being on a big-endian machine .
Sorry for asking dump question aagain
To what I understand is
-union id in above example will have size 32 bytes (256 bits).
-when we assign id.d[0] = 186519317
then underlying storage will be binary as shown below
001100010011100000110110001101010011000100111001001100110011000100110111(rest 0 ahead to fill upto 256)
-Since its union if I try to access variable len it shd take first 1 byte (8 bit) which is 00110001
-00110001 is 49 but in above eg getting 11 (which is correct :) )
Any reason to consider hexadecimal format ? also is my above understanding incorrect.
Thanks a lot for your help and sorry if my question is to dumb
Actully i converted online website will check again ,
I tried to make reverse of the program meaning from text SMARTNA_DEV want to get the string P i hardcoded.
But xor part could not fig out how we can get.
Need help how we can get the original string back from the final string
Below is the decryption part code I wrote but since don't know how to put hexadecimal value to a variable , I am unot getting original string back