Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. def getBinary(bitstr):
  2. bit=' '.join(format(ord(char), 'b') for char in bitstr)
  3. return bit
  4.  
  5. def getChar(charstr):
  6. char = []
  7. for b in range(len(charstr) / 8):
  8. byte = charstr[b*8:(b+1)*8]
  9. char.append(chr(int(''.join([str(bit) for bit in byte]), 2)))
  10. return ''.join(chars)
  11.  
  12. message="We attack at dawn!?*"
  13. key=2
  14. resp=getCaesar(message, key)
  15. print("Ciphertext: ")
  16. print(resp)
  17. print()
  18.  
  19. bitstr=list(resp)
  20. binary=getBinary(bitstr)
  21. print("Binary: ")
  22. print(binary)
  23. print()
  24.  
  25. charstr=getChar(binary)
  26. print("Char String: ")
  27. print(charstr)
  28. print()
  29.  
  30. Ciphertext:
  31. Yg cvvcem cv fcyp#!,
  32.  
  33. Binary:
  34. 1011001 1100111 100000 1100011 1110110 1110110 1100011 1100101 1101101 100000 1100011 1110110 100000 1100110 1100011 1111001 1110000 100011 100001 101100
  35.  
  36. for b in range(len(charstr) / 8):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement