Thread: SyntaxError
View Single Post
Old 10-03-2012, 12:20 PM   PM User | #1
smarty
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
smarty is an unknown quantity at this point
SyntaxError

I need assistance with Python Programming
I need apply the XOR operation to file on a particular keyword. I found the function:
Code:
def xor(fileTarget, key): 
   fileTarget = fileTarget + os.listdir(fileTarget)[0] 
  
   ifile = os.path.split(fileTarget)[0]+"/xor.in" 
   ofile = os.path.split(fileTarget)[0]+"/xor.out" 
   os.rename(fileTarget, ifile) 
  
   if os.path.isfile(key): 
      kf = open(key) 
      keyData = kf.read() 
      kf.close() 
   else: 
      keyData = key 
  
   e = open(ofile, "w") 
   f = open(ifile, "r") 
  
   bytesToCopy = os.stat(os.path.split(fileTarget)[0]+"/xor.in")[6] 
  
   while bytesToCopy: 
  
      if bytesToCopy > = len(keyData): 
         data = f.read(len(keyData)) 
         bytesToCopy -= len(keyData) 
         encryptedData = ''.join([chr(ord(data[i])^ord(keyData[i])) for i in xrange(len(data))]) 
         # encryptedData = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key))) 
         e.write(encryptedData) 
  
      else: 
         data = f.read(bytesToCopy) 
         bytesToCopy = 0 
         encryptedData = ''.join([chr(ord(data[i])^ord(keyData[i])) for i in xrange(len(data))]) 
         # encryptedData = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key))) 
         e.write(encryptedData) 
   os.remove(ifile) 
  
   e.close() 
   f.close() 
  
   return os.path.split(fileTarget)[0]+"/xor.out"
I run it in the terminal Ubuntu 12.04 LTS and get error "SyntaxError: invalid syntax". Error causes a semicolon on line 22 ( if bytesToCopy > = len(keyData): ). I tried to add and remove spaces, remove the semicolon - does not help.
What is wrong?
TIA

Last edited by smarty; 10-03-2012 at 12:31 PM..
smarty is offline   Reply With Quote