Skip to content

Instantly share code, notes, and snippets.

@pa4373
Created August 20, 2014 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pa4373/994f9e40412ba12da37b to your computer and use it in GitHub Desktop.
Save pa4373/994f9e40412ba12da37b to your computer and use it in GitHub Desktop.
Bit modification concept demonstration
'''
Usage:
$ python flip.py [SEED_NUMBER]
ex: python flip.py 3923
'''
import sys, random
message = [True, True, True, True, True, False, True, False]
carrier = [False, False, False, True, False, False, True, False, False, False, True, False, True, True, False]
message_size = len(message)
carrier_size = len(carrier)
message_loc = []
random.seed(int(sys.argv[1]))
while len(message_loc) != message_size:
loc = random.randrange(0,carrier_size)
if loc in message_loc:
continue
message_loc.append(loc)
new_carrier = []
carrier_cursor = 0
message_cursor = 0
while carrier_cursor != len(carrier):
if carrier_cursor in message_loc:
if carrier[carrier_cursor] != message[message_cursor]:
carrier[carrier_cursor] = not carrier[carrier_cursor]
message_cursor += 1
new_carrier.append(carrier[carrier_cursor])
carrier_cursor += 1
get_data = []
for i in message_loc:
get_data.append(new_carrier[i])
print message # The message itself
print get_data # The reconstructed message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment