파이썬[Python]: base64 - a85decode 함수

파이썬(Phthon): base64 모듈 - a85decode 함수(function)


/// 설명

Ascii85를 사용하여 바이트 객체나 아스키(ascii) 문자열을 디코딩합니다.
foldspaces는 'y'를 '20202020(16)'로 변환합니다. 'btoa'에서 사용되며 표준 ascii85 디코딩에서는 사용되지 않습니다.
adobe는 입력이 Adobe Ascii85 형식이어야 합니다.('<~디코딩 할 객체~>')
ignorechars는 바이트 객체나 아스키(ascii) 문자열에서 무시되어야 할 문자를 지정합니다. 공백문자이어야 하며, ASCII 코드의 공백문자가 기본값입니다.

※ 형식
base64.a85decode(bytes, *, foldspaces=False, adobe=False, ignorechars=b'\t\n\r\x0b')

reference
https://docs.python.org/3/library/base64.html#module-base64

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from base64 import *
 
# Ascii85 encoding
test_bytes1 = b'byte'  # is a multiple of 4 Byte
test_bytes2 = b'byte\x20\x20\x20\x20'
test_bytes3 = b'byt'  # is not a multiple of 4 Byte
test_encode1 = a85encode(test_bytes1)
test_encode2 = a85encode(test_bytes2, foldspaces=True)
test_encode3 = a85encode(test_bytes1, wrapcol=1)
test_encode4 = a85encode(test_bytes3, pad=True)
test_encode5 = a85encode(test_bytes1, adobe=True)
 
print('Ascii85               :', test_encode1)  # Ascii85               : b"@X3',"
print('Ascii85 with foldspace:', test_encode2)  # Ascii85 with foldspace: b"@X3',y"
print('Ascii85 with wrapcol  :', test_encode3)  # Ascii85 with wrapcol  : b"@\nX\n3\n'\n,"
print('Ascii85 with pad      :', test_encode4)  # Ascii85 with pad      : b'@X3%q'
print('Ascii85 with adobe    :', test_encode5)  # Ascii85 with adobe    : b"<~@X3',~>"
 
print('-' * 40)
 
# Ascii85 decoding
test_decode1 = a85decode(test_encode1)
test_decode2 = a85decode(test_encode2, foldspaces=True)
test_decode3 = a85decode(test_encode5, adobe=True)
test_decode4 = a85decode(test_encode3, ignorechars=b'\t\n\r\x0b')
 
print('decoded                  :', test_decode1)  # decoded                  : b'byte'
print('decoded with foldspace   :', test_decode2)  # decoded with foldspace   : b'byte    '
print('decoded with adobe       :', test_decode3)  # decoded with adobe       : b'byte'
print('decoded with ignorechars :', test_decode4)  # decoded with ignorechars : b'byte'
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수