]> code.delx.au - monosys/commitdiff
Psi password decoder
authorJames Bunton <jamesbunton@fastmail.fm>
Fri, 5 Oct 2007 02:32:49 +0000 (12:32 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Fri, 5 Oct 2007 02:32:49 +0000 (12:32 +1000)
scripts/psi-password.py [new file with mode: 0755]

diff --git a/scripts/psi-password.py b/scripts/psi-password.py
new file mode 100755 (executable)
index 0000000..3b4d34a
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# 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
+
+
+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 __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)
+