Base64 Encode and Decode - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Base64 Encode and Decode

Description:

Base64 Encode and Decode Student: Ying Hong Course: Database Security Instructor: Dr. Yang Contents Introduction Algorithm Example Issues for Considerations Other ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 20
Provided by: Hai87
Category:

less

Transcript and Presenter's Notes

Title: Base64 Encode and Decode


1
Base64 Encode and Decode
  • Student Ying Hong
  • Course Database Security
  • Instructor Dr. Yang

2
Contents
  • Introduction
  • Algorithm
  • Example
  • Issues for Considerations
  • Other Methods
  • References

3
Introduction
  • The Base64 Content-Transfer-Encoding is a method
    to encode an arbitrary sequence of octets in a
    form that is unintelligible to unauthorized
    readers.
  • Its used for MIME (Multipurpose Internet Mail
    Extensions) email and various other
    Internet-related applications.

4
Algorithm
  • Read inputs from left to right.
  • Combine 3 8-bit input data to a 24-bit input
    group.
  • Split each 24-bit input group to 4 6-bit units.
  • If last group is not 24-bit, add zero bits to
    form 4 6-bit units.
  • Translate each 6-bit input data into a single
    digit.
  • The digit is used as an index into the base64
    alphabet table.

5
Algorithm cont
  • Represent each digit by its corresponding
    alphabet in the base64 alphabet table.
  • Set the last several output characters (at most
    two) that do not represent actual input data to
    the character . That is, in the last group
    last one or two 6-bit units may be 0 you
    should either interpret it/them to A if they
    come from the plaintext, or set it/them to if
    they are added by ourselves.

6
The Base64 Alphabet Table
7
Example
  • To encode www.cl.uh.edu
  • Represent www.cl.uh.edu as its ASCII code
    number (in hexadecimal for easier to be
    represented as binary number later)
  • 77 77 77 2E 63 6C 2E 75 68 2E 65 64 75.
  • Represent it as binary number and combine 3 8-bit
    input data to a 24-bit group
  • 01110111 01110111 01110111, 00101110 01100011
    01101100,

8
Example cont
  • Form 4 6-bit inputs in each 24-bit group
  • 011101 110111 011101 110111, 001011 100110
    001101 101100,
  • Attention
  • in the last group is only 01110101(7510), so we
    need to add 0s to form 4 6-bit units, that is,
    011101 010000 000000 000000
  • NOTE last 2 6-bit units dont represent actual
    input data
  • Translate each 6-bit input into a single digit
    29 55 29 55, 11 38 13 44, 11 39 21 40, 11 38 21
    36, 29 16 0 0.

9
Example cont
  • Each digit is used as index into the base64
    alphabet table.
  • Represent each digit as corresponding character
    in the base64 table
  • 29 55 29 55, 11 38 13 44, 11 39 21 40, 11 38 21
    36, 29 16 0 0
  • d 3 d 3 , L m N s , L n V o ,
    L m V T , d Q
  • Attention
  • Last two 0s are interpreted as , because
    they do NOT represent actual input data, they are
    added by ourselves.
  • The final result of encoding www.cl.uh.edu is
    d3d3LmNsLnVoLmVTdQ.

10
Issues for Considerations
  • The encoded data are consistently about 33
    larger than the unencoded data.
  • The output stream (encoded bytes) must be
    represented in lines of no more than 76
    characters each.

11
Issues for Considerations cont
  • All other characters (including line breaks) not
    found in the table must be ignored during
    decoding, since they probably indicate a
    transmission error, for which a warning message
    or a rejection message may be given under some
    circumstances.

12
Issues for Considerations cont
  • Careful decoding must be made when last group of
    input data is less than 24 bits, that is adding
    0s bits to form multiple of 6-bit unit and set
    output character that doesnt represent actual
    input data to the character .
  • Three cases may occur in the last group of
    output
  • inputs are 24 bits, outputs are 4 characters
    with no
  • inputs are 16 bits, outputs are 3 characters
    with one
  • inputs are 8 bits, outputs are 2 characters with
    two

13
Issues for Considerations cont
  • Care must be taken when directly encoding text
    material. That is, some special characters like
    line breaks should be converted into CRLF
    sequences prior to base64 encoding (that means
    you should be aware of both printable characters
    and those control code).

14
Other Methods?? uuencode
  • Uuencode is a set of algorithms that convert
    files to 7-bit ASCII characters, which can be
    transmitted over the Internet.
  • Its especially popular for sending email
    attachments.
  • Originally, uuencode stood for Unix-to-Unix
    encode, but it has become a universal protocol to
    transfer files between different platforms such
    as Unix, Windows, and Macintosh.

15
Other Methods ?? Base85
  • The Base85 encoding is used to encode IPv6
    address, which is treated as a 128-bit integer.
  • The Base85 digits in ascending order are 0..9,
    A..Z, a..z, !, , , , , (, ), , ,-, , lt, ,
    gt, ?, _at_, , _, , , , , .

16
Other Methods ?? Base85 cont
  • Algorithm
  • Convert address to decimal number.
  • 10800008800200C417A (Hex.)
  • 21932261930451111902915077091070067066 (Dec.)
  • Divide this number by 85 and take the remainder,
    then continue to divide the quotient by 85 and
    take the remainder, and so on.
  • The remainders are 51, 34, 65, 57, 58, 0, 75,
    53, 37,4, 19, 61, 31, 63, 12, 66, 46, 70, 68, 4.
  • Reverse the order of the remainders.
  • 4, 68, 70, 46, 66, 12, 63, 31, 61, 19, 4, 37,
    53, 75, 0, 58, 57, 65, 34, 51.

17
Other Methods ?? Base85 cont
  • Algorithm (cont)
  • Use the numbers (reversed remainders) as index
    into the Base85 alphabet table to get the
    corresponding characters.
  • 4, 68, 70, 46, 66, 12, 63, 31, 61, 19,
    (remainders)
  • 4, ), , k, , C, , V, z, J,
    (encoded in Base85)
  • 4, 37, 53, 75, 0, 58, 57, 65, 34, 51.
    (remainders)
  • 4, b, r, gt, 0, w, v, , Y, p.
    (encoded in Base85)
  • Final result is 4)kCVzJ4brgt0wvYp

18
Other Methods ?? Base85 cont
  • Benefits
  • Reduce IPv6 address length when encoding it in
    textual format, that is from 39 characters to 20
    characters.
  • Encode IPv6 address to a fixed-length
    representation.
  • Its very hard to be decoded by any casual
    observer, so its more secure.
  • Other issues
  • So far many current processors dont have 128-bit
    arithmetic. Future processors should address this
    defect before any significant IPv6 deployment has
    been accomplished.

19
References
  • http//www.python.org/doc/current/lib/module-base6
    4.html (Base64)
  • RFC 1521 (Base64)
  • http//www.webopedia.com/TERM/U/Uuencode.html
    (uuencode)
  • RFC 1924 (Base85)
Write a Comment
User Comments (0)
About PowerShow.com