Created
August 20, 2014 11:54
-
-
Save pa4373/994f9e40412ba12da37b to your computer and use it in GitHub Desktop.
Bit modification concept demonstration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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