Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def symbEncode(x):
  2.     if x < 26:
  3.         return chr(x + 65)
  4.     elif x < 52:
  5.         return chr(x + 97 - 26)
  6.     elif x < 62:
  7.         return chr(x + 45 - 26*2)
  8.     elif x == 62:
  9.         return "+"
  10.     else:
  11.         return "/"
  12.  
  13. x = 21
  14. print(symbEncode(x))
  15.  
  16. def sybmDecode(y):
  17.     n = ord(y)
  18.     if n == 43:
  19.         return "{0:b}".format(63).zfill(6)
  20.     elif n == 47:
  21.         return "{0:b}".format(62).zfill(6)
  22.     elif n < 58:
  23.         return "{0:b}".format(n - 48 + 52).zfill(6)
  24.     elif n < 91:
  25.         return "{0:b}".format(n - 65).zfill(6)
  26.     else:
  27.         return "{0:b}".format(n - 97 + 26).zfill(6)
  28.        
  29. def sybmDecode2(y):
  30.     n = ord(y)
  31.     if n == 43:
  32.         return bin(63)[2:].zfill(6)
  33.     elif n == 47:
  34.         return bin(62)[2:].zfill(6)
  35.     elif n < 58:
  36.         return bin(n - 48 + 52)[2:].zfill(6)
  37.     elif n < 91:
  38.         return bin(n - 65)[2:].zfill(6)
  39.     else:
  40.         return bin(n - 97 + 26)[2:].zfill(6)
  41.        
  42. y = "B"
  43. print(sybmDecode2(y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement