Nov 16, 2014 at 6:44pm Nov 16, 2014 at 6:44pm UTC
Something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <stdint.h>
#include <stdio.h>
unsigned char * to_char_array(uint64_t in, unsigned char * buf)
{
for (int i = 0; i < 8; ++i)
buf[i] = (in >> 8*i) & 0xFFu;
return buf;
}
void output(unsigned char * key)
{
printf("Current key: %02X %02X %02X %02X %02X %02X %02X %02X \n" ,
key[0],key[1],key[2],key[3],key[4],key[5],key[6],key[7]);
}
int main()
{
const uint64_t start = 0xFFFFFFFFFFFFFF0Fu;
const uint64_t end = 0xFFFFFFFFFFFFFFFFu;
unsigned char buf[8];
//Handles overflow gracefully
for (uint64_t x = start; x != end + 1; ++x)
output(to_char_array(x, buf));
}
http://ideone.com/YJtaSa
Last edited on Nov 16, 2014 at 6:59pm Nov 16, 2014 at 6:59pm UTC
Nov 16, 2014 at 7:07pm Nov 16, 2014 at 7:07pm UTC
hi,
Thanks for reply i run the program it increments in 1 byte only output as:
10 FF FF FF FF FF FF FF
11 FF FF FF FF FF FF FF
12 FF FF FF FF FF FF FF
13 FF FF FF FF FF FF FF
14 FF FF FF FF FF FF FF
15 FF FF FF FF FF FF FF
16 FF FF FF FF FF FF FF
.
.
.
FF FF FF FF FF FF FF FF << stop here
increamenting each byte is simple byte[0]++; and byte[1]++; but this way all possible combinations cant be generate , i also tried this way but we must take the char array as whole integer.
Last edited on Nov 16, 2014 at 7:09pm Nov 16, 2014 at 7:09pm UTC
Nov 16, 2014 at 7:15pm Nov 16, 2014 at 7:15pm UTC
hi,
sorry i think i mistake in key start range in decimal key range is :
1152921504606846975 <to> 18446744073709551615
conisder these in hex :
unsigned char key_low[] = {0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
to
unsigned char key_high[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
it should increament like:
0F FF FF FF FF FF FF FF
01 00 00 00 00 00 00 00
01 00 00 00 00 00 00 01
01 00 00 00 00 00 00 02
01 00 00 00 00 00 00 03
01 00 00 00 00 00 00 04
and so on ....
or plz consider key start/low rang :
unsigned char key_low[] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
hope this avoid confusion ...
Last edited on Nov 16, 2014 at 7:22pm Nov 16, 2014 at 7:22pm UTC
Nov 16, 2014 at 7:29pm Nov 16, 2014 at 7:29pm UTC
newcslover wrote:0F FF FF FF FF FF FF FF
01 00 00 00 00 00 00 00
It should be actually
0F FF FF FF FF FF FF FF
10 00 00 00 00 00 00 00
Only problem you have now is that values are
backward outputted in big endian format.
Change output to:
1 2 3 4 5
void output(unsigned char * key)
{
printf("Current key: %02X %02X %02X %02X %02X %02X %02X %02X \n" ,
key[7],key[6],key[5],key[4],key[3],key[2],key[1],key[0]);
}
http://ideone.com/1c3Jkx
(I intentionally changes start range. Otherwise ideone would not allow program to finish, as output will be too long)
Last edited on Nov 16, 2014 at 7:30pm Nov 16, 2014 at 7:30pm UTC
Nov 16, 2014 at 8:33pm Nov 16, 2014 at 8:33pm UTC
Yes thanks it indeed solve my problem ... i will try improve it further thanks you so much brother