hello I wanted to prevent other users of my computers to read my files. So tried to creat a module to achieve it. I used a flag to deside which methods to be called on the object. somehow it is not working.I realise after 2 days of struggle that as it is usuel , I am blind to my faults. I tested all the metheds except main() in idle interactively,found them working. So there is a bug in the main(), kan anyone point it out to me?
<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[:1]=='flag1\n': ns='flag0\n' data=data[1:] for line in data: nl=__compress((__digi(__lengthen(line.strip()))))+'\n' ns+=nl dest.write(ns) elif data[:1]=='flag0\n': ns='flag1\n' data=data[1:] for line in data: nl=__decompress((__undigi(__shorten(line.strip()))))+'\n' ns+=nl dest.write(ns) 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>
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor