0

I have a binary string of the form

"000000110111010100110110001010001010110111010110010001111111101010000001"  # for example

to encode to base 64, i use pack and encode_base64

my $base64 = encode_base64 pack 'B*', $binaryString;

Which I would then get.

A3U2KK3WR/qB

I would like to revert back to the original binary form of the string, I tried

my $binString = decode_base64 $base64;  

but that returns

u6(��G��

How can i revert back the original binary string?

2
  • Looks like your problem needs some unpacking. Commented Sep 30, 2014 at 19:59
  • Live demo of the unpacked result. Commented Sep 30, 2014 at 20:39

1 Answer 1

3

The inverse of

my $base64 = encode_base64(pack('B*', $binary));

is

my $binary = unpack('B*', decode_base64($base64));
Sign up to request clarification or add additional context in comments.

2 Comments

Note: I assume length($binary) is always evenly divisible by 8. If its not, there isn't enough information in $base64 to recreate the original string.
thank you, works perfectly, feeling pretty dump that i forgot to unpack

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.