Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rot-13 Encrypter/Decrypter
#1
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()
Reply
#2
cool script, but you could have just done

Code:
print raw_input("Text: ").encode("rot13")
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply
#3
aww. Just realized there something wrong with the decrypt part. It's late, I'll have to fix it tommorow.
Reply
#4
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
Reply
#5
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!
Reply
#6
(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
Reply
#7
(11-28-2009, 12:55 AM)Fallen Wrote: cool script, but you could have just done

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

lold
[Completely Honest. Seriously.]

Protip: Anonymous Reputation Points are for Pussies
Reply
#8
(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.
Reply
#9
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.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)