]> code.delx.au - monosys/blobdiff - scripts/psi-password.py
python2 and tabs to spaces
[monosys] / scripts / psi-password.py
index 3b4d34a083e6a2d0f50a5819d15b9ada3b6bd249..d662159719ea06481e7112678be894f33a17e8cf 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python2
 # Copyright 2007 James Bunton <jamesbunton@fastmail.fm>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 # Decodes a password taken from a Psi config.xml file
@@ -7,33 +7,33 @@
 import sys
 
 def decodePassword(passwd, key):
-       if not key:
-               return passwd
-       
-       result = ""
-       n1 = n2 = 0
-       while n1 < len(passwd):
-               x = 0
-               if n1 + 4 > len(passwd):
-                       break
-               x += int(passwd[n1+0], 16) * 4096
-               x += int(passwd[n1+1], 16) * 256
-               x += int(passwd[n1+2], 16) * 16
-               x += int(passwd[n1+3], 16) * 1
-               result += chr(x ^ ord(key[n2]))
-               n1 += 4
-               n2 += 1
-               if n2 >= len(key):
-                       n2 = 0
-       
-       return result
+    if not key:
+        return passwd
+    
+    result = ""
+    n1 = n2 = 0
+    while n1 < len(passwd):
+        x = 0
+        if n1 + 4 > len(passwd):
+            break
+        x += int(passwd[n1+0], 16) * 4096
+        x += int(passwd[n1+1], 16) * 256
+        x += int(passwd[n1+2], 16) * 16
+        x += int(passwd[n1+3], 16) * 1
+        result += chr(x ^ ord(key[n2]))
+        n1 += 4
+        n2 += 1
+        if n2 >= len(key):
+            n2 = 0
+    
+    return result
 
 if __name__ == "__main__":
-       try:
-               passwd = sys.argv[1]
-               key = sys.argv[2]
-       except:
-               print >> sys.stderr, "Usage: %s passwd jid" % sys.argv[0]
-               sys.exit(1)
-       print decodePassword(passwd, key)
+    try:
+        passwd = sys.argv[1]
+        key = sys.argv[2]
+    except:
+        print >> sys.stderr, "Usage: %s passwd jid" % sys.argv[0]
+        sys.exit(1)
+    print decodePassword(passwd, key)