-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstegotext.py
69 lines (57 loc) · 1.86 KB
/
stegotext.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import os.path
# Output - cover file with message in it
output = []
# Get words from a cover file
def getWords(cover_file):
words = []
if not os.path.isfile(cover_file):
print('File does not exist.')
else:
with open(cover_file) as content:
for line in content:
for word in line.split():
words.append(word+' ') #find smarter way to put spaces between words
return words
# stego stuff - extended line
def stegoStuff(binary, words, limit):
word_nummber = 0
for value in binary:
print(value)
line = ''
if value == 0:
while len(line)+len(words[word_nummber]) <= limit:
line += words[word_nummber]
word_nummber += 1
elif value == 1:
while len(line) <= limit:
line += words[word_nummber]
word_nummber += 1
output.append(line)
output.append(len(line))
# todo once there are no values left in binary, generate a few random
print(output)
# returns binary values of the message
def messageToBinary(message):
dec_values = list(message.encode('ascii'))
bin_values = [format(i,'08b') for i in dec_values]
bin_string = ''.join(str(x) for x in bin_values) # TODO: this is not nice and overcomplicated
bin_array = [int(value) for value in bin_string]
return bin_array
# TODO decode method decode(file, limit)
# TODO input params
# TODO output to file/cli
if __name__ == "__main__":
# Message
message = 'Hi'
# Define a cover file
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'cover_files/lorem_ipsum.txt')
# List of words
words = []
# Line limit
limit = 30
binary = messageToBinary(message)
print(binary)
words = getWords(filename)
stegoStuff(binary, words, limit)