diff --git a/contrib_bots/lib/EncryptBot/EncryptBot-terminal.png b/contrib_bots/lib/EncryptBot/EncryptBot-terminal.png new file mode 100644 index 0000000..92e15a2 Binary files /dev/null and b/contrib_bots/lib/EncryptBot/EncryptBot-terminal.png differ diff --git a/contrib_bots/lib/EncryptBot/EncryptBot-test.png b/contrib_bots/lib/EncryptBot/EncryptBot-test.png new file mode 100644 index 0000000..018c87e Binary files /dev/null and b/contrib_bots/lib/EncryptBot/EncryptBot-test.png differ diff --git a/contrib_bots/lib/EncryptBot/EncryptBot-test2.png b/contrib_bots/lib/EncryptBot/EncryptBot-test2.png new file mode 100644 index 0000000..ae7cae7 Binary files /dev/null and b/contrib_bots/lib/EncryptBot/EncryptBot-test2.png differ diff --git a/contrib_bots/lib/EncryptBot/EncryptBot-test3.png b/contrib_bots/lib/EncryptBot/EncryptBot-test3.png new file mode 100644 index 0000000..2efaf8e Binary files /dev/null and b/contrib_bots/lib/EncryptBot/EncryptBot-test3.png differ diff --git a/contrib_bots/lib/EncryptBot/docs.md b/contrib_bots/lib/EncryptBot/docs.md new file mode 100644 index 0000000..1df555d --- /dev/null +++ b/contrib_bots/lib/EncryptBot/docs.md @@ -0,0 +1,16 @@ +About EncryptBot: +EncryptBot Allows for quick ROT13 encryption in the middle of a chat. + +What It Does: +The bot encrypts any message sent to it on any stream it is subscribed to with ROT13. + +How It Works: +The bot will Use ROT13(A -> N, B -> O... and vice-versa) in a python +implementation to provide quick and easy encryption. + +How to Use: + +-Send the message you want to encrypt, add @encrypt to the beginning. +-The Encrypted message will be sent back to the stream the original +message was posted in to the topic 's encrypted text. +-Messages can be decrypted by sending them to EncryptBot in the same way. diff --git a/contrib_bots/lib/encrypt_bot.py b/contrib_bots/lib/encrypt_bot.py new file mode 100755 index 0000000..4e2942c --- /dev/null +++ b/contrib_bots/lib/encrypt_bot.py @@ -0,0 +1,56 @@ +def encrypt(text): + # This is where the actual ROT13 is applied + # WHY IS .JOIN NOT WORKING?! + textlist = list(text) + newtext = '' + firsthalf = 'abcdefghijklmABCDEFGHIJKLM' + lasthalf = 'nopqrstuvwxyzNOPQRSTUVWXYZ' + for char in textlist: + if char in firsthalf: + newtext += lasthalf[firsthalf.index(char)] + elif char in lasthalf: + newtext += firsthalf[lasthalf.index(char)] + else: + newtext += char + + return newtext + +class EncryptHandler(object): + ''' + This bot allows users to quickly encrypt messages using ROT13 encryption. + It encrypts/decrypts messages starting with @encrypt. + ''' + + def usage(self): + return ''' + This bot uses ROT13 encryption for its purposes. + It responds to me starting with @encrypt. + Feeding encrypted messages into the bot decrypts them. + ''' + + def triage_message(self, message, client): + + original_content = message['content'] + + # This makes sure that the bot only replies to messages it supposed to reply to. + should_be_encrypted = original_content.startswith('@encrypt') + + return should_be_encrypted + + def handle_message(self, message, client, state_handler): + original_content = message['content'] + temp_content = encrypt(original_content.replace('@encrypt', '')) + send_content = "Encrypted/Decrypted text: " + temp_content + + client.send_message(dict( + type='stream', + to=message['display_recipient'], + subject=message['subject'], + content = send_content + )) + +handler_class = EncryptHandler + +if __name__ == '__main__': + assert encrypt('ABCDabcd1234') == 'NOPQnopq1234' + assert encrypt('NOPQnopq1234') == 'ABCDabcd1234'