You should probably open the file using the "rb" and "wb" modes. This opens the file in binary format, as opposed to text format. In text format, certain "character" sequences are converted, while other single "characters", such as 0x1a (Ctrl-Z), are...