by Marcus Rogers [marcuswrogers at hotmail dot com] posted on 2004/07/23 |
|
I'm using the C# SSL class to connect to a credit card processor, and everything works great for the provider's primary system. However, their backup system only works with even parity transmissions, whereas their main system works with even parity or no parity. Is even parity supported? |
by Marcus Rogers [marcuswrogers at hotmail dot com] posted on 2004/07/26 |
|
I figured this out and thought I'd post the solution for anyone else. Ends up it doesn't have anything to do with SSL or this object. The socket is used to send ASCII characters. ASCII chars are 7 bits, but the socket, of course, sends bytes (8 bits), so it simply sets the first bit of the 8 to 0 and then appends the 7 bits of the ASCII character. To acheive parity (positive parity, to be precise), examine each ASCII character and if its binary representation has an odd number of positive bits (1's), change that first bit from a 0 to a 1. For example, the character "B" is ASCII character # 66, and is represented in binary as 100 0010. Since it has an even number (2) of positive bits, it gets prepended with a 0 to become 0100 0010. On the other hand, the character "C" is ASCII character # 67, and is represented in binary as 100 0011. It has an odd number (3) positive bits, so it needs to be prepended with a 1 to become 1100 0011. Interestingly enough, if you use .NET's decoder to decode a parity corrected byte array, it will handle the parity bits without a problem and spit out the correct translation. But if you use the encoder, it only gives you the non-parity output. There is no option to add parity. |