import random import sys def unmunge(c, n): assert c != 0x81 c -= n if 0 <= c <= 25: return ord('A') + c elif 26 <= c <= 31: return ord('4') + c - 26 else: raise Exception('Character out of range') def construct(version, dst): version ^= 0x3b3 dst[15] = (version >> 14) & 0x7f dst[16] = (version >> 7) & 0x7f dst[17] = version & 0x7f dst[15] ^= dst[0] ^ dst[3] ^ dst[6] ^ dst[9] ^ dst[12] dst[16] ^= dst[1] ^ dst[4] ^ dst[7] ^ dst[10] ^ dst[13] dst[17] ^= dst[2] ^ dst[5] ^ dst[8] ^ dst[11] ^ dst[14] lookup_inv = [0x08, 0x5B, 0x5F, 0x49, 0x1C, 0x3F, 0x41, 0x1B, 0x4D, 0x22, 0x3D, 0x5A, 0x2C, 0x20, 0x15, 0x13, 0x3C, 0x6E, 0x0A, 0x7D, 0x71, 0x66, 0x6F, 0x61, 0x32, 0x6D, 0x57, 0x76, 0x35, 0x59, 0x63, 0x73, 0x11, 0x52, 0x16, 0x02, 0x1F, 0x1D, 0x25, 0x10, 0x09, 0x0B, 0x64, 0x6B, 0x0F, 0x51, 0x4B, 0x47, 0x5C, 0x2F, 0x70, 0x39, 0x5E, 0x05, 0x5D, 0x07, 0x4A, 0x7B, 0x7A, 0x69, 0x75, 0x06, 0x33, 0x3E, 0x17, 0x65, 0x54, 0x42, 0x04, 0x45, 0x1E, 0x2A, 0x4F, 0x26, 0x14, 0x30, 0x72, 0x01, 0x62, 0x58, 0x3A, 0x55, 0x6C, 0x24, 0x74, 0x1A, 0x27, 0x77, 0x2D, 0x50, 0x38, 0x12, 0x31, 0x68, 0x4C, 0x00, 0x40, 0x6A, 0x2B, 0x29, 0x34, 0x46, 0x4E, 0x03, 0x53, 0x0D, 0x0C, 0x28, 0x67, 0x7F, 0x0E, 0x7E, 0x23, 0x7C, 0x19, 0x3B, 0x21, 0x60, 0x79, 0x44, 0x36, 0x2E, 0x37, 0x43, 0x56, 0x48, 0x78, 0x18] for i in range(18): dst[i] += dst[(i+1) % 18] + i*3 dst[i] %= 128 dst[i] = lookup_inv[dst[i]] for n in range(18,26): dst[n] = 0 for n in range(0,18): key = 32 * (dst[n] // 32) dst[n] = unmunge(dst[n], key) ctr = 2*n if key & (1 << 5): dst[ctr // 5 + 18] |= 1 << (ctr % 5) if key & (1 << 6): dst[(ctr+1) // 5 + 18] |= 1 << ((ctr+1) % 5) for n in range(18, 26): dst[n] = unmunge(dst[n], 0) perm_table = [14, 3, 5, 11, 8, 9, 12, 25, 4, 13, 22, 16, 2, 10, 6, 24, 0, 21, 19, 1, 20, 17, 23, 7, 15, 18] dst = [dst[perm_table[i]] for i in range(len(dst))] return dst def generate(name, grace='a', version=1014): chars = ['\x00', '\x20', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67', '\x68', '\x69', '\x6A', '\x6B', '\x6C', '\x6D', '\x6E', '\x6F', '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77', '\x78', '\x79', '\x7A', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47', '\x48', '\x49', '\x4A', '\x4B', '\x4C', '\x4D', '\x4E', '\x4F', '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57', '\x58', '\x59', '\x5A', '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37', '\x38', '\x39', '\xCB', '\xE7', '\xE5', '\xCC', '\x80', '\x81', '\xAE', '\x82', '\xE9', '\x83', '\xE6', '\xE8', '\xED', '\xEA', '\xEB', '\xEC', '\x3F', '\x84', '\xF1', '\xEE', '\xEF', '\xCD', '\x85', '\xD8', '\xAF', '\xF4', '\xF2', '\xF3', '\x86', '\x3F', '\x3F', '\xA7', '\x88', '\x87', '\x89', '\x8B', '\x8A', '\x8C', '\xBE', '\x8D', '\x8F', '\x8E', '\x90', '\x91', '\x93', '\x92', '\x94', '\x95', '\x3F', '\x96', '\x98', '\x97', '\x99', '\x9B', '\x9A', '\x2D', '\xBF', '\x9D', '\x9C', '\x9E', '\x9F', '\x3F', '\x3F'] assert len(name) <= 13, 'Name cannot be longer than 13 characters' for c in name: assert c in chars, 'Name contains invalid character: ' + c padding = ''.join([random.choice(chars) for _ in range(13 - len(name))]) skeleton = name + '\x00' + padding + grace + '\x00'*3 + '\x00'*8 skeleton_indices = [chars.index(c) for c in skeleton] serial_ords = construct(version, skeleton_indices) serial = ''.join([chr(n) for n in serial_ords]) return serial if len(sys.argv) == 2: name = sys.argv[1] else: name = 'rufo' print( 'ColorPerfect v2.22 keygen by rufo') print( 'Using name: ' + name + '\n' ) for (v_name, v_id) in [('English - Windows', 1014), ('English - Mac', 879), ('German - Windows', 477), ('German - Mac', 492)]: serial = generate(name, version=v_id) print( serial + ' (' + v_name + ')') |