-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter_encode_binary.py
76 lines (64 loc) · 2.07 KB
/
twitter_encode_binary.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
70
71
72
73
74
75
76
"""
CSEC 791 MS Project
Grace Lombardi
Twitter Covert Channel
Encode Binary
"""
import tweepy
import twitter_config
client = tweepy.Client(
bearer_token=twitter_config.bearer_token,
consumer_key=twitter_config.api_key,
consumer_secret=twitter_config.api_secret,
access_token=twitter_config.access_token,
access_token_secret=twitter_config.access_secret
)
def get_user_id():
"""
This function prompts the user for a username and then returns the user id associated with that
username.
"""
username = input("Enter the username of the profile to place your message on: ")
response = client.get_user(username=username)
return response.data.id
def get_message_input():
"""
This function prompts the user for a message to encode and then returns a list of all characters
in the message.
"""
message = input("Enter the message to encode: ")
message = message.replace(" ", "")
chars = list(message)
return chars
def convert_to_binary(chars):
"""
This function coverts every character in the list to their binary equivalent.
"""
binary = ''.join(format(ord(char), '08b') for char in chars)
return binary
def main():
"""
This is the main encoding function.
"""
user_id = get_user_id()
response = client.get_users_tweets(id=user_id, max_results=100)
message = get_message_input()
binary = convert_to_binary(message)
list_ids = []
if len(response.data) < (len(message) * 8):
print("There are not enough tweets on this account to send the message. Please try a "
"different user account.")
else:
for tweets in response.data:
tweet_id = tweets.id
list_ids.append(tweet_id)
for tweet_id in list_ids:
client.unlike(tweet_id)
for num, tweet_id in zip(binary, list_ids):
if num == '0':
client.unlike(tweet_id)
elif num == '1':
client.like(tweet_id)
print("Finished Liking/Unliking Tweets to Hide Message")
if __name__ == '__main__':
main()