-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from misarb/dev
add md5 and morse code
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters