-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempCodeRunnerFile.python
41 lines (36 loc) · 1.49 KB
/
tempCodeRunnerFile.python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def text_to_binary(text):
binary = ""
for char in text:
binary += format(ord(char), '08b')
return binary
def binary_to_text(binary):
text = ""
for i in range(0, len(binary), 8):
byte = binary[i:i+8]
text += chr(int(byte, 2))
return text
def embed_secret_message(carrier_text, secret_message):
binary_secret_message = text_to_binary(secret_message)
modified_carrier_text = ""
secret_message_index = 0
for char in carrier_text:
binary_char = format(ord(char), '08b')
if secret_message_index < len(binary_secret_message):
modified_char = binary_char[:-2] + binary_secret_message[secret_message_index:secret_message_index+2]
secret_message_index += 2
else:
modified_char = binary_char
modified_carrier_text += chr(int(modified_char, 2))
return modified_carrier_text
def extract_secret_message(modified_carrier_text):
binary_secret_message = ""
for char in modified_carrier_text:
binary_char = format(ord(char), '08b')
binary_secret_message += binary_char[-1]
secret_message = binary_to_text(binary_secret_message)
return secret_message
carrier_text = "The quick brown fox jumps over the lazy dog."
secret_message = "hello i am garv haldia and i am thirsty"
modified_carrier_text = embed_secret_message(carrier_text, secret_message)
with open('modified_carrier_text.txt', 'w') as f:
f.write(modified_carrier_text)