Unofficial LSL Reference

[[articles:base64]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

articles:base64 [2015-01-31 21:01 SLT]
sei info on padding
articles:base64 [2015-07-10 04:15 SLT] (current)
sei Add nav
Line 1: Line 1:
 +$nav
 =====Base64===== =====Base64=====
  
-Base64 is one way of storing sequences of characters in strings, that represent a sequence of bytes.+Base64 is one way of storing sequences of characters in strings, that represent a sequence of bytes. It's similar to hexadecimal,​ which provides 4 bits per character, and thus it needs 2 characters per byte. Base64 is more compact: with base64 only 4 characters are needed for every 3 bytes, or ~1.333 characters per byte on average.
  
 The representation uses the characters A to Z, a to z, 0 to 9, the plus sign (+) and the slash (/), in that order. Each character represents a 6-bit binary number from ''​000000''​ to ''​111111'',​ which is part of a byte. So A represents ''​000000'',​ B ''​000001'',​ ..., Z ''​011001'',​ a ''​011010'',​ ..., z ''​110011'',​ 0 ''​110100'',​ ..., 9 ''​111101'',​ + represents ''​111110'',​ and finally / represents ''​111111''​. The representation uses the characters A to Z, a to z, 0 to 9, the plus sign (+) and the slash (/), in that order. Each character represents a 6-bit binary number from ''​000000''​ to ''​111111'',​ which is part of a byte. So A represents ''​000000'',​ B ''​000001'',​ ..., Z ''​011001'',​ a ''​011010'',​ ..., z ''​110011'',​ 0 ''​110100'',​ ..., 9 ''​111101'',​ + represents ''​111110'',​ and finally / represents ''​111111''​.
Line 7: Line 8:
 These sequences of six bits are parts of bytes. The first character represents the leftmost 6 bits of the first byte; the second character represents the rightmost two bits of the first byte, plus the leftmost 4 bits of the second byte; the third character represents the rightmost 4 bits of the second byte, plus the leftmost two bits of the third byte; the fourth character represents the rightmost 6 bits of the third byte, and then the cycle repeats. These sequences of six bits are parts of bytes. The first character represents the leftmost 6 bits of the first byte; the second character represents the rightmost two bits of the first byte, plus the leftmost 4 bits of the second byte; the third character represents the rightmost 4 bits of the second byte, plus the leftmost two bits of the third byte; the fourth character represents the rightmost 6 bits of the third byte, and then the cycle repeats.
  
-So, every four Base64 characters represent three bytes. Let's see for example what sequence of bytes does the string "​z9+A"​ represent. z is ''​110011'',​ 9 is ''​111101'',​ + is ''​111110''​ and A is '​000000''​ so the bit string is:+So, every four Base64 characters represent three bytes. Let's see for example what sequence of bytes does the string "​z9+A"​ represent. z is ''​110011'',​ 9 is ''​111101'',​ + is ''​111110''​ and A is ''​000000''​ so the bit string is:
  
     110011 111101 111110 000000     110011 111101 111110 000000
Line 16: Line 17:
  
 which is the byte sequence 0xCF, 0xDF, 0x80. Therefore we can say that the Base64 string "​z9+A"​ represents the byte sequence 0xCF 0xDF 0x80. which is the byte sequence 0xCF, 0xDF, 0x80. Therefore we can say that the Base64 string "​z9+A"​ represents the byte sequence 0xCF 0xDF 0x80.
- 
-It's more compact than hexadecimal,​ which provides 4 bits per character, and thus it needs 2 characters per byte. With base64 only 4 characters are needed for every 3 bytes, or ~1.333 characters per byte on average. 
  
 The standard that specifies how Base64 is encoded requires that Base64 strings have a number of characters that is a multiple of four. When it is not, equal signs (=) are appended until it is. LSL is permissive with respect to padding, and accepts unpadded strings. When it generates Base64 strings, it generates them with padding. The standard that specifies how Base64 is encoded requires that Base64 strings have a number of characters that is a multiple of four. When it is not, equal signs (=) are appended until it is. LSL is permissive with respect to padding, and accepts unpadded strings. When it generates Base64 strings, it generates them with padding.