#!/usr/bin/env python # Decrypts the Tom-Skype 3.6.x - 4.2.x era keyfiles and outputs them in UTF-8 # Jeffrey Knockel jeffk cs unm edu # Usage: python decrypt.py < keyfile > plainfile import random import struct import sys def decrypt(hexcrypt): crypt = [int(hexcrypt[i:i + 2], 16) for i in range(0, len(hexcrypt), 2)] return b''.join(struct.pack('B', ((b ^ 0x68) - a) % 255) for a, b in zip(crypt, crypt[1:])) def encrypt(plain, nonce=None): if nonce is None: nonce = random.randint(0, 0xff) crypt = [nonce] for p in bytearray(plain.encode('ascii')): crypt.append(((p + crypt[-1]) % 255) ^ 0x68) return ''.join('%.2X' % c for c in crypt) def main(): if hasattr(sys.stdout, 'buffer'): sys.stdout = sys.stdout.buffer for lineno, line in enumerate(sys.stdin): stripped = line.strip('\0\t\n\x0b\x0c\r ') if stripped: try: plain = decrypt(stripped).decode('gbk').encode('utf-8') except Exception: sys.stderr.write('Error decrypting line %d\n' % (lineno + 1)) else: sys.stdout.write(plain + b'\n') if __name__ == '__main__': main()