2017-01-09 18:54:06 +01:00
|
|
|
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.
|
2017-02-16 22:56:32 +01:00
|
|
|
It encrypts/decrypts messages starting with @mention-bot.
|
2017-01-09 18:54:06 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
def usage(self):
|
|
|
|
return '''
|
|
|
|
This bot uses ROT13 encryption for its purposes.
|
2017-02-16 22:56:32 +01:00
|
|
|
It responds to me starting with @mention-bot.
|
2017-01-09 18:54:06 +01:00
|
|
|
Feeding encrypted messages into the bot decrypts them.
|
|
|
|
'''
|
|
|
|
|
|
|
|
def handle_message(self, message, client, state_handler):
|
2017-03-05 19:58:18 +01:00
|
|
|
bot_response = self.get_bot_encrypt_response(message)
|
2017-05-24 01:59:23 +02:00
|
|
|
client.send_reply(message, bot_response)
|
2017-03-05 19:58:18 +01:00
|
|
|
|
|
|
|
def get_bot_encrypt_response(self, message):
|
2017-01-09 18:54:06 +01:00
|
|
|
original_content = message['content']
|
2017-02-16 22:56:32 +01:00
|
|
|
temp_content = encrypt(original_content)
|
2017-01-09 18:54:06 +01:00
|
|
|
send_content = "Encrypted/Decrypted text: " + temp_content
|
2017-03-05 19:58:18 +01:00
|
|
|
return send_content
|
2017-01-09 18:54:06 +01:00
|
|
|
|
|
|
|
handler_class = EncryptHandler
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
assert encrypt('ABCDabcd1234') == 'NOPQnopq1234'
|
|
|
|
assert encrypt('NOPQnopq1234') == 'ABCDabcd1234'
|