#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Python code - Can you break?


    Hi guys,
    so here is my python code:

    Code:
    from sys import argv
     
    def decript(password,itens):
            file = open(itens,"r")
            text = file.read()
            file.close()
            tarray = text.split(" ")
            counter = 0
            counter2 = 0
            while counter < len(tarray):
                    tarray[counter] = int(tarray[counter])
                    tarray[counter] += 127
                    tarray[counter] -= ord(password[counter2])
                    tarray[counter] = chr(tarray[counter])
                    counter += 1
                    if counter2 == len(password)-1:
                            counter2 = 0
                    else:
                            counter2 += 1
            file = open(itens.replace(".cr",""),"w")
            file.write("".join(tarray))
            file.close()
     
    def cript(password,itens):
            file = open(itens,"r")
            text = file.read()
            file.close()
            tarray = []
            for item in text:
                    tarray.append(ord(item))
            counter = 0
            counter2 = 0
            while counter < len(tarray):
                    tarray[counter] += ord(password[counter2])
                    tarray[counter] -= 127
                    tarray[counter] = str(tarray[counter])
                    counter += 1
                    if counter2 == len(password)-1:
                            counter2 = 0
                    else:
                            counter2 += 1
            file = open(itens+".cr","w")
            file.write(chr(32).join(tarray))
            file.close()
    Usage:
    cript(arg1,arg2)
    arg1 = Password
    arg2 = location of text (folder/text.txt)
    same of decript.

    Its very simple,this is my first code and i want to know if you guys think this is safe to use.

    and here is a code:
    Code:
    94 91 32 80 68 83 84 33 10 90 19 96 85 99 79 13 84 71 108 42 24 51 26 26 36 94 69 177 144 -50 91 105 19 86 94 98 95 13 92 6 92 125 106 37 87 97 29 15 28 62 -16
    can u guys break it following the source code?
    Thanks!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Your code is basically a polyalphabetic cipher, the most famous version of this is the vigenere cipher.

    It might keep secrets from your kid sister, but if your encrypted messages are somewhat longer (or there are enough encrypted messages samples), the key can be broken (it was famously broken by Charles Babbage, who later went on to pioneer the idea of the modern computer). If you look at the link I posted about the vigenere cipher above, you'll see a method on how to break it (alternatively, you could read a book called The Code Book by Simon Singh, which goes into the development of cryptography and also shows how to break some polyalphabetic ciphers in great detail.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo