Support Forums

Full Version: Rot-13 Encrypter/Decrypter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
def rot(a):
    e = list(a)
    q = len(e)
    z = 0
    w = []
    while z < q:
        b = ord(a[z:z+1])
        z = z + 1
        c = b+13
        d = chr(c)
        r = chr(b-13)
        if c <= 122 and c > 96:
            w.append(d)
        elif c > 122:
            w.append(r)
        else: w.append(' ')
    print "".join(w)
    raw_input("Press Enter To Continue")
    menu()




def unrot(a):
    e = list(a)
    q = len(e)
    z = 0
    w = []
    while z < q:
        b = ord(a[z:z+1])
        z = z + 1
        c = b-13
        d = chr(c)
        r = chr(b+13)
        if c <= 122 and c > 96:
            w.append(d)
        elif c > 122:
            w.append(r)
        else: w.append(' ')
    print "".join(w)
    raw_input("Press Enter To Continue")
    menu()
def menu():
    print "1) Encrypt"
    print "2) Decrypt"
    u = (raw_input("What do you want to do?: "))
    if u == '1': rot(raw_input("What do you want to encrypt?: "))
    elif u == '2': unrot(raw_input("What do you want to encrypt?: "))
    else:
        print "Invalid"
        raw_input("Press Enter To Continue")
        menu()
menu()
cool script, but you could have just done

Code:
print raw_input("Text: ").encode("rot13")
aww. Just realized there something wrong with the decrypt part. It's late, I'll have to fix it tommorow.
Fixed:

Code:
def rot(a):
    e = list(a)
    q = len(e)
    z = 0
    w = []
    while z < q:
        b = ord(a[z:z+1])
        z = z + 1
        c = b+13
        d = chr(c)
        r = chr(b-13)
        if c <= 122 and c > 96:
            w.append(d)
        elif c > 122:
            w.append(r)
        else: w.append(' ')
    print "".join(w)
    raw_input("Press Enter To Continue")
    menu()




def unrot(a):
    e = list(a)
    q = len(e)
    z = 0
    w = []
    while z < q:
        b = ord(a[z:z+1])
        z = z + 1
        c = b+13
        d = chr(c)
        r = chr(b-13)
        if c <= 122 and c > 96:
            w.append(d)
        elif c > 122:
            w.append(r)
        else: w.append(' ')
    print "".join(w)
    raw_input("Press Enter To Continue")
    menu()
def menu():
    print "1) Encrypt"
    print "2) Decrypt"
    u = (raw_input("What do you want to do?: "))
    if u == '1': rot(raw_input("What do you want to encrypt?: "))
    elif u == '2': unrot(raw_input("What do you want to encrypt?: "))
    else:
        print "Invalid"
        raw_input("Press Enter To Continue")
        menu()
menu()

and
elif u == '2': unrot(raw_input("What do you want to encrypt?: "))
should be
elif u == '2': unrot(raw_input("What do you want to decrypt?: "))
not really a big deal though
Nice, dude.

One time, when I was learning to code programs to communicate over TCP/IP, I wrote a server that took in text, encoded in rot13, then spat out the encrypted text. That's all it did because I was just proving to myself I could accomplish communications across computers in my programs. Isn't rot13 fun? Just encrypting something twice decrypts it!
(11-28-2009, 10:56 PM)J4P4NM4N Wrote: [ -> ]Nice, dude.

One time, when I was learning to code programs to communicate over TCP/IP, I wrote a server that took in text, encoded in rot13, then spat out the encrypted text. That's all it did because I was just proving to myself I could accomplish communications across computers in my programs. Isn't rot13 fun? Just encrypting something twice decrypts it!

Yeah, the decryptor was a lot easier then I thought it was going to be Big Grin
(11-28-2009, 12:55 AM)Fallen Wrote: [ -> ]cool script, but you could have just done

Code:
print raw_input("Text: ").encode("rot13")

lold
(12-03-2009, 03:50 AM)iintens Wrote: [ -> ]lold

I knew about the function, but I was practicing using chr and ord, and this was the only thing I could think of.
It is commendable; I usually like doing things the longer way in order to figure them out. Now nevets04 will feel more empowered with using that function and will know exactly what it does. It's just the curious hacker mindset.