Skip to content

Commit

Permalink
Merge pull request #6 from misarb/dev
Browse files Browse the repository at this point in the history
add md5 and morse code
  • Loading branch information
Soulsender authored Aug 27, 2022
2 parents 68e1615 + 4aed102 commit 723123d
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cogs/md5.py
Original file line number Diff line number Diff line change
@@ -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))

85 changes: 85 additions & 0 deletions cogs/mor.py
Original file line number Diff line number Diff line change
@@ -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))

3 changes: 3 additions & 0 deletions cogs/template_file.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
intents=intents)
client.remove_command('help')


async def main():
async with client:

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 723123d

Please sign in to comment.