bitbot-3.11-fork/modules/hash.py

18 lines
682 B
Python
Raw Normal View History

2016-04-20 12:52:23 +00:00
import hashlib
from src import ModuleManager, Utils
2016-04-20 12:52:23 +00:00
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.hash", min_args=2, usage="<algo> <string>")
2016-04-20 12:52:23 +00:00
def hash(self, event):
"""
Hash a given string with a given algorithm
"""
2016-04-20 12:52:23 +00:00
algorithm = event["args_split"][0].lower()
if algorithm in hashlib.algorithms_available:
phrase = " ".join(event["args_split"][1:])
cipher_text = hashlib.new(algorithm, phrase.encode("utf8")
).hexdigest()
event["stdout"].write("%s -> %s" % (phrase, cipher_text))
else:
event["stderr"].write("Unknown algorithm provided")