0

I wish to read a jar in binary mode and write the binary as string(encoded if need be) to a file. This string would be included in code to be read and converted back into binary and written as a jar file.

I'm trying to replicate what get-pip.py has done to distribute pip.

What would be the best way to do this in C?

Sam Thomas
  • 647
  • 7
  • 25
  • 1
    perhaps you should investigate base64: https://stackoverflow.com/q/342409/1212725 – bruceg May 23 '18 at 23:13
  • Indeed. Base64 is the standard way to encode arbitrary binary data as a sequence of printable characters. – Eugene Sh. May 24 '18 at 00:51
  • @bruceg thanks for the link, there is an answer there that compares many implementations and shows the best encoding and the best decoding implementation. Can I use the best of both or do I have to stick a complete implementation? – Sam Thomas May 24 '18 at 06:36
  • @SamThomas base64 is a standard. you can use the encoder from one implementation, and the decoder from another. Back in the dark ages when I had to do it myself, I always used a simple table driven approach. – bruceg May 24 '18 at 19:32
  • @bruceg Cool Thanks :D – Sam Thomas May 24 '18 at 19:40
  • @bruceg Can you submit an answer? I'll accept it and lets close this :D – Sam Thomas Jun 04 '18 at 20:42
  • 1
    @SamThomas here's the consolidated information in the answer below. Hope it helps! – bruceg Jun 04 '18 at 21:08

1 Answers1

1

You can use base64 encoding for this. Base64 is a standard, and you can use the encoder from one implementation, and the decoder from another, and you'd get back the original string on the other side. The typical straightforward implementation is a table driven one, as in this answer here: https://stackoverflow.com/a/6782480/1212725

bruceg
  • 2,433
  • 1
  • 22
  • 29