View Single Post
Old 07-04-2008   #6
Google

 
Google's Avatar
 
Last Online: 05-30-2013
Join Date: Jan 2008
Posts: 1,788
Thanks: 10,018
Thanked 1,100 Times in 651 Posts
Groans: 1
Groaned at 6 Times in 6 Posts
Default Re: Encryption Pre-challenge - Base64

Ok, I'll answer you...
when you divide a number by 3, there are 3 possibilities, either you have 0 as remainder or 1 as remainder or 2 as remainder...
In our situation, when the remainder is 0 we don't have problem (the number was completely divisible by 3...)
We only have problem when the remainder is either 1 or 2... in these two cases we have to add padding symbol (=)...

Let's first take the case when we have 1 byte remaining...
Taking the same example ‘00000001’... This byte is the remaining byte...
We add two zero bytes... We obtain:
‘00000001’ ‘00000000’ ‘00000000’
Taking each 6 bits alone gives us:
‘000000’ ‘010000’ ‘000000’ ‘000000’
Now you have to use the calculator to know what these binary numbers represents in decimal...
‘000000’ is 0
‘010000’ is 16
The first letter in alphabet is A so ‘000000’ is A...
The letter number 17 in the alphabet is Q so ‘010000’ is Q...
Here we are taking A and Q as capital letters because of this classification:
0 … 25 -> ‘A’ … ’Z’
26 … 51 -> ‘a’ … ‘z’
52 … 61 -> ‘0’ … ‘9’
62 -> ‘+’
63 -> ‘/’
Now the last two bytes we replace them with the padding symbol (=).
So the answer will be AQ==

The second case when we have 2 bytes remaining...
Taking the same example ‘00000010’ ‘00000001’, these two bytes are the remaining bytes...
We add to them 1 zero byte... We obtain:
‘00000010’ ‘00000001’ ‘00000000’
Taking each 6 bits alone gives us:
‘000000’ ‘100000’ ‘000100’ ‘000000’
Also using the calculator we convert these binaries to decimal...
‘000000’ is 0
‘100000’ is 32
‘000100’ is 4
The first letter in alphabet is A so ‘000000’ is A...
The number 26 is a, going till 32 to get the letter g... so ‘100000’ is g...
The letter number 5 in the alphabet is E so ‘000100’ is E...
Now the last byte we replace it with the padding symbol...
So the answer will be ‘AgE=’





Google is offline   Reply With Quote
The Following User Says Thank You to Google For This Useful Post:
MARX ® (07-04-2008)