Show available hash algorithms when none is provided
This commit is contained in:
parent
25b507e80c
commit
06b41cb30e
1 changed files with 11 additions and 7 deletions
|
@ -4,17 +4,21 @@ import hashlib
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.hash", min_args=2, remove_empty=False)
|
@utils.hook("received.command.hash", remove_empty=False)
|
||||||
def hash(self, event):
|
def hash(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Hash a given string with a given algorithm
|
:help: Hash a given string with a given algorithm
|
||||||
:usage: <algo> <string>
|
:usage: <algo> <string>
|
||||||
"""
|
"""
|
||||||
|
if event["args_split"]:
|
||||||
algorithm = event["args_split"][0].lower()
|
algorithm = event["args_split"][0].lower()
|
||||||
if algorithm in hashlib.algorithms_available:
|
|
||||||
phrase = " ".join(event["args_split"][1:])
|
phrase = " ".join(event["args_split"][1:])
|
||||||
|
if algorithm in hashlib.algorithms_available:
|
||||||
cipher_text = hashlib.new(algorithm, phrase.encode("utf8")
|
cipher_text = hashlib.new(algorithm, phrase.encode("utf8")
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
event["stdout"].write("%s -> %s" % (phrase, cipher_text))
|
event["stdout"].write("%s -> %s" % (phrase, cipher_text))
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Unknown algorithm provided")
|
event["stderr"].write("Unknown algorithm provided")
|
||||||
|
else:
|
||||||
|
event["stdout"].write("Available algorithms: %s" %
|
||||||
|
", ".join(hashlib.algorithms_available))
|
||||||
|
|
Loading…
Reference in a new issue