Support Forums
Rot-13 Encrypter/Decrypter - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: Rot-13 Encrypter/Decrypter (/showthread.php?tid=3180)



Rot-13 Encrypter/Decrypter - nevets04 - 11-28-2009

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()



RE: Rot-13 Encrypter/Decrypter - Fallen - 11-28-2009

cool script, but you could have just done

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



RE: Rot-13 Encrypter/Decrypter - nevets04 - 11-28-2009

aww. Just realized there something wrong with the decrypt part. It's late, I'll have to fix it tommorow.


RE: Rot-13 Encrypter/Decrypter - nevets04 - 11-28-2009

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


RE: Rot-13 Encrypter/Decrypter - J4P4NM4N - 11-28-2009

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!


RE: Rot-13 Encrypter/Decrypter - nevets04 - 11-28-2009

(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


RE: Rot-13 Encrypter/Decrypter - manipulate - 12-03-2009

(11-28-2009, 12:55 AM)Fallen Wrote: cool script, but you could have just done

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

lold


RE: Rot-13 Encrypter/Decrypter - nevets04 - 12-03-2009

(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.


RE: Rot-13 Encrypter/Decrypter - J4P4NM4N - 12-05-2009

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.