[Tutor] flag to call methods on objects?

prasad rao prasadaraon50 at gmail.com
Fri Jul 31 06:29:54 CEST 2009


hello
 I removed the bugs.But still getting error report.


>>import mcript

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    import mcript
  File "C:\Python26\mcript.py", line 78, in <module>
    a.main()
  File "C:\Python26\mcript.py", line 58, in main
    nl=__compress(__digi(__lengthen(line.strip())))+'\n'
NameError: global name '_Cripto__compress' is not defined

There is no string  '_Cripto__compress'  any whare in the script.

So I dont know what corrections Ineed to make in the script.

I am giving my code below again again .

<code>

#! usr/bin/env python

import ast,random,os,zlib,string
key=5
class Cripto(object):
    def __init__(self,afile):
        self.afile=afile
    def __digi(self,astring):
        y=[]
        for x in astring:
            y.append(ord(x))
        y=str(y)

        return y
    def __undigi(self,astring):

        alist=ast.literal_eval(astring)
        y=[]
        for x in alist:
            y.append(chr(x))
        astring=''.join(y)
        return astring
    def __gen_string(self):
        s=''
        nl=random.sample(string.ascii_letters,key)
        for x in nl:s+=x
        return s

    def __lengthen(self,astring):
         s=list(astring)
         ns=''
         for x in s:
             ns+=x
             ns+=gen_string()
         return ns
    def __shorten(self,astring):

         s=list(astring)
         ns=''
         for x in range(0,len(s),key+1):
            ns+=s[x]
        return ns
    def __compress(self,astring):
        astring=zlib.compress(astring)
        return astring
    def __decompress(self,astring):
        astring=zlib.decompress(astring)
        return astring
    def main(self):
        sorce=open(self.afile,'r')
        data=(sorce.readlines())
        dest=open((os.path.split(self.afile)[0]+os.sep+'temp'),'w')
        if (data[0]).strip()=='flag1':

            ns='flag0\n'
            data=data[1:]
            for line in data:
               nl= __compress(__digi(__lengthen(line.strip())))+'\n'
               ns+=nl
            dest.write(ns)
        elif data[0].strip()=='flag0':
            ns='flag1\n'
            data=data[1:]
            for line in data:
                nl= __shorten((__undigi(__decompress(line.strip()))))+'\n'
                ns+=nl
            dest.write(ns)
        else:prind 'File does not begin with the flag'

        sorce.close()
        dest.close()

        os.remove(self.afile)
        os.rename((os.path.split(self.afile)[0]+os.sep+'temp'),self.afile)


#========
a=Cripto('C:/pp.txt')
a.main()

<\code>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090731/436f6bbd/attachment.htm>


More information about the Tutor mailing list