The problem is almost certainly the final part of your method:
return new ASCIIEncoding().GetString(ret);
Converting a byte array to a string using any form of encoding is likely to give you a string that can't be converted back to the original array of bytes.
Try it: instead of returning a string, use your code to generate the string, then use your complementary code to immediately generate a "unstringed" byte array from that.
Then compare each byte in the original with it's equivalent in the "regenerated" version. One single bit different will be enough to scupper the whole operation.