nekotrap

Untitled

Oct 1st, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. def getEqCh(n):
  5.     rem24 = (n * 8) % 24
  6.     return int((24 - rem24) % 24 / 8)
  7.  
  8.  
  9. def cutStr(str, step):
  10.     res = []
  11.     delta = step
  12.     for i in range(0, len(str), delta):
  13.         res.append(str[i:step])
  14.         step += delta
  15.     return res
  16.  
  17.  
  18. s = open('base64.in')
  19. arr = s.readlines()
  20. s.close()
  21. arr[0], arr[1] = int(arr[0]), arr[1][:-1]
  22. n = len(arr[1].split())
  23.  
  24. newBinArr = (cutStr(''.join([format(int(bin(int(arr[1].split()[i], 16))[2:], 2), '#010b')[2:] for i in range(n)]), 6))
  25. while len(newBinArr[-1]) < 6:
  26.     newBinArr[-1] += '0'
  27.  
  28. result = ""
  29. alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
  30. for item in newBinArr:
  31.     result += alphabet[int(item, 2)]
  32. result += getEqCh(arr[0]) * '='
  33.  
  34. f = open('base64.out', 'w')
  35. f.write(f"{result}")
  36. f.close()
Add Comment
Please, Sign In to add comment