Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3.  
  4. import binascii
  5.  
  6.  
  7. def encode_hexlify(origin_text, encoding='utf-8'):
  8.     """
  9.    function to simply encode the text string using hexlify.
  10.  
  11.    :param `origin_text` is string original text to encode.
  12.    :param `encoding` is encode mode.
  13.    :return string of encoded text.
  14.    """
  15.     byte = bytes(origin_text, encoding)
  16.     return binascii.hexlify(byte).decode(encoding)
  17.  
  18.  
  19. def decode_hexlify(encoded_text, encoding='utf-8'):
  20.     """
  21.    function to simply decode the text string using hexlify.
  22.  
  23.    :param `encoded_text` is string encoded text to decode.
  24.    :param `encoding` is encode mode.
  25.    :return string of decoded text.
  26.    """
  27.     byte = bytes(encoded_text, encoding)
  28.     return binascii.unhexlify(byte).decode(encoding)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement