You are not logged in.
Pages: 1
I've been tinkering around with cryptography, and looking for a way to generate a page of random numbers from /dev/random. Some quick google work turns up a couple of methods, one using hexdump and one using either od or dd.
So I took a look at the man pages and other info about these utilities to see how they were used, and they seem to me to be redundant; they seem to do the exact same thing, just with different syntax. Does anyone know more in depth how these functions work, and why I would choose to use one over the other?
Offline
Something like this?
$ od -t u1 /dev/urandom | head -n 10 | cut -d' ' -f2-
250 174 33 71 131 163 182 134 247 205 138 252 103 103 29 165
80 56 111 89 89 10 247 166 139 207 81 106 201 181 160 109
47 95 115 243 54 118 92 108 98 223 174 151 203 91 63 100
100 120 45 115 84 202 224 104 225 23 142 123 83 50 215 67
77 27 133 254 62 38 129 115 144 240 36 170 5 84 12 74
12 71 253 132 182 152 100 217 10 247 2 188 9 162 98 253
62 216 2 155 18 1 11 182 215 59 170 25 62 12 175 85
172 170 26 121 8 84 247 21 73 87 203 214 144 49 99 50
154 237 143 160 15 250 95 64 189 217 139 56 167 56 19 37
187 217 208 33 247 190 3 119 191 41 169 182 65 144 186 48
I tried it with hexdump, but it looks complicated.
Offline
$ hexdump -d -n 48 /dev/random
0000000 38030 00633 39946 58926 53927 29523 56775 06475
0000010 34335 32605 01201 49477 04577 03462 38569 27701
0000020 32932 54542 05110 38278 60108 20146 04924 00718
0000030
I found in some ways, hexdump is easier to get a direct result, so I don't know that it's more complicated. Its output is different: the first column catalogs the number of bits used, essentially. Each 5 digit number is 2 bits, so 16 bits per line (hence 0x10, 0x20, etc., can be supressed with -s)
The equivalent od command, I think, would be
$ od -t u2 -N 48 /dev/random
0000000 45388 41311 39918 56995 1742 8573 40478 31762
0000020 27172 18537 40670 23827 62650 48597 39033 43433
0000040 26550 62165 1196 9266 56362 64998 46322 62522
0000060
Only difference is the leading zeros. (The index is octal for od, I think)
I'm not so much interested in how to get the random numbers as I am why I would choose to use one utility over the other. Both are required by sysvinit and udev, so it'd be near impossible to have a (Arch) linux system without both, so what's the reason for having two different utilities that seem to do pretty much the same thing? Hopefully someone knows what the difference is.
For example, is there something you can do with od that you can't with hexdump (or vice versa)?
Last edited by beretta (2009-04-06 17:43:33)
Offline
hexdump has some nice defaults like -C
This is the first time I had heard of od actually. It seems simpler. That -t u1 looks nice. Can you do that in hexdump? With some complex -e '? ? "%_d"' maybe but I couldn't get it to work at all.
Offline
Pages: 1