khbr

hideMessage_textstego3.py

Nov 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 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.     message_binary = to_binary_string(message)
  20.  
  21.     with open(input_file) as f:
  22.         container = f.read()
  23.        
  24.     lines = container.split('\n')
  25.     print 'Lines: %d' % len(lines)
  26.     print 'Bits in message: %d' % len(message_binary)
  27.            
  28.     message_binary += '0' * (len(lines) - len(message_binary))
  29.     for i in range(len(message_binary)):
  30.         if message_binary[i] == '0':
  31.             lines[i] += '\r\n' #CRLF
  32.         else:
  33.             lines[i] += '\n\r' #LFCR
  34.            
  35.     with open(output_file, 'w') as f:
  36.         f.write(''.join(lines))
  37.  
  38.  
  39. if __name__ == '__main__':
  40.     main()
Add Comment
Please, Sign In to add comment