Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import binascii
  3. import base64
  4.  
  5. def A2B(data):
  6.      bin(ord(ch))[2:].zfill(8) for ch in data
  7.  
  8.  
  9. def B2A(data):
  10.     for ch in data:
  11.         print("ASCII is ",int(ch,2))
  12.  
  13.  
  14. def S2H(data):
  15.     data = binascii.hexlify(data)
  16.  
  17. def H2S(data):
  18.     data = binascii.unhexlify(data)
  19.  
  20. def S2b64(data):
  21.  
  22.     base64.b64encode(data.encode())
  23.  
  24. def S2B(data):
  25.     returnData = ""
  26.     for character in data:
  27.         returnData  = returnData +
  28.         bin(int(character,base=16)).lstrip("0b").zfill(8)
  29.         + " "
  30.  
  31. #base64.b64encode(b'string to encode') <- put b before as needs to be byte.
  32. #binascii.hexlify()
  33. #binascii.unhexlify()
  34. #ENCODING & DECODING String to bytes
  35. #myString = "This is a string" myBytes = myString.encode() Can specify utf-8
  36. #but encode converts to utf-8 as default.
  37.  
  38. #bytearray(String,'UTF-8')
  39. #'{0:08b}'.format(6)  <- converts 6 to bninary with 8 bits padded with 0's
  40. #"{0:020b}".format(int('ABC123EFFF', 16))
  41. #chr() changes from hex int to hex string  0xFF to \xFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement