Advertisement
khbr

hideMessage_textstego1.py

Nov 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import sys
  2. import os
  3.  
  4. def to_binary_string(s):
  5.     binary_s = ''
  6.     for c in s:
  7.         binary_s += '{:08b}'.format(ord(c))
  8.     return binary_s
  9.  
  10. def main():
  11.     if len(sys.argv) != 4:
  12.         print 'Usage: python %s <input-file> <message> <output-file>' % sys.argv[0]
  13.         exit(1)
  14.        
  15.     input_file   = sys.argv[1]
  16.     message      = sys.argv[2]
  17.     output_file  = sys.argv[3]
  18.        
  19.     if not os.path.exists(input_file):
  20.         print 'File "%s" does not exist' % input_file
  21.         exit(1)
  22.        
  23.    
  24.     message_binary = to_binary_string(message)
  25.  
  26.     with open(input_file) as f:
  27.         container = f.read()
  28.        
  29.     words = container.split(' ')
  30.            
  31.     message_binary += '0' * (len(words) - len(message_binary))
  32.     for i in range(len(message_binary)):
  33.         if message_binary[i] == '0':
  34.             words[i] += ' ' # 1 space
  35.         else:
  36.             words[i] += '  ' # 2 spaces
  37.            
  38.     with open(output_file, 'w') as f:
  39.         f.write(''.join(words))
  40.    
  41. if __name__ == '__main__':
  42.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement