Skip to content

Commit

Permalink
Added the ability to send encrypted files over twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Towns committed Mar 13, 2010
1 parent 6b757e1 commit 44bfc05
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions rsachat.py
Expand Up @@ -4,7 +4,7 @@
#
#
#
import rsa, pickle, os, math, twitter, datetime, feedparser, re
import rsa, pickle, os, math, twitter, datetime, feedparser, re, binascii, sys
from optparse import OptionParser

def get_twitter(url, limit=10):
Expand Down Expand Up @@ -97,9 +97,18 @@ def readTweet((tag, author, pubkey)):
outputencr = ""
for neworder in posts:
outputencr = outputencr + neworder
print "==========================="
print "@%s: %s" % (author, rsa.decrypt(outputencr.replace("\n", ""), key).strip())
print "==========================="
decrypted = rsa.decrypt(outputencr.replace("\n", ""), key).strip()
if decrypted[0:5].strip() == "FILE:":
print "Tweet is a file, decrypting.."
a = pickle.loads(binascii.a2b_base64(decrypted[5:]))
filename = a['filename'].replace("/", "")
fp = open(filename, "w")
fp.write(binascii.a2b_base64(a['data']))
print "Saved: %s" % a['filename']
else:
print "==========================="
print "@%s: %s" % (author, decrypted)
print "==========================="
print "Done!"

def getKey(filepath):
Expand All @@ -113,16 +122,51 @@ def sortedDictValues1(adict):
items.sort()
return [value for key, value in items]

def fileThis((tag, filename)):
print "Encoding %s" % filename
fp = open(filename, 'rb')
encoded = binascii.b2a_base64(fp.read())
fp.close()
sendme = {'filename': filename, 'data':encoded}
data = pickle.dumps(sendme)
keys = getPubPriv()
login = getLogin()
if keys == -1:
print "You have not created the proper keys, try ./%s -h" % (sys.argv[0])
exit(-1)
if login == -1:
print "You have not specified your twitter details, try ./%s -h" % (sys.argv[0])
exit (-1)
# All seems g2g
etweet = "FILE: %s" % binascii.b2a_base64(data)
htag = tag
print "Tweeting: %s [%s]" % (etweet, htag)
enctweet = rsa.encrypt(etweet, keys["pub"])
splits = int(math.ceil(len(enctweet) / 120.00))
tweets = {}
for i in range(0,splits):
tweets[i] = "%s" % (enctweet[(i*120):(i+1)*120])
header = "[%s/%s] %s" % ("%s", len(tweets), htag)
#posttweets = {}
api = twitter.Api(username=login[0], password=login[1])
for i in range(0, len(tweets)):
api.PostUpdate("%s %s" % ((header % (i+1)), tweets[i]))
#posttweets[i+1] = "%s %s" % ((header % (i+1)), tweets[i])
print "Done!"



if __name__ == "__main__":
print "RSA Encrypted tweets by ikex <ashleyis@me.com>"
parser = OptionParser(version="%prog 0.1")
parser.add_option("-g", dest="genkey", help="Generate a private/public key for use", action="store_true")
parser.add_option("-a", "--twitter", dest="twitter", help="Your twitter login specified as <user> <pass>", metavar="login", nargs=2)
parser.add_option("-a", dest="twitter", help="Your twitter login specified as <user> <pass>", metavar="login", nargs=2)
parser.add_option("-t", dest="tweet", help="Post a tweet starting with the hashtag eg, \"#RSAToMyFriends Hi guys!\"", metavar="#tag tweet")
parser.add_option("-f", dest="tweetfile", help="Post a file encrypted as tweets eg, \"#tag <filename>\"", metavar="#tag filename.txt", nargs=2)
parser.add_option("-r", dest="readtweet", help="Reads a tweet with the specified tag author pubkey", metavar="tag author pubkey", nargs=3)
(options, args) = parser.parse_args()
if options.genkey: genKey()
elif options.twitter: twitterInfo(options.twitter)
elif options.tweet: tweetThis(options.tweet)
elif options.readtweet: readTweet(options.readtweet)
elif options.readtweet: readTweet(options.readtweet)
elif options.tweetfile: fileThis(options.tweetfile)

0 comments on commit 44bfc05

Please sign in to comment.