Login Register


Morse Encode/Decode Class filter_list
Author
Message
Morse Encode/Decode Class #1
[Image: FY7L401.png]

Here's a class that I made for Morse Encode/Decode functions for Deque's Multi-Encoder Collection Smile

Code:
class ex094morse: def encode(self, text): morse_encode = {'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' : '----.',' ' : ' '} store = '' for item in text.upper(): store += morse_encode[item] + ' ' return store def decode(self, text): morse_decode = {'.-' : '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'} store = '' for item in text.split(): store += ' ' + morse_decode[item] return store

ArkPhase's Modified Code:

Code:
class ex094morse: morse_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' morse_encode = ['.-', '-...', '-.-.', '-.', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.','...' ,'-' ,'..-' ,'...-' ,'.--' ,'-..-' ,'-.--' ,'--..' ,'-----' ,'.----','..---','...--','....-','.....','-....','--...','---..','----.'] def encode(self, text): store = '' for item in text.upper(): store += self.morse_encode[self.morse_alpha.find(item)] + ' ' return store def decode(self, text): store = '' for item in text.split(): store += ' ' + self.morse_alpha[self.morse_encode.index(item)] return store

No explanation because I've already done it in this thread http://www.hackcommunity.com/Thread-Mors...#pid134332

Have fun Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

Morse Encode/Decode Class #2
[Image: FY7L401.png]

Here's a class that I made for Morse Encode/Decode functions for Deque's Multi-Encoder Collection Smile

Code:
class ex094morse: def encode(self, text): morse_encode = {'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' : '----.',' ' : ' '} store = '' for item in text.upper(): store += morse_encode[item] + ' ' return store def decode(self, text): morse_decode = {'.-' : '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'} store = '' for item in text.split(): store += ' ' + morse_decode[item] return store

ArkPhase's Modified Code:

Code:
class ex094morse: morse_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' morse_encode = ['.-', '-...', '-.-.', '-.', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.','...' ,'-' ,'..-' ,'...-' ,'.--' ,'-..-' ,'-.--' ,'--..' ,'-----' ,'.----','..---','...--','....-','.....','-....','--...','---..','----.'] def encode(self, text): store = '' for item in text.upper(): store += self.morse_encode[self.morse_alpha.find(item)] + ' ' return store def decode(self, text): store = '' for item in text.split(): store += ' ' + self.morse_alpha[self.morse_encode.index(item)] return store

No explanation because I've already done it in this thread http://www.hackcommunity.com/Thread-Mors...#pid134332

Have fun Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Morse Encode/Decode Class #3
Hi Ex094,

thanks for your entry.
There are some things I would like to change though.
You are doing the input and output yourself. But this is my part. The Multi-Encoder program will get the user input and use your class (and the class of other submissions) to encode or decode it. Because of that I just need the encoding/decoding from you, not any kind of user interface that I will have to remove.

Please make sure that your program adheres the specification. Look at the example and the description

Do this:

Code:
def encode(self, text): def decode(self, code):

Not this:

Code:
def encode(): def decode():

Otherwise I can't use your code.

Last but not least: The dictionaries (morse_decode, morse_encode) belong into the class, not outside of it.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Morse Encode/Decode Class #4
Hi Ex094,

thanks for your entry.
There are some things I would like to change though.
You are doing the input and output yourself. But this is my part. The Multi-Encoder program will get the user input and use your class (and the class of other submissions) to encode or decode it. Because of that I just need the encoding/decoding from you, not any kind of user interface that I will have to remove.

Please make sure that your program adheres the specification. Look at the example and the description

Do this:

Code:
def encode(self, text): def decode(self, code):

Not this:

Code:
def encode(): def decode():

Otherwise I can't use your code.

Last but not least: The dictionaries (morse_decode, morse_encode) belong into the class, not outside of it.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Morse Encode/Decode Class #5
(04-19-2013, 07:04 PM)Deque Wrote: Hi Ex094,

thanks for your entry.
There are some things I would like to change though.
You are doing the input and output yourself. But this is my part. The Multi-Encoder program will get the user input and use your class (and the class of other submissions) to encode or decode it. Because of that I just need the encoding/decoding from you, not any kind of user interface that I will have to remove.

Please make sure that your program adheres the specification. Look at the example and the description

Do this:

Code:
def encode(self, text): def decode(self, code):

Not this:

Code:
def encode(): def decode():

Otherwise I can't use your code.

Last but not least: The dictionaries (morse_decode, morse_encode) belong into the class, not outside of it.
Jeez, Thanks alot, I'll correct those stuff right away and for the dictionary I kept getting confused whether to put em inside or outside but now you've cleared it

@Deque I've done the adjustments in the code, do check it and alert me if it needs further edit Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Morse Encode/Decode Class #6
(04-19-2013, 07:04 PM)Deque Wrote: Hi Ex094,

thanks for your entry.
There are some things I would like to change though.
You are doing the input and output yourself. But this is my part. The Multi-Encoder program will get the user input and use your class (and the class of other submissions) to encode or decode it. Because of that I just need the encoding/decoding from you, not any kind of user interface that I will have to remove.

Please make sure that your program adheres the specification. Look at the example and the description

Do this:

Code:
def encode(self, text): def decode(self, code):

Not this:

Code:
def encode(): def decode():

Otherwise I can't use your code.

Last but not least: The dictionaries (morse_decode, morse_encode) belong into the class, not outside of it.
Jeez, Thanks alot, I'll correct those stuff right away and for the dictionary I kept getting confused whether to put em inside or outside but now you've cleared it

@Deque I've done the adjustments in the code, do check it and alert me if it needs further edit Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Morse Encode/Decode Class #7
It could be fun to create this in C# (or VB.NET) with a call to the Beep function from Kernel32.dll as sound lol. Maybe i'll write it up quick tomorrow and release it. I have other projects on my plate but it's nice to have something else to distract you for a day or two just to regain a clear mind.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Morse Encode/Decode Class #8
Code:
def encode(self): for item in self.upper():

What are you doing here?
self is not the text. It is the reference to the instance of the class. You shouldn't use it at all.
You should do:

Code:
def encode(self, text):

And

Code:
def decode(self, text):

Please have a look at my example in the contest thread and you will understand.
If you do

Code:
encoder = new MorseEncoder() encoder.encode("my text")

it is a bit like doing this instead:

Code:
encode(encoder, "my text")

encoder is the self, the object that you pass to the function. You shouldn't handle it as a string.

Code:
return 'Your Decoded Message is: %s' % store

Here you are doing part of the user interface ("Your Decoded Message is" is a note from the UI).
I only want the decoded/encoded message, not any description or I end up getting stuff like this in the tool:

Code:
Encoded message: You encoded message is: Hello World
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Morse Encode/Decode Class #9
Quote:Code:
def encode(self):

for item in self.upper():

What are you doing here?
self is not the text. It is the reference to the instance of the class. You shouldn't use it at all.
You should do:

Code:
def encode(self, text):

And

Code:
def decode(self, text):

Please have a look at my example in the contest thread and you will understand.
If you do

Code:
encoder = new MorseEncoder()
encoder.encode("my text")

it is a bit like doing this instead:

Code:
encode(encoder, "my text")

encoder is the self, the object that you pass to the function. You shouldn't handle it as a string.

Code:
return 'Your Decoded Message is: %s' % store

Here you are doing part of the user interface ("Your Decoded Message is" is a note from the UI).
I only want the decoded/encoded message, not any description or I end up getting stuff like this in the tool:

Code:
Encoded message: You encoded message is: Hello World

Understood! Sorry Deque for putting such a mess! I didn't had the time to properly correct as I was a little busy of my own, I've done the work now and I think it meets your needs now!
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Morse Encode/Decode Class #10
Quote:Code:
def encode(self):

for item in self.upper():

What are you doing here?
self is not the text. It is the reference to the instance of the class. You shouldn't use it at all.
You should do:

Code:
def encode(self, text):

And

Code:
def decode(self, text):

Please have a look at my example in the contest thread and you will understand.
If you do

Code:
encoder = new MorseEncoder()
encoder.encode("my text")

it is a bit like doing this instead:

Code:
encode(encoder, "my text")

encoder is the self, the object that you pass to the function. You shouldn't handle it as a string.

Code:
return 'Your Decoded Message is: %s' % store

Here you are doing part of the user interface ("Your Decoded Message is" is a note from the UI).
I only want the decoded/encoded message, not any description or I end up getting stuff like this in the tool:

Code:
Encoded message: You encoded message is: Hello World

Understood! Sorry Deque for putting such a mess! I didn't had the time to properly correct as I was a little busy of my own, I've done the work now and I think it meets your needs now!
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply







Users browsing this thread: