Sfoglia il codice sorgente

adding Cryptography() IRC command class with hash functions via hashlib

tags/v0.1^2
Ben Kurtovic 13 anni fa
parent
commit
369b60b823
1 ha cambiato i file con 43 aggiunte e 0 eliminazioni
  1. +43
    -0
      irc/commands/crypt.py

+ 43
- 0
irc/commands/crypt.py Vedi File

@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

# Cryptography functions (hashing and cyphers).

import hashlib

from irc.base_command import BaseCommand

class Calc(BaseCommand):
def get_hooks(self):
return ["msg"]

def get_help(self, command):
if command == "hash":
return ("Return the hash of a string using a given algorithm, " +
"e.g. '!hash sha512 Hello world!'.")
else:
return ("{0} a string with a given key using a given algorithm, " +
"e.g. '!{1} blowfish some_key Hello world!'.").format(
command.capitalize(), command)

def check(self, data):
if data.is_command and data.command in ["hash", "encrypt", "decrypt"]:
return True
return False

def process(self, data):
if not data.args:
self.connection.reply(data, "what do you want me to do?")
return

if data.command == "hash":
algo = data.args[0]
if algo in hashlib.algorithms:
string = ' '.join(data.args[1:])
result = eval("hashlib.{0}(string)".format(algo)).hexdigest()
self.connection.reply(data, result)
else:
self.connection.reply(data, "unknown algorithm: {0}".format(
algo))

else:
self.connection.reply(data, "not implemented yet!")

Caricamento…
Annulla
Salva