This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-26 19:11:34

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Python ROT13 Decoder!

Hey guys! Check out my ROT13 Decoder in Python!:

Code:

Alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
Alphabet2 = list('abcdefghijklmnopqrstuvwxyz')
while True:
    
    Result = ""
    Text = raw_input('Enter text here to translate to ROT13:')

    if Text.lower() == '/quit':
        break
        
    for i in range(0, len(Text)):

        if Text[i] in Alphabet:
            if Alphabet.index(Text[i]) <= 12:
                Result = Result + Alphabet[Alphabet.index(Text[i]) + 13]
            else:
                Result = Result + Alphabet[Alphabet.index(Text[i]) - 13]
            
        elif Text[i] in Alphabet2:
            if Alphabet2.index(Text[i]) <= 12:
                Result = Result + Alphabet2[Alphabet2.index(Text[i]) + 13]
            else:
                Result = Result + Alphabet2[Alphabet2.index(Text[i]) - 13]
            
        else:
            Result = Result + Text[i] 
    print ('The translation is: ' + Result)

EDIT: I added a while loop so that you can type in as many things as you like.
EDIT: Added a /quit command.
EDIT: /quit is no longer case sensitive.

Last edited by ImagineIt (2012-05-27 20:34:38)

Offline

 

#2 2012-05-26 19:19:35

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Python ROT13 Decoder!

I'm no good at python, but from skimming docs, you can try STRING_TEXT_WHATEVER_VARIABLE.ascii_uppercase.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#3 2012-05-26 19:22:04

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Python ROT13 Decoder!

Your method is not seeming to work for me bobbybee. I can show the code to you if you would like:

Code:

Alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
Result = ""
Text = raw_input('Enter text here to translate to ROT13:')
for i in range(0, len(Text)):
    if Text[i] in Alphabet:
        if Alphabet.index(Text[i]) <= 12:
            Result = Result + Alphabet[Alphabet.index(Text[i]) + 13]
        else:
            Result = Result + Alphabet[Alphabet.index(Text[i]) - 13]
    else:
        Result = Result + Text[i]
print(Result)

Offline

 

#4 2012-05-26 19:25:54

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Python ROT13 Decoder!

I dunno, but maybe:

Code:

Alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
Result = ""
Text = raw_input('Enter text here to translate to ROT13:')
Text = Text.ascii_uppercase
for i in range(0, len(Text)):
    if Text[i] in Alphabet:
        if Alphabet.index(Text[i]) <= 12:
            Result = Result + Alphabet[Alphabet.index(Text[i]) + 13]
        else:
            Result = Result + Alphabet[Alphabet.index(Text[i]) - 13]
    else:
        Result = Result + Text[i]
print(Result)

I support the Free Software Foundation. Protect our digital rights!

Offline

 

#5 2012-05-26 19:28:40

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Python ROT13 Decoder!

It's .upper() I believe  smile

Code:

print 'lowercase is uppercase'.upper()

Offline

 

#6 2012-05-26 19:29:20

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Python ROT13 Decoder!

Nope...  hmm  Wait, didn't you code all of DragonThunder in Python? Or was that Flash?

Offline

 

#7 2012-05-26 19:31:39

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Python ROT13 Decoder!

Well, Magnie made the mirror in Python, and I did some extra stuff for FireMMO compatibility (but Magnie get's most the credit)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#8 2012-05-26 19:44:02

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Python ROT13 Decoder!

Thank you so much Magnie! And thank you for your attempt to help me bobbybee, I appreciate your effort.

Offline

 

#9 2012-05-26 19:45:40

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Python ROT13 Decoder!

ImagineIt wrote:

Thank you so much Magnie! And thank you for your attempt to help me bobbybee, I appreciate your effort.

As I said, I'm not much of a Pythoner.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#10 2012-05-26 22:22:48

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Python ROT13 Decoder!

I edited the code to work nicer.

Last edited by ImagineIt (2012-05-26 22:23:01)

Offline

 

#11 2012-05-27 20:34:56

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Python ROT13 Decoder!

Bump.

Offline

 

#12 2012-05-27 22:19:20

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Python ROT13 Decoder!

Wait, wait, wait...  this sounds a LOT like CF4, which is made by me.  CF4 uses more If's, though...


http://i.imgur.com/BAEgGDL.png

Offline

 

#13 2012-05-27 23:28:19

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Python ROT13 Decoder!

GeonoTRON2000 wrote:

Wait, wait, wait...  this sounds a LOT like CF4, which is made by me.  CF4 uses more If's, though...

I thought of using that language once, but it's to easy to discover.

Offline

 

#14 2012-06-12 20:27:55

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Python ROT13 Decoder!

HwZms1


http://i.imgur.com/BAEgGDL.png

Offline

 

Board footer