0

I am trying to decode a base64 string but the result contains some invalid characters.

The string is

decodeString=`bWFpbi5jOiBJbiBmdW5jdGlvbiDigJhtYWlu4oCZOgptYWluLmM6NToyMzog
              ZXJyb3I6IGV4cGVjdGVkIOKAmDvigJkgYmVmb3JlIOKAmH3igJkgdG9rZW4K
              ICAgIDUgfCBwcmludGYoIkhlbGxvIFdvcmxkISIpCiAgICAgIHwgICAgICAg
              ICAgICAgICAgICAgICAgIF4KICAgICAgfCAgICAgICAgICAgICAgICAgICAg
              ICAgOwogICAgNiB8IAogICAgNyB8IH0KICAgICAgfCB+ICAgICAgICAgICAg
              ICAgICAgICAgIAo=`
console.log(atob(decodeString));

The output that I am getting is:

main.c: In function ‘main’:

main.c:5:23: error: expected ‘;’ before ‘}’ token

5 | printf("Hello World!")
  |                       ^
  |                       ;
6 | 
7 | }
  | ~                      

The decoded string is a compiler output. Everything expect " ' "(single quotes) are printing just fine. Please help

3limin4t0r
  • 19,353
  • 2
  • 31
  • 52
Rishav
  • 49
  • 9
  • What are you trying to do inside the function which is decoding this string? Moreover, how is this relevant to reactjs, please use correct tags for better reachability. – VIshal Jain Nov 01 '20 at 06:49
  • you can check your decoded result from here https://www.base64decode.org/ – Sifat Haque Nov 01 '20 at 06:50
  • I am designing a compiler in react js. I am using the judge0 api which sends compiler output in base64 encoded string. I simplified the question by just pasting a specific string else the result always gives the single quotes as an unreadable character – Rishav Nov 01 '20 at 06:51
  • @SifatHaque yeah i checked it is giving correct result – Rishav Nov 01 '20 at 06:52
  • @Rishav - [a lot of dupes](https://www.google.com/search?q=atob+%C3%A2%C2%80) are found when you just search for atob and †– mplungjan Nov 01 '20 at 07:04
  • From the dupe I posted: `const b64DecodeUnicode = str => decodeURIComponent(atob(str).split('').map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')); ` – mplungjan Nov 01 '20 at 07:09

0 Answers0