-2

My problem is fairly simple. See the piece of code here:

fprintf(fpOut, "%01X",ciphertext[s] ^ test[0]);
fprintf(fpOut, "%01X",ciphertext[s+1] ^ test[1]);
//the array test[] is a previously defined array containing characters, so is ciphertext[]

if I run the code above, I print into the file a sequence of hexadecimal characters (1AB289DF...) However, if I try to print on the screen, I get gibberish. All I am asking for is a way to save those characters I am able to print into the file in order to use them later. I do not want to save them all into the file and then reopen it and read them again. Any ideas?

XenonDragon
  • 13
  • 2
  • 9
  • care to show how you print it to the screen ? there is a difference between what's stored in memory, which are nothing but buts like 01001001001, and how you want them to appear on your screen – qdii Nov 21 '14 at 22:25
  • 1
    So you take a char, and xor it with another char. These chars are 8 bit no's 0-255 represented in by 2 hex chars 00-ff. You write "%01X" which will display ascii codes 0->15 with 1 didgit, and all others with two digits. When you print you need to read two hex digits and convert them back into ascii for display. For this reason, I would also use "%02X" instead, though ascii 0-15 is probably not a prob. – Chris Nov 21 '14 at 22:45

1 Answers1

0

From How to display hexadecimal numbers in C?, try using printf("%08X", hex_example)

This is more of a formatting issue, if you are still unsure how to do this provide more code on how you would go about outputting the hex values to the terminal.

  • (0) pads the numbers to the left of your hex value.
  • (08) gives the width of your values (i.e. how long your display will be)
  • (X) identifier for hexadecimal values.
Community
  • 1
  • 1
KillaBytes
  • 447
  • 3
  • 10