diff --git a/cogs/md5.py b/cogs/md5.py new file mode 100644 index 0000000..9e2634e --- /dev/null +++ b/cogs/md5.py @@ -0,0 +1,36 @@ +#!/usr/bin/python +# created by : Boulbalah lahcen + +from discord.ext import commands +import hashlib + +class md5(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.Cog.listener() + async def on_ready(self): + print(__file__, ' Online') + + @commands.command() + async def md5(self, ctx, action, *, text): + + # encode md5 + if action == "encode" or action == "e": + # encode to md5 + output = hashlib.md5(text.encode()).hexdigest() + await ctx.send(output) + return [output, True] + + # decode md5 + if action == "decode" or action == "d": + # decode to md5 + if hashlib.md5(text.encode()).hexdigest() == text: + return [text,True] + else: + output = "Eroor" + return {output,True} + +async def setup(client): + await client.add_cog(md5(client)) + diff --git a/cogs/mor.py b/cogs/mor.py new file mode 100644 index 0000000..39e1d11 --- /dev/null +++ b/cogs/mor.py @@ -0,0 +1,85 @@ +#!/usr/bin/python +# created by : Boulbalah lahcen + +from discord.ext import commands + + + +class mor(commands.Cog): + def __init__(self, client): + self.client = client + # Dictionary representing the morse code + @commands.Cog.listener() + async def on_ready(self): + print(__file__, ' Online') + + @commands.command() + async def mor(self, ctx, action, *, text): + cipher = '' + # Dictionary representing the morse code + MORSE_CODE_DICT = { 'A':'.-', 'B':'-...', + 'C':'-.-.', 'D':'-..', 'E':'.', + 'F':'..-.', 'G':'--.', 'H':'....', + 'I':'..', 'J':'.---', 'K':'-.-', + 'L':'.-..', 'M':'--', 'N':'-.', + 'O':'---', 'P':'.--.', 'Q':'--.-', + 'R':'.-.', 'S':'...', 'T':'-', + 'U':'..-', 'V':'...-', 'W':'.--', + 'X':'-..-', 'Y':'-.--', 'Z':'--..', + '1':'.----', '2':'..---', '3':'...--', + '4':'....-', '5':'.....', '6':'-....', + '7':'--...', '8':'---..', '9':'----.', + '0':'-----', ', ':'--..--', '.':'.-.-.-', + '?':'..--..', '/':'-..-.', '-':'-....-', + '(':'-.--.', ')':'-.--.-'} + # encode morse + if action == "encode" or action == "e": + # encode to morse + + for letter in text: + if letter != ' ': + output += MORSE_CODE_DICT[letter] + ' ' + else: + output += ' ' + # output = cipher + await ctx.send(output) + return [output, True] + + # decode mor + if action == "decode" or action == "d": + text += ' ' + output = '' + citext = '' + for letter in text: + + # checks for space + if (letter != ' '): + + # counter to keep track of space + i = 0 + + # storing morse code of a single character + citext += letter + + # in case of space + else: + # if i = 1 that indicates a new character + i += 1 + + # if i = 2 that indicates a new word + if i == 2 : + + # adding space to separate words + output += ' ' + else: + # accessing the keys using their values (reverse of encryption) + output += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT + .values()).index(citext)] + citext = '' + + await ctx.send(output) + return [output,True] + +async def setup(client): + await client.add_cog(mor(client)) + diff --git a/cogs/template_file.py b/cogs/template_file.py index 425ed42..85fa3ab 100644 --- a/cogs/template_file.py +++ b/cogs/template_file.py @@ -1,6 +1,8 @@ # IMPORTS from discord.ext import commands +from cogs.mor import mor + # INIT CLASS # should be the same name as the file class x(commands.Cog): @@ -31,6 +33,7 @@ async def x(self, ctx, action, *, text): elif action == "decode" or "d": # do the cipher code here + output = "output of the cipher" # this sends the result diff --git a/main.py b/main.py index f0d50e2..50d07f6 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ intents=intents) client.remove_command('help') + async def main(): async with client: @@ -66,6 +67,10 @@ async def help(ctx): "Encoding and decoding with Rotation 13.", inline=False) embed.add_field(name="Binary", value="`bin {encode/e & decode/d} {\"string\"}`\n" "Encoding and decoding with binary.", inline=False) + embed.add_field(name="MD5", value="`md5 {encode/e & decode/d} {\"string\"}`\n" + "Encoding and decoding with md5.", inline=False) + embed.add_field(name="Morse", value="`mor {encode/e & decode/d} {\"string\"}`\n" + "Encoding and decoding Morse code.", inline=False) embed.set_footer(text='Created by Soulsender. See the wiki for documentation.') await ctx.send(embed=embed)