Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*- coding: windows-1251 -*-
- # Todo: пока работает только с маленькими o
- import sys
- import os
- def to_binary_string(s):
- binary_s = ''
- for c in s:
- binary_s += '{:08b}'.format(ord(c))
- return binary_s
- def main():
- if len(sys.argv) != 4:
- print 'Usage: python %s <input-file> <message> <output-file>' % sys.argv[0]
- exit(1)
- input_file = sys.argv[1]
- message = sys.argv[2]
- output_file = sys.argv[3]
- if not os.path.exists(input_file):
- print 'File "%s" does not exist' % input_file
- exit(1)
- message_binary = to_binary_string(message)
- print 'message_binary', message_binary
- with open(input_file) as f:
- container = f.read()
- assert(container.count('o') >= len(message_binary))
- indices = []
- for idx, c in enumerate(container):
- if c == 'o':
- indices.append(idx)
- container_lst = list(container)
- for idx, bit in enumerate(message_binary):
- if bit == '1':
- container_lst[indices[idx]] = ' # russian
- with open(output_file, 'w') as f:
- f.write(''.join(container_lst))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment