-6

How do I create a file that has X bytes of 0, Y bytes of the number 7 (i.e. 0x07 in hex, 00000111 in binary), Z random bytes and T bytes of the number 25(0x19 in hex, 00011001 in binary). Finally, this file should be of size X+Y+Z+T bytes.

5
  • 1
    You should clarify something in your question: when you say 'bytes of 25' or 'bytes of 7' you're being ambiguous. Does it mean 0x77 and 0x25 or 0x37 and 0x3235, respectively?
    – Azendale
    Dec 7, 2011 at 18:22
  • a byte of 7 is formed by 00000111, where 0 and 1 are bits
    – johnny
    Dec 7, 2011 at 18:38
  • So, we're talking about the number 7, written in hex as 0x07 and the number 25 which would be 00011001 in binary which would be 0x19 in hex. You should probably edit your question and put that in it.
    – Azendale
    Dec 7, 2011 at 18:46
  • The numbers are in binary. For example, if I want a file of a total size of 2 bytes, with the first byte 0 and the second one 7 it should look like 00000000 00000111.
    – johnny
    Dec 7, 2011 at 18:56
  • 3
    This seems like a homework question
    – tgm4883
    Dec 7, 2011 at 20:05

1 Answer 1

3

Install 'ghex' from the software center.

Go to a terminal and run touch hexfile.

Open ghex, then open the 'hexfile'.

Press insert, then type the bytes you want.

Save.


You might be able to do save something like this in a file, change the varibles (as instructed), and make it executable (chmod +x filename), then run it ./filename.

#!/bin/bash
#(C) 2011 Erik B. Andersen This script is licensed under the latest non-draft
#version of the AGPL as published by the Free Software Foundation (currently 
#at http://www.gnu.org/licenses/) .
# Set the following four variables.
X=
Y=
Z=
T=
#######Don't need to change anything past here.
y=0
t=0
head -c $X /dev/zero >> structurefile
while [ $y -lt $Y ]; do echo -n -e "\x07"; y=$(($y+1)); done >> structurefile
head -c $Z /dev/urandom >> structurefile
while [ $t -lt $T ]; do echo -n -e "\x19"; t=$(($t+1)); done >> structurefile
6
  • is there any way to do it with "dd"?
    – johnny
    Dec 7, 2011 at 18:38
  • Maybe. But I would use something like "head -c" instead and using the shell's append operator ('>>'). The problem is reading the data from somewhere. You can get zeros from /dev/zero and random data from /dev/urandom (or /dev/random if it needs to be crypto strength random). I'm not sure where you would repeatedly copy 0x19 and 0x07 from, though.
    – Azendale
    Dec 7, 2011 at 18:51
  • For 0x07: echo -en "\x07"
    – Caesium
    Dec 7, 2011 at 19:06
  • @johnny I'm assuming you're wanting dd because you want the command line way to do it. So does my answer work for you now?
    – Azendale
    Dec 8, 2011 at 16:58
  • yes I want to use the command line, but there is a problem. For variable Y nothing is added to the file and for variable T it enters infinite cycling.
    – johnny
    Dec 8, 2011 at 20:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .