Skip to content

Commit

Permalink
mor dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
misarb committed Aug 27, 2022
1 parent 14ac9a3 commit 4aed102
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 56 deletions.
3 changes: 2 additions & 1 deletion cogs/md5.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async def md5(self, ctx, action, *, text):
if hashlib.md5(text.encode()).hexdigest() == text:
return [text,True]
else:
return "Eroor"
output = "Eroor"
return {output,True}

async def setup(client):
await client.add_cog(md5(client))
Expand Down
109 changes: 54 additions & 55 deletions cogs/mor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,74 @@ class mor(commands.Cog):
def __init__(self, client):
self.client = client
# Dictionary representing the morse code
encode_table = {
"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": "--..",
"0": "-----",
"1": ".----",
"2": "..---",
"3": "...--",
"4": "....-",
"5": ".....",
"6": "-....",
"7": "--...",
"8": "---..",
"9": "----.",
".": ".-.-.-",
",": "--..--",
"?": "..--..",
" ": "SPACE",
}
#reverse encode tabale
decode_table = {v: k for k, v in encode_table.items()}
def encode(self,s):
enc = " ".join(self.encode_table[x] for x in s)
return enc.replace(" SPACE ", " ")

def decode(self,encoded):
symbols = encoded.replace(" ", " SPACE ").split(" ")
return "".join(self.decode_table[x] for x in symbols)

@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
output = self.encode(text)

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":
output = self.decode(text)
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]

Expand Down
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
1 change: 1 addition & 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

0 comments on commit 4aed102

Please sign in to comment.