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

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Memory of Python


    hello all i am new in python community. i study python couple of months and i try to make to make a program with WxPython (GUI)
    program name : Crypter And Decrypter
    this is not something new there are a lot of copies in web so i would like to create mine
    all was very good in first try and the program works great the idea was to set an algorith like :
    read a text and then :
    'a'='0x'
    'b'='6s'
    ....
    ....
    so to encrypt the text...
    but that was kind of easy in decryption progress so i say to make it litle more complex.
    and the program was great too but then i discover something .. that the program was great only with small texts and crashing with big texts like : aDSAKJSFKLSABFHASKL HDFKLASKLDFKL NALSHFKLBKLWAJEFKLHDSKNFLHAKBSLJKHFRWHLFKHSDKLAHFKLHASKLDHFSKLADHFKLHASKLDHFLNAWJFHIDSHVUOHAISNFOU SDHFB AWNFIUSDIFHOASD I etc..

    so the questing is the problem is my program or the python has some errors with the memory and is crashing ?

    if someone want to check my program let me know if it is allowed to put a link here

    sorry about my bad english i am from Greece so pls be lenient




    you will new the image below because i use it in the program :
    http://img694.imageshack.us/img694/2461/hered.jpg
    for some reasons i can use the Insert Image button :P

    the code :


    Code:
    import wx
    # this def find the location of the (code or the message) letter 
    def location(x,letters):
            i = 0
            while True :
                    if x == letters[i]:
                            break
                    i = i + 1
                    if i == len(letters) and x != letters[i]:
                            return 0
            return i
    # this def just put the first item of the list to the end of the list 
    def algorith(codes):
            for i in range(0,len(codes)-1):
                    k=codes[i]
                    codes[i]=codes[i+1]
                    codes[i+1]=k
    
    
    # main program all inside here! ;)
    class main(wx.Frame):
        def __init__(self,parent,id):
    
            # Create Panel ( backGround )
            wx.Frame.__init__(self,parent,id,'Crypter & Decrypter',size = (805,628),style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)
            panel=wx.Panel(self)
            
            # take the image from the working directory
            image_file = 'here.jpg'
            bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
            # image's upper left corner anchors at panel coordinates (0, 0)
            self.bitmap1 = wx.StaticBitmap(self, -1, bmp1, (0, 0))
    
            # Create 3 buttons for Task Choice
            button1=wx.Button(self.bitmap1,label="Task  1",pos=(100 ,350),size=(100,50))
            button2=wx.Button(self.bitmap1,label="Task  2",pos=(270 ,350),size=(100,50))
            button3=wx.Button(self.bitmap1,label="Task  3",pos=(430 ,350),size=(100,50))
            self.Bind(wx.EVT_BUTTON,self.TextCryption,button1)
            self.Bind(wx.EVT_BUTTON,self.TextDecryption,button2)
            self.Bind(wx.EVT_BUTTON,self.closebutton,button3)
            
        # Close Button Def for button 3   
        def closebutton(self,event):
            self.Close(True)
                
        # def for event in button 1!
        def TextCryption(self,event):
            found=[]
            F=[]
            codes   = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
            letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
            box=wx.TextEntryDialog(None,"Just put your text below","Cryption progress","")
            if box.ShowModal()==wx.ID_OK:
                message = box.GetValue()
                cryption = ''
                for i in range(0,len(message)):
                    if message[i] in found :
                            F.append(i)
                            algorith(codes)
                    cryption = cryption + codes[location(message[i],letters)]
                    if message[i] not in found:
                            found.append(message[i])
                topothesia='' # topothesia = location in greek.. i just want to put in front of the code the location of the repeating letter and then XXXX for example
                              #  code will be : -1-5-10-20XXXXaksdkhqklhqw  this is useful for decryption because now i know that the code list has changed 4 times in
                              #                                                                                                              location 1,5,10 and 20 
                for i in range(0,len(F)):
                        topothesia=topothesia+'-'+str(F[i]) # put - and the location of the reapetable letter ( my english sucks :P )
                        
                topothesia=topothesia+'XXXX'
                cryption=topothesia+cryption
                box=wx.MessageDialog(None,"The code has Been Copied to the clipboard just Paste it somewhere",'Cryption Finished',wx.OK)
                answer=box.ShowModal()
                self.dataObj = wx.TextDataObject()
                self.dataObj.SetText(cryption)
                if wx.TheClipboard.Open():
                    wx.TheClipboard.SetData(self.dataObj)
                    wx.TheClipboard.Close()
                
        # def for event in button 2!
        def TextDecryption(self,event):
            found=[]
            codes   = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
            letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
            box=wx.TextEntryDialog(None,"Put the code Below For Decryption","Decryption progress","")
            if box.ShowModal()==wx.ID_OK:
                A=[]
                code = box.GetValue()
                for i in range(0,len(code)):
                        if code[i] =='X' and code[i+1] =='X' and code[i+2] =='X' and code[i+3] =='X':
                                for p in range(0,i): 
                                        l=''
                                        while code[p]!='-' and code[p] !='X': # i am taking only the numbers without '-'
                                                l=l+code[p]
                                                p=p+1      
                                        if l!='':
                                                A.append(int(l))
                                                if len(A)>1:
                                                        # i do this below because the code is puting more that i need ... for example if the code is -20-15-10 the program puts on A
                                                        # the 20 and 0 and 15 and 5 and 10 and 0 and i want only the 20 15 10 ;) i hope you understand
                                                        if A[len(A)-1] < A[len(A)-2]:
                                                                A.remove(A[len(A)-1])
                                A.sort()   # to make sure that all items are in the right order       
                                edw=[]
                                
                                for K in range(0,len(code)):
                                        edw.append(code[K])
                                code=''
                                for X in range(i+4,len(edw)):
                                        code=code+edw[X]
                                break
                decryption = ''
                m = 0
                q=0
                for i in range(0,(len(code)/2)): # len(code)/2 because one letter = 2 letters in cryption
                    if code[i+m:i+2+m] not in codes:
                            decryption='Wrong Code!' # if someone just something that's not in code list just print Wrong code ;)
                            break 
                    else:
                            if A !=[] and q < len(A):
                                    if i == int(A[q]):
                                            algorith(codes)
                                            q=q+1
                                    
                            decryption = decryption + letters[location(code[i+m:i+2+m],codes)]
                    m = m + 1
                box=wx.MessageDialog(None,decryption,'Decryption Finished',wx.OK)
                answer=box.ShowModal()
                
    if __name__=='__main__':
    
        app=wx.App()
        frame=main(parent=None,id=-1)
        frame.Show()
        app.MainLoop()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Not having wxpython, I extracted TextCryption from your program, not sure I faithfully reproduced it.
    Code:
    # this def find the location of the (code or the message) letter
    def location(x,letters):
        i = 0
        while not (i == len(letters) and x != letters[i]):
            if x == letters[i]:
                return i
            i += 1
        return 0
        
    
    # this def just put the first item of the list to the end of the list
    def algorith(codes):
        for i in range(0,len(codes)-1):
            k=codes[i]
            codes[i]=codes[i+1]
            codes[i+1]=k
    
    def TextCryption(message):
        found=[]
        F=[]
        codes   = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W  ','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0  ','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp  ','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
        letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B  ','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c  ','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
        cryption = ''
        for i in range(0,len(message)):
            if message[i] in found :
                F.append(i)
                algorith(codes)
            cryption += codes[location(message[i],letters)]
            if message[i] not in found:
                found.append(message[i])
        topothesia = ''
        for i in range(0,len(F)):
            topothesia+='-'+str(F[i])
        topothesia+='XXXX'
        cryption=topothesia+cryption
        return cryption
    Then I ran it on a particular sequence of letters:
    Code:
    >>> for a in string.ascii_letters:print a,p.TextCryption(a)
    ... 
    a XXXXww
    b XXXX1S
    c
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "p.py", line 28, in TextCryption
        cryption += codes[location(message[i],letters)]
      File "p.py", line 4, in location
        while not (i == len(letters) and x != letters[i]):
    IndexError: list index out of range
    >>>
    Your program failed at "c". Do you really mean to have extra spaces in your letters data?
    Code:
    ...','x','c  ','v','...
    There are several similar occurrences.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Strange.. mine work great with all letters and all numbers...
    let me post the code without WxPython commands...


    the code must be this :

    Code:
    def location(x,letters):
        i = 0
        while True :
            if x == letters[i]:
                break
            i = i + 1
            if i == len(letters) and x != letters[i]:
                return 0
        return i
    
    
    def algorith(codes):
        for i in range(0,len(codes)-1):
            k=codes[i]
            codes[i]=codes[i+1]
            codes[i+1]=k
    
    def TextCryption(message):
        
        codes   = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
        letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
        found=[]
        F=[]
        cryption = ''
        print len(message)
        for i in range(0,len(message)):
            if message[i] in found :
                F.append(i)
                algorith(codes)
            cryption = cryption + codes[location(message[i],letters)]
            if message[i] not in found:
                found.append(message[i])
        topothesia=''
        for i in range(0,len(F)):
            topothesia=topothesia+'-'+str(F[i]) 
        topothesia=topothesia+'XXXX'
        cryption=topothesia+cryption
        print cryption
        return
    
    
    def TextDecryption(code):
        found=[]
        codes   = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
        letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
        A=[]
        for i in range(0,len(code)):
            if code[i] =='X' and code[i+1] =='X' and code[i+2] =='X' and code[i+3] =='X':
                for p in range(0,i): 
                    l=''
                    while code[p]!='-' and code[p] !='X': 
                        l=l+code[p]
                        p=p+1      
                    if l!='':
                        A.append(int(l))
                        if len(A)>1:
                            if A[len(A)-1] < A[len(A)-2]:
                                A.remove(A[len(A)-1])
                A.sort()
                edw=[]
                for K in range(0,len(code)):
                    edw.append(code[K])
                code=''
                for X in range(i+4,len(edw)):
                    code=code+edw[X]
                break
        decryption = ''
        m = 0
        q=0
        for i in range(0,(len(code)/2)):
            if code[i+m:i+2+m] not in codes:
                decryption='Wrong Code!' 
                break 
            else:
                if A !=[] and q < len(A):
                    if i == int(A[q]):
                        algorith(codes)
                        q=q+1
                decryption = decryption + letters[location(code[i+m:i+2+m],codes)]
                m = m + 1
        print decryption
        return
    
    
    # main program
    
    task = '5'
    while task != '3' :
        task =raw_input("give task ( 1 for cryption , 2 for decryption ,3 to exit ): ")
        if task == '1' :
            message=raw_input("give your message:")
            TextCryption(message)
        elif task == '2' :
            code = raw_input("give the code here :")
            TextDecryption(code)

    Wait a sec... when i check the code to my PC all it is great.. but when i post it here and then take it back to check it again something fail with letter 'c' check the txt file below it have the code and tell me if it's works.. it should be good now.. take the code from the file no here..

    link for code :

    http://txtup.co/tjIac

    or

    http://textuploader.com/?p=6&id=tjIac
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    for some reason when i put the code here in ["code"] some letters take one or two spaces.. for example.. if you check the letter list you will see that the c letter is 'c ' instead of 'c' strange... hmm
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    1) As far as I can tell your location function is equivalent in this program to the index method. (Error type may differ, but you don't test this.)

    2) I inserted tests using increasing length of ascii letters in random order, testing that
    decrypt(encrypt(STRING))==STRING
    The test fails at a string length of 105.

    3) I have not yet duplicated the memory problem.

    Code:
    # http://textuploader.com/?p=6&id=tjIac
    def location(x,letters):
        return letters.index(x)
    
    def algorith(codes):
        for i in range(0,len(codes)-1):
            k=codes[i]
            codes[i]=codes[i+1]
            codes[i+1]=k
    
    def TextCryption(message):
        codes = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
        letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
        found=[]
        F=[]
        cryption = ''
        for i in range(0,len(message)):
            if message[i] in found :
                F.append(i)
                algorith(codes)
            cryption = cryption + codes[location(message[i],letters)]
            if message[i] not in found:
                found.append(message[i])
        topothesia=''
        for i in range(0,len(F)):
            topothesia=topothesia+'-'+str(F[i])
        topothesia=topothesia+'XXXX'
        cryption=topothesia+cryption
        return cryption
    
    def TextDecryption(code):
        found=[]
        codes   = ['Bp','Pc','{a','[A',']s','}s','S:','"s','d;',';x',';X','<s','S>',':)',':P',':d',':(','G^','j&','l@','@l','p$','F!','!F','(D',')D','A$','$A','%A','A%','u*','A0','4A','9C','9F','4Q','5(','4K','9W','WW','X4','0S','0)','XX','V8','7W','W7','QQ','9Q','SS','AZ','XP','1^','1V','0B','C0','0A','0a','a0','4a','9c','9f','4q','54','4k','9w','ww','x4','0s','09','xx','v8','7w','w7','qq','9q','ss','aZ','xp','1S','1v','0b','c0','00','s1','1s','s2','2s','s3','3s','s4','4s','s5','5s']
        letters = ['\'','\\','[','{','}',']','|',';',':','"',',','<','.','>','/','?','!','@','#','$','%','^','&','*','(',')','_','-','=','+','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','Q','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',' ','0','1','2','3','4','5','6','7','8','9']
        A=[]
        for i in range(0,len(code)):
            if code[i] =='X' and code[i+1] =='X' and code[i+2] =='X' and code[i+3] =='X':
                for p in range(0,i):
                    l=''
                    while code[p]!='-' and code[p] !='X':
                        l=l+code[p]
                        p=p+1
                    if l!='':
                        A.append(int(l))
                        if len(A)>1:
                            if A[len(A)-1] < A[len(A)-2]:
                                A.remove(A[len(A)-1])
                A.sort()
                edw=[]
                for K in range(0,len(code)):
                    edw.append(code[K])
                code=''
                for X in range(i+4,len(edw)):
                    code=code+edw[X]
                break
        decryption = ''
        m = 0
        q=0
        for i in range(0,(len(code)/2)):
            if code[i+m:i+2+m] not in codes:
                decryption='Wrong Code!'
                break
            else:
                if A !=[] and q < len(A):
                    if i == int(A[q]):
                        algorith(codes)
                        q=q+1
                decryption = decryption + letters[location(code[i+m:i+2+m],codes)]
                m = m + 1
        return decryption
    
    def main():
        task = '5'
        while task != '3' :
            task =raw_input("give task ( 1 for cryption , 2 for decryption ,3 to exit ): ")
            if task == '1' :
                message=raw_input("give your message:")
                print(TextCryption(message))
            elif task == '2' :
                code = raw_input("give the code here :")
                print(TextDecryption(code))
    
    if '__main__' == __name__:
        import random,string,sys
        i = 0
        L = 26
        A = string.ascii_letters*10
        for L in range(100,208):
            sys.stdout.write('string length: %d'%L)
            B = list(A[:L])
            random.shuffle(B)
            sys.stdout.write(' to encrypt')
            C = TextCryption(B)
            sys.stdout.write(' to decrypt')
            D = TextDecryption(C)
            sys.stdout.write('\n')
            SB = ''.join(B)
            SD = ''.join(D)
            try:
                assert SB == SD
            except:
                if (len(SB) < 500) and (len(SD) < 500):
                    print(SB)
                    print(SD)
                if len(SB) != len(SD):
                    print('lengths differ')
                for (I,(E,F,)) in enumerate(zip(SB,SD,)):
                    if E != F:
                        print('differ on character %d\n'%I)
                        raise
                raise
    
    if '__main__' == __name__:
        import random,string,sys
        i = 0
        L = 26
        A = string.ascii_letters[:]
        while L < 50*1000*1000:
            L = len(A)
            sys.stdout.write('string length: %d'%L)
            B = list(A)
            random.shuffle(B)
            sys.stdout.write(' to encrypt')
            C = TextCryption(B)
            sys.stdout.write(' to decrypt')
            D = TextDecryption(C)
            sys.stdout.write('\n')
            SB = ''.join(B)
            SD = ''.join(D)
            try:
                assert SB == SD
            except:
                if (len(SB) < 500) and (len(SD) < 500):
                    print(SB)
                    print(SD)
                if len(SB) != len(SD):
                    print('lengths differ')
                for (I,(E,F,)) in enumerate(zip(SB,SD,)):
                    if E != F:
                        print('differ on character %d\n'%I)
                        raise
                raise
            A *= 2
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    so if i have understand right there is a problem with my code ..
    i thought that memory of python has error and that's why the program crash.. i will try to check your code .. as i said i am studying python only couple of months :P so i hope to understand it thx you for your help!

    ( My english sucks i know :P )

    edit :


    Code:
    if '__main__' == __name__:
        import random,string,sys
        i = 0
        L = 26
        A = string.ascii_letters[:]
        while L < 50*1000*1000:
            L = len(A)
            sys.stdout.write('string length: %d'%L)
            B = list(A)
            random.shuffle(B)
            sys.stdout.write(' to encrypt')
            C = TextCryption(B)
            sys.stdout.write(' to decrypt')
            D = TextDecryption(C)
            sys.stdout.write('\n')
            SB = ''.join(B)
            SD = ''.join(D)
            try:
                assert SB == SD
            except:
                if (len(SB) < 500) and (len(SD) < 500):
                    print(SB)
                    print(SD)
                if len(SB) != len(SD):
                    print('lengths differ')
                for (I,(E,F,)) in enumerate(zip(SB,SD,)):
                    if E != F:
                        print('differ on character %d\n'%I)
                        raise
                raise
            A *= 2

    ok i got what you are doing but i can't understand why are you doing all this?
    let's see if have understand all right :
    first you put on A list a lot of letters letters ( 520 len) and then you take a B list with only 24 of them.. ( all letters ) then you shuffle it and then you create two list on with the cryption of the letters and the other one with decryption of the letters and then you check if they had the same lenght? of course the don't.. because one letters in cryption = 2 letters in decryption..
    hmmm i didn't get it... but i would think about it i sure that i will understand.. give me some time :P


    the point is that the problem is with my code! so i will find it ! thx again for your help! and thx for this command : list.index(element) i didn't know that very useful!!!

IMN logo majestic logo threadwatch logo seochat tools logo