Encoding.ASCII Decoder returns ? for value RRS feed

  • Question

  • Okay,

    So I don't know if this was always the behavior, i tend to expect it wasn't but maybe my memory is faulty.

    A while back I created a login structure that would cypher text the password string internally, so that I could save the "string" to a registry or XML file simply, and still be able to de-crypt the value.  HOwever, at the time, I was coming from a much lesser understanding of .Net, and was often quite frustrated at the string/char/byte delineation. 

    So, my theory was to automate a lot of processes.  pass in a string. String.ToAscii() (extension) uses Encoding.ASCII.GetEncoder, to convert the string to an array of bytes. Using a simple XOR methodology, very archaic and not very secure I know, but at the time will dissuade most cavalier users, i convert the bytes in the array to new values.  I then take those bytes and run them through a Encoding.ASCII.GetDecoder() to get the "characters" from those bytes and turn them into a string. 

    Now, I remember testing this when I wrote (a few years ago) and never had a problem.  But now, I've gone back to this code and suddenly had a use for it, and instead of reinventing my own wheel, i decided to use my login structure, and this process (most specifically the ASCII Decoder) is turning the "byte array" into a string of question marks "????????".  The ? (ascii 192) is not character 205.  but the decoder is mucking up the works here.  Why is this?  When did the ASCII decoder not simply take a byte (from 0 to 255) and turn it into a character value?

    This is most disconcerting and I would like to have the Encoder/Decoder work directly.  I woudl understand if I was using UTF 8 or UTF16 or something, but this is ASCII.  there are 255 characters in the ASCII table, and I can just as simply use CHR(#) to get the character representation of the value, so why doesn't the Encoding.Decoder for the ASCIIEncoding do the same?


    Jaeden "Sifo Dyas" al'Raec Ruiner

    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

    Thursday, February 9, 2012 11:39 AM


  • Your assumption ascii is 8 bits is wrong, standard ascii is only 7 bits (0-127), any value you feed the AsciiEncoder class over 127 will return a '?' since it's not defined in the standard.
    • Proposed as answer by Jared Van Leeuwen Tuesday, February 14, 2012 12:07 AM
    • Marked as answer by JaedenRuiner Tuesday, February 14, 2012 8:10 PM
    Thursday, February 9, 2012 10:01 PM