-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmokeSignals.py
73 lines (60 loc) · 2.05 KB
/
SmokeSignals.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
from googlevoice import Voice,util,settings
from googlevoice.util import input
import sys
import BeautifulSoup
from java.io import *
from java.lang import String
from no.swag.nsa.crypto import *
from twitter4j import *
from twitter4j.conf import *
import time
voice = Voice()
voice.login()
def encrypt(plainText, key):
bf = Blowfish(key)
return bf.encrypt(plainText)
def decrypt(cipherText, key):
bf = Blowfish(key)
return bf.decrypt(cipherText)
def postToTwitter(message):
twitter = TwitterFactory.getSingleton()
status = twitter.updateStatus(messge)
#print "Successfully updated the status to [",status.getText(),"]."
def returnText(number, message):
voice.send_sms(number, message)
def checkInbox():
for message in voice.sms().messages:
if not message.isRead:
n=message.phoneNumber
msgtxt = str(message.messageText)
txtarray = msgtxt.split(" ")
print txtarray
if len(txtarray) > 2:
e = String(txtarray[0])
#print e
key = txtarray[1]
#print key
code = ' '.join([str(x) for x in txtarray[2:len(txtarray)]])
#print code
if e.equalsIgnoreCase("encode"):
coded = encrypt(code, key)
#print "Coded message"
if len(coded) < 140:
postToTwitter(coded)
returnText(n, "Posted to Twitter: "+coded)
else:
returnText(n, "Coded message too long")
elif e.equalsIgnoreCase("decode"):
uncoded = decrypt(code, key)
#print "Decoded message"
returnText(n, "Uncoded text: "+uncoded)
else:
returnText(n, "Unable to parse input text message")
message.delete()
time.sleep(10)
def main():
while True:
checkInbox()
time.sleep(10)
if __name__ == '__main__':
main()