Back to Bobby's CueCat Home Page

 
Exactly how does the Modified BASE64 encoding work?

For me to go into detail one must know how the code works.   I have written out a step by step decoding method of how to decode the encoded data given out by the CueCat.  This method can be used to decode any part of the data given off.   Even the S/N and Type sections of code will return good data once they are processed through this procedure.

Ok let's get started with some data.   Let me scan a barcode that I use for my PineWood Racer software.  The data given off by the CueCat is:
 .C3nZC3nZC3nXC3nZCxvYDNn6.ahb6.fbmxChO.  

Knowing that the last part of this data is what we are looking for, we will take it and decode it.

I will take this string of characters: fbmxChO

In the example of decoding this string of letters I will refer to the "String Reference".  This string reference is the following:  (I will place numbers under it to help in finding the number that corresponds to the letter)

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-
1234567890123456789012345678901234567890123456789012345678901234
         1         2         3         4         5         6
 
1. Take first character and find it's position in the Reference String. f  => 6
2. Subtract 1 from step 1. 6-1 = 5
3. Shift this number left 2 places.   So 5 in binary is "00000101" shift left two places is "00010100" convert to decimal is "20". Shift 5 left 2  = 20
4. Take the second character and find it's position in the Reference String. b => 2
5. Subtract 1 from step 4. 2-1 = 1
6. Shift this number right 4 places.  So 1 in binary is "00000001" shift right four places is "00000000" convert to decimal is "0" Shift 1 right 4 => 0
7. Do the binary OR operation to numbers generated in steps 3 and 6.  That would be "20 OR 0" and in binary "00011000 or 00000000" that would be "00011000" convert to decimal is "20". 20 or 0 => 20
8. Take step 7 and XOR it with 3.  That would be "20 XOR 3" and in binary "00010100 xor 00000011" that would equal 23 or binary "00010111" 20 xor 3 => 23
9. Take step 8 and add 64 to it. 23 + 64 = 87
10. IF step 9 is larger then 128 then subtract 128. 87
11. Then using a standard ASCII chart look up character for step 10.  This will give you the first letter.  So the 87st character in the ASCII chart is: W   87 => W
12. If you don't have a third letter then quit.
13. Take the number in step 5 and shift it left 4 places.  That would be "00000001" shifting left four places would be "00010000" shift 1 left 4 = 16
14. Take the third character and find it's position in the Reference String. m => 13
15. Subtract 1 from step 14. 13 - 1 = 12
16. Take the number in step 15 and shift it to the Right 2 places.  In binary that would be "00001100" shift right 2 places "00000011" that would be 3 in decimal. shift 12 right 2 = 3
17. Use the Bit Operation OR on steps 13 and 16.  That would be "16 or 3" in binary "00010000 or 00000011" to make "00010011" which would be 19 in decimal. 16 or 3 = 19
18. Now take step 17 and XOR it with 3.  So that's "19 xor 3" and in binary "00010011 xor 00000011" to come out with "00010000" or 16 decimal. 19 xor 3 = 16
19. Now take step 18 and  add 64 to it. 16 + 64 = 80
20. If step 19 is larger then 128 then subtract 128 80
21. Take the number in step 20 and look it up on an ASCII chart to find it's character.  This will be the second letter. 80 => P
22. If you don't have a forth letter then quit.
23. Take the number in Step 15 and shift it left 6 places.  That would be "00001100" shift left 6 places "00000000" in decimal 0. shift 12 left 6 = 0
24. Take the forth character and find it's position in the Reference String. x => 24
25. Subtract one from step 24. 24 -1 = 23
26. Use the Bit Operation OR on steps 23 and 25.  That would be "0 or 23" and in binary "00010111 or 00000000" which will get "00010111" or 23 in decimal. 0 or 23 = 23
27. Take step 26 and XOR it with 3.  That would be "23 xor 3" and in Binary "00010111 xor 00000011" to come up with "00010100" in decimal that would be 20  23 xor 3 = 20
28. Add 64 to to step 27. 20 + 64 = 84
29. Look up the number in step 28 on an ASCII chart to get your third character. 84 => T

Once you have finished you first four characters.  You would then repeat with the next four characters until you finish.

Your final answer should be: WPT39

I hope that this helps out fellow programmers in planning how to add support for the CueCat in their programs.

 

The previous directions was last updated on April 30, 2005 after finding some typing errors.  If you have tried and failed at decoding with the directions I gave please try again!  And feel free to E-Mail me with any problems!

 

Digital:Convergence, :C, :CRQ, :CueCat, Slant Code, the :CueCat reader and 
"Engineering Your Digital Future"  are trademarks of Digital:Convergence.

RadioShack and RadioShack.com are trademarks of RadioShack Corporation