tanszek:oktatas:techcomm:base64_coding
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tanszek:oktatas:techcomm:base64_coding [2024/10/07 11:25] – created knehez | tanszek:oktatas:techcomm:base64_coding [2024/10/07 11:29] (current) – knehez | ||
|---|---|---|---|
| Line 44: | Line 44: | ||
| We split it into two 6-bit groups: | We split it into two 6-bit groups: | ||
| - | ``` | + | '' |
| - | 001100 , 110011 | + | |
| - | ``` | + | |
| These groups correspond to decimal values **12** and **51**. Using the Base-64 table: | These groups correspond to decimal values **12** and **51**. Using the Base-64 table: | ||
| - | - 12 → ' | + | * 12 → ' |
| - | - 51 → ' | + | |
| Thus, the Base-64 encoding of `001100110011` is **Mz**. | Thus, the Base-64 encoding of `001100110011` is **Mz**. | ||
| - | ### Padding and Handling Non-Multiples of 3 Bytes | + | === Padding and Handling Non-Multiples of 3 Bytes === |
| Base-64 encoding operates on blocks of 3 bytes (24 bits). If the input data isn’t divisible by 3, padding is added to complete the block. This padding is represented by the **' | Base-64 encoding operates on blocks of 3 bytes (24 bits). If the input data isn’t divisible by 3, padding is added to complete the block. This padding is represented by the **' | ||
| - | #### Example 1: Encoding the byte `00000001` | + | ===Example 1 === |
| + | |||
| + | Encoding the byte `00000001` | ||
| - | 1. We first extend it to 3 bytes by adding two zero bytes: | + | 1. We first extend it to 3 bytes by adding two zero bytes: |
| - | 2. Split this into 6-bit groups: `000000 010000 000000 000000`. | + | |
| - | 3. The result is `AQ==`. | + | |
| - | #### Example | + | 2. Split this into 6-bit groups: '' |
| - | 1. Extend to 3 bytes: `00000010 00000001 00000000`. | + | 3. The result is '' |
| - | 2. Split into 6-bit groups: `000000 100000 000100 000000`. | + | |
| - | 3. The result is `AgE=`. | + | |
| - | ### Base-64 Decoding | + | === Example 2: === |
| + | |||
| + | Encoding the bytes '' | ||
| + | |||
| + | 1. Extend to 3 bytes: '' | ||
| + | |||
| + | 2. Split into 6-bit groups: '' | ||
| + | |||
| + | 3. The result is '' | ||
| + | |||
| + | === Base-64 Decoding | ||
| Decoding Base-64 involves reversing the process, converting each Base-64 character back into its 6-bit binary equivalent. The binary groups are then combined to form the original data. The number of **' | Decoding Base-64 involves reversing the process, converting each Base-64 character back into its 6-bit binary equivalent. The binary groups are then combined to form the original data. The number of **' | ||
| - | ### Special Considerations | + | === Special Considerations=== |
| - | - Base-64 encoded data can contain **line break characters** to help manage long strings. These line breaks (or any other non-Base-64 characters) should be ignored during decoding. | + | * Base-64 encoded data can contain **line break characters** to help manage long strings. These line breaks (or any other non-Base-64 characters) should be ignored during decoding. |
| - | - One major advantage of Base-64 encoding is that it safely encodes binary data into a **text-friendly format**, making it ideal for transmission over protocols that only support text (like email and HTTP headers). | + | |
| - | ### Real-World Application of Base-64 | + | === Real-World Application of Base-64 |
| In everyday internet use, Base-64 encoding is used in various places, such as: | In everyday internet use, Base-64 encoding is used in various places, such as: | ||
| - | - Email attachments (as shown in the MIME example). | + | |
| - | - Embedding image data in HTML or CSS files. | + | * Email attachments (as shown in the MIME example). |
| - | - Encoding sensitive data in URL query parameters to ensure safe transmission. | + | |
| + | * Embedding image data in HTML or CSS files. | ||
| + | |||
| + | * Encoding sensitive data in URL query parameters to ensure safe transmission. | ||
| For instance, in the email example above, the binary content of the attachment is encoded into Base-64 so it can be transmitted through the SMTP protocol, which only supports 7-bit ASCII characters. | For instance, in the email example above, the binary content of the attachment is encoded into Base-64 so it can be transmitted through the SMTP protocol, which only supports 7-bit ASCII characters. | ||
tanszek/oktatas/techcomm/base64_coding.1728300308.txt.gz · Last modified: 2024/10/07 11:25 by knehez
