├── lxpy ├── encrypt │ ├── md5.py │ ├── hmac.py │ ├── des.py │ ├── rc4.py │ ├── aes.py │ ├── rsa.py │ └── serpent.py ├── __init__.py ├── setup.py ├── js.py ├── lxtools.py ├── tracks.py ├── lxml_check.py ├── lxheader.py ├── cipher.py ├── encoding.py └── lxdate.py └── README.md /lxpy/encrypt/md5.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author : lx 3 | # @IDE :PyCharm 4 | import hashlib 5 | # md5 6 | def get_md5(string): 7 | m = hashlib.md5() 8 | m.update(string.encode()) 9 | return m.hexdigest() 10 | 11 | -------------------------------------------------------------------------------- /lxpy/encrypt/hmac.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author : lx 3 | # @IDE :PyCharm 4 | 5 | import hmac 6 | import hashlib 7 | # hmac 8 | def get_hamc(key,text,model=hashlib.sha256): 9 | key = key.encode() 10 | texts = text.encode() 11 | mac = hmac.new(key, texts, model) 12 | mac.digest() 13 | return mac.hexdigest() 14 | -------------------------------------------------------------------------------- /lxpy/__init__.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : lx 3 | 4 | __all__ = ['DateGo','create_root_node','get_ua','re_xpath', 5 | 'copy_headers_dict','html_format','jsonp_to_json'] 6 | 7 | 8 | from .lxdate import DateGo 9 | from .lxml_check import create_root_node 10 | from .lxheader import * 11 | from .lxtools import * 12 | 13 | -------------------------------------------------------------------------------- /lxpy/setup.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : lx 3 | 4 | from distutils.core import setup 5 | 6 | 7 | setup( 8 | name = 'lxpy', 9 | version = '1.2.0', 10 | py_modules = ['lxpy'], 11 | author = 'ying5338619', 12 | author_email = '125066648@qq.com', 13 | url='https://github.com/lixi5338619/lxpy.git', 14 | install_requires=["wheel"], 15 | description = 'Web crawler and data processing toolkit !' 16 | ) 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lxpy 2 | Web crawler and data processing toolkit ! 3 | 4 | pypi: https://pypi.org/project/lxpy/ 5 | 6 | 安装方法: pip install lxpy 7 | 8 | 如果下载最新版本失败的话,换其他国内下载源试试。 9 | 10 | --- 11 | 12 | 主要还是一些小工具吧,想起来什么常用的就添加一下。 13 | 14 | lxdata : 处理时间的文件 15 | 16 | lxheader:headers的转换及生成 17 | 18 | lxtools:jsonp转json、html去除标签、xpath的正则 19 | 20 | --- 21 | 22 | 23 | **LXPY 1.3.0** 24 | 25 | 新增了加密算法和编码的加解密 26 | 27 | 新增了一些密码算法 28 | 29 | 新增了一些解析方法 30 | 31 | 新增了js还原方法 32 | -------------------------------------------------------------------------------- /lxpy/encrypt/des.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Time : 2021/12/28 12:29 3 | # @Author : lx 4 | # @IDE :PyCharm 5 | 6 | import binascii 7 | from pyDes import des, CBC, PAD_PKCS5 8 | # DES 9 | def des_encrypt(secret_key, s): 10 | iv = secret_key 11 | k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5) 12 | en = k.encrypt(s, padmode=PAD_PKCS5) 13 | return binascii.b2a_hex(en) 14 | 15 | def des_decrypt(secret_key, s): 16 | iv = secret_key 17 | k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5) 18 | de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5) 19 | return de 20 | 21 | #secret_str = des_encrypt('999', 'lx-message') 22 | #clear_str = des_decrypt('999', secret_str) 23 | -------------------------------------------------------------------------------- /lxpy/js.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author : lx 3 | # @IDE :PyCharm 4 | 5 | # 将js中的 eval 压缩加密的代码还原成压缩前的代码 6 | def parse_evaljs(s): 7 | import re 8 | x = r"\}\(('(?:[^'\\]|\\.)*') *, *(\d+) *, *(\d+) *, *'((?:[^'\\]|\\.)*)'\.split\('\|'\) *, *(\d+) *, *(\{\})" 9 | p, a, c, k, e, d = re.findall(x, s)[0] 10 | p, a, c, e, k, d = eval(p), int(a), int(c), int(e), k.split('|'), {} 11 | def evaljs_code(p, a, c, k, e, d): 12 | def e(c): 13 | x = '' if c < a else e(int(c/a)) 14 | c = c % a 15 | return x + (chr(c + 29) if c > 35 else '0123456789abcdefghijklmnopqrstuvwxyz'[c]) 16 | for i in range(c): d[e(i)] = k[i] or e(i) 17 | return re.sub(r'\b(\w+)\b', lambda e: d.get(e.group(0)) or e.group(0), p) 18 | return evaljs_code(p, a, c, k, e, d) 19 | -------------------------------------------------------------------------------- /lxpy/encrypt/rc4.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Time : 2021/12/28 12:34 3 | # @Author : lx 4 | # @IDE :PyCharm 5 | 6 | import base64 7 | def rc4(text, key = b'default-key', mode = "encode"): 8 | if mode == "decode": text = base64.b64decode(text) 9 | S = list(range(256)) 10 | j = 0 11 | for i in range(256): 12 | j = (j + S[i] + key[i%len(key)]) % 256 13 | S[i], S[j] = S[j], S[i] 14 | i, j = 0, 0 15 | R = [] 16 | for c in text: 17 | i = (i + 1) % 256 18 | j = (j + S[i]) % 256 19 | S[i], S[j] = S[j], S[i] 20 | t = c ^ (S[(S[i] + S[j]) % 256]) 21 | R.append(t) 22 | if mode == "encode": return base64.b64encode(bytes(R)) 23 | return bytes(R) 24 | 25 | #text = '123'.encode() 26 | #key = '123'.encode() 27 | #encd = rc4(text,key,mode='encode');print(encd) 28 | #decd = rc4(encd,key,mode='decode');print(decd) 29 | -------------------------------------------------------------------------------- /lxpy/encrypt/aes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Time : 2021/12/28 12:29 3 | # @Author : lx 4 | # @IDE :PyCharm 5 | 6 | 7 | import base64 8 | from Crypto.Cipher import AES 9 | # AES 10 | # 需要补位,str不是16的倍数那就补足为16的倍数 11 | def add_to_16(value): 12 | while len(value) % 16 != 0: 13 | value += '\0' 14 | return str.encode(value) # 返回bytes 15 | 16 | # 加密方法 17 | def aes_encrypt(key, text): 18 | aes = AES.new(add_to_16(key), AES.MODE_ECB) # 初始化加密器 19 | encrypt_aes = aes.encrypt(add_to_16(text)) # 先进行aes加密 20 | encrypted_text = str(base64.encodebytes(encrypt_aes), encoding='utf-8') 21 | return encrypted_text 22 | 23 | # 解密方法 24 | def aes_decrypt(key, text): 25 | aes = AES.new(add_to_16(key), AES.MODE_ECB) # 初始化加密器 26 | base64_decrypted = base64.decodebytes(text.encode(encoding='utf-8')) 27 | decrypted_text = str(aes.decrypt(base64_decrypted), encoding='utf-8').replace('\0', '') # 执行解密密并转码返回str 28 | return decrypted_text 29 | 30 | 31 | -------------------------------------------------------------------------------- /lxpy/lxtools.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author : lx 3 | 4 | import re 5 | 6 | def html_format(string): 7 | """ html去除标签 """ 8 | dr = re.compile(r'<[^>]+>', re.S) 9 | not_format = dr.sub('', string) 10 | return not_format 11 | 12 | 13 | def jsonp_to_json(jsonp): 14 | result = re.findall(r'\w+[(]{1}(.*)[)]{1}',jsonp,re.S) 15 | return result 16 | 17 | 18 | def re_xpath(node,compile): 19 | """ 20 | :param compile: './/span[re:match(@class, "allstar(\d0)")]/@class' 21 | """ 22 | namespaces = {"re": "http://exslt.org/regular-expressions"} 23 | result = node.xpath(compile, namespaces=namespaces) 24 | return result 25 | 26 | 27 | def url_parse(url:str): 28 | # 提取url中的params参数,返回item 29 | p = url.split('?')[1] 30 | item = {} 31 | if '&' in p: 32 | param = p.split('&') 33 | for v in param: 34 | k = v.split('=') 35 | item[k[0]] = k[1] 36 | else: 37 | k = p.split('=') 38 | item[k[0]] = k[1] 39 | return item 40 | 41 | 42 | -------------------------------------------------------------------------------- /lxpy/tracks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Time : 2021/12/14 12:47 3 | # @Author : lx 4 | # @IDE :PyCharm 5 | import random 6 | 7 | def get_tracks(distance): 8 | tracks = [] 9 | y = 0 10 | v = 0 11 | t = 1 12 | current = 0 13 | mid = distance * 3 / 4 14 | exceed = random.randint(40, 50) 15 | z = random.randint(30, 150) 16 | 17 | while current < (distance + exceed): 18 | if current < mid / 2: 19 | a = 2 20 | elif current < mid: 21 | a = 3 22 | else: 23 | a = -3 24 | a /= 2 25 | v0 = v 26 | s = v0 * t + 0.5 * a * (t * t) 27 | current += int(s) 28 | v = v0 + a * t 29 | 30 | y += random.randint(-3, 3) 31 | z = z + random.randint(6, 8) 32 | tracks.append([min(current, (distance + exceed)), y, z]) 33 | 34 | while exceed > 0: 35 | exceed -= random.randint(0, 5) 36 | y += random.randint(-1, 3) 37 | z = z + random.randint(6, 8) 38 | tracks.append([min(current, (distance + exceed)), y, z]) 39 | # return tracks 40 | track_str = '' 41 | for x in tracks: 42 | x = [str(i) for i in x] 43 | x = '|'.join(x) 44 | track_str += (x + ',') 45 | return track_str[:-1] 46 | 47 | 48 | # test: 49 | # dis_x =500 50 | # print(get_tracks(int(dis_x * (392 / 118)))) 51 | 52 | 53 | -------------------------------------------------------------------------------- /lxpy/lxml_check.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : lx 3 | 4 | 5 | """ 6 | 解决 etree.HTML解析后数据丢失的问题 7 | 调用 create_root_node 方法,传入response.text即可 8 | """ 9 | 10 | from lxml import etree, html 11 | 12 | 13 | class SafeXMLParser(etree.XMLParser): 14 | def __init__(self, *args, **kwargs): 15 | kwargs.setdefault('resolve_entities', False) 16 | super(SafeXMLParser, self).__init__(*args, **kwargs) 17 | 18 | 19 | _ctgroup = { 20 | 'html': { 21 | '_parser': html.HTMLParser, 22 | '_tostring_method': 'html', 23 | }, 24 | 'xml': { 25 | '_parser': SafeXMLParser, 26 | '_tostring_method': 'xml', 27 | }, 28 | } 29 | _default_type = None 30 | 31 | 32 | def _st(st): 33 | if st is None: 34 | return 'html' 35 | elif st in _ctgroup: 36 | return st 37 | else: 38 | raise ValueError('Invalid type: %s' % st) 39 | 40 | 41 | def create_root_node(text, base_url=None, doc_type='html'): 42 | """Create root node for text using given parser class. 43 | """ 44 | st = _st(doc_type or _default_type) 45 | parser_cls = _ctgroup[st]['_parser'] 46 | body = text.strip().replace('\x00', '').encode('utf-8') or b'' 47 | parser = parser_cls(recover=True, encoding='utf-8') 48 | root = etree.fromstring(body, parser=parser, base_url=base_url) 49 | if root is None: 50 | root = etree.fromstring(b'', parser=parser, base_url=base_url) 51 | return root 52 | 53 | -------------------------------------------------------------------------------- /lxpy/lxheader.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author : lx 3 | 4 | def copy_headers_dict(headers_raw): 5 | """ headers Converts 6 | Example: 7 | copy_headers = ''' 8 | accept-encoding: gzip 9 | accept-language: zh-CN 10 | upgrade-insecure-requests: 1 11 | user-agent: Mozilla/5.0 Safari/537.36 12 | ''' 13 | print(headers_raw_to_dict(copy_headers)) 14 | """ 15 | if headers_raw is None: 16 | return None 17 | 18 | headers = headers_raw.splitlines() 19 | headers_tuples = [header.split(":", 1) for header in headers] 20 | 21 | result_dict = {} 22 | for header_item in headers_tuples: 23 | if not len(header_item) == 2: 24 | continue 25 | 26 | item_key = header_item[0].strip() 27 | item_value = header_item[1].strip() 28 | result_dict[item_key] = item_value 29 | 30 | return result_dict 31 | 32 | 33 | 34 | 35 | import random 36 | def get_ua(): 37 | """Get some user-agent ,But not necessarily accepted by the website""" 38 | first_num = random.randint(55, 62) 39 | third_num = random.randint(0, 3200) 40 | fourth_num = random.randint(0, 140) 41 | os_type = [ 42 | '(Windows NT 6.1; WOW64)', 43 | '(Windows NT 10.0; WOW64)', 44 | '(X11; Linux x86_64)', 45 | '(Macintosh; Intel Mac OS X 10_12_6)' 46 | ] 47 | chrome_version = 'Chrome/{}.0.{}.{}'.format(first_num, third_num, fourth_num) 48 | ua = ' '.join(['Mozilla/5.0', random.choice(os_type), 'AppleWebKit/537.36', 49 | '(KHTML, like Gecko)', chrome_version, 'Safari/537.36'] 50 | ) 51 | userAgent = {"user-agent":ua} 52 | return userAgent 53 | -------------------------------------------------------------------------------- /lxpy/encrypt/rsa.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Time : 2021/12/28 12:32 3 | # @Author : lx 4 | # @IDE :PyCharm 5 | import base64 6 | import rsa 7 | from rsa import common 8 | 9 | class RsaUtil(object): 10 | PUBLIC_KEY_PATH = 'public_key.pem' # 公钥 11 | PRIVATE_KEY_PATH = 'private_key.pem' # 私钥 12 | 13 | # 初始化key 14 | def __init__(self, 15 | company_pub_file=PUBLIC_KEY_PATH, 16 | company_pri_file=PRIVATE_KEY_PATH): 17 | 18 | if company_pub_file: 19 | self.company_public_key = rsa.PublicKey.load_pkcs1_openssl_pem(open(company_pub_file).read()) 20 | if company_pri_file: 21 | self.company_private_key = rsa.PrivateKey.load_pkcs1(open(company_pri_file).read()) 22 | 23 | def get_max_length(self, rsa_key, encrypt=True): 24 | """加密内容过长时 需要分段加密 换算每一段的长度. 25 | :param rsa_key: 钥匙. 26 | :param encrypt: 是否是加密. 27 | """ 28 | blocksize = common.byte_size(rsa_key.n) 29 | reserve_size = 11 # 预留位为11 30 | if not encrypt: # 解密时不需要考虑预留位 31 | reserve_size = 0 32 | maxlength = blocksize - reserve_size 33 | return maxlength 34 | 35 | def encrypt_by_public_key(self, message): 36 | """使用公钥加密. 37 | :param message: 需要加密的内容. 38 | 加密之后需要对接过进行base64转码 39 | """ 40 | encrypt_result = b'' 41 | max_length = self.get_max_length(self.company_public_key) 42 | while message: 43 | input = message[:max_length] 44 | message = message[max_length:] 45 | out = rsa.encrypt(input, self.company_public_key) 46 | encrypt_result += out 47 | encrypt_result = base64.b64encode(encrypt_result) 48 | return encrypt_result 49 | 50 | def decrypt_by_private_key(self, message): 51 | """使用私钥解密. 52 | :param message: 需要加密的内容. 53 | 解密之后的内容直接是字符串,不需要在进行转义 54 | """ 55 | decrypt_result = b"" 56 | 57 | max_length = self.get_max_length(self.company_private_key, False) 58 | decrypt_message = base64.b64decode(message) 59 | while decrypt_message: 60 | input = decrypt_message[:max_length] 61 | decrypt_message = decrypt_message[max_length:] 62 | out = rsa.decrypt(input, self.company_private_key) 63 | decrypt_result += out 64 | return decrypt_result 65 | 66 | def sign_by_private_key(self, data): 67 | """私钥签名. 68 | :param data: 需要签名的内容. 69 | 使用SHA-1 方法进行签名(也可以使用MD5) 70 | 签名之后,需要转义后输出 71 | """ 72 | signature = rsa.sign(str(data), priv_key=self.company_private_key, hash='SHA-1') 73 | return base64.b64encode(signature) 74 | 75 | def verify_by_public_key(self, message, signature): 76 | """公钥验签. 77 | :param message: 验签的内容. 78 | :param signature: 对验签内容签名的值(签名之后,会进行b64encode转码,所以验签前也需转码). 79 | """ 80 | signature = base64.b64decode(signature) 81 | return rsa.verify(message, signature, self.company_public_key) 82 | -------------------------------------------------------------------------------- /lxpy/cipher.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # 凯撒密码 4 | def caesar(t, n, keys='abcdefghijklmnopqrstuvwxyz'): 5 | s = list(keys) 6 | r = '' 7 | for i in t: 8 | if i in s: 9 | r += s[(s.index(i) + n)% len(keys)] 10 | else: 11 | r += i 12 | return r 13 | 14 | 15 | # 摩斯密码 16 | def morse_dec(string, a='.', b='-', p=None): 17 | morse = { 18 | '.-' :'A', '-...':'B', '-.-.':'C', '-..' :'D', '.' :'E', 19 | '..-.':'F', '--.' :'G', '....':'H', '..' :'I', '.---':'J', 20 | '-.-':'K', '.-..' : 'L', '--' :'M', '-.' :'N', '---':'O', 21 | '.--.' : 'P', '--.-' : 'Q', '.-.':'R', '...':'S', '-' :'T', 22 | '..-':'U', '...-' : 'V', '.--':'W', '-..-' : 'X', '-.--' : 'Y', 23 | '--..' : 'Z', '.----' : '1', '..---' : '2', '...--' : '3', 24 | '....-' : '4', '.....' : '5', '-....' : '6', '--...' : '7', 25 | '---..' : '8','----.' : '9','-----' : '0', 26 | '-...-' : '=', '.-.-':'~', '.-...' :'', '.-.-.' : '', '...-.-' : '', 27 | '-.--.' : '', '..-.-' : '', '....--' : '', '...-.' : '', 28 | '.-..-.' : '\\', '.----.' : '\'', '...-..-' : '$', '-.--.' : '(', '-.--.-' : ')', 29 | '--..--' : ',', '-....-' : '-', '.-.-.-' : '.', '-..-.' : '/', '---...' : ':', 30 | '-.-.-.' : ';', '..--..' : '?', '..--.-' : '_', '.--.-.' : '@', '-.-.--' : '!' 31 | } 32 | _a, _b = '.', '-' 33 | _names = string.split() if p is None else string.split(p) 34 | r = [] 35 | for ps in _names: 36 | ps = ps.replace(a, _a).replace(b, _b) 37 | ge = morse.get(ps) 38 | if ge: 39 | r.append(ge) 40 | else: 41 | r.append('[undefined:{}]'.format(ps)) 42 | return ''.join(r) 43 | 44 | def morse_enc(string, a='.', b='-', p=None): 45 | morse = { 46 | 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 47 | 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 48 | 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': 49 | '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 50 | 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', 'Z': '--..', 51 | '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', 52 | '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', 53 | '=': '-...-', '~': '.-.-', '': '.-...', '': '.-.-.', 54 | '': '...-.-', '(': '-.--.', '': '..-.-', '': '....--', 55 | '': '...-.', '\\': '.-..-.', "'": '.----.', '$': '...-..-', 56 | ')': '-.--.-', ',': '--..--', '-': '-....-', '.': '.-.-.-', '/': '-..-.', 57 | ':': '---...', ';': '-.-.-.', '?': '..--..', '_': '..--.-', '@': '.--.-.', '!': '-.-.--' 58 | } 59 | _a, _b = '.', '-' 60 | r = [] 61 | for i in string: 62 | if i.upper() in morse: 63 | v = morse[i.upper()].replace(_a, a).replace(_b, b) 64 | else: 65 | v = '[undefined:{}]'.format(i) 66 | r.append(v) 67 | return ' '.join(r) if p is None else p.join(r) 68 | 69 | 70 | # 栅栏密码 71 | def rail_fence_enc(string, n, padding=None): 72 | b = [] 73 | q = [] 74 | for idx,i in enumerate(string, 1): 75 | q.append(i) 76 | if idx % n == 0: 77 | b.append(q) 78 | q = [] 79 | r = [] 80 | if q: 81 | for i in '~!@#$%^&*': # 自动选一个padding进行处理 82 | if i not in string: 83 | padding = i 84 | break 85 | if padding is None: 86 | raise ('cannot find a padding, cos ~!@#$%^&* all in string.') 87 | q += [padding] * (n - len(q)) 88 | b.append(q) 89 | for i in zip(*b): 90 | r.extend(i) 91 | return ''.join(r), padding 92 | 93 | def rail_fence_dec(string, n, padding=None): 94 | a = len(string)/n 95 | b = len(string)//n 96 | n = b if a == b else b+1 97 | b = [] 98 | for i in range(0,n): 99 | b.append(string[i::int(n)]) 100 | r = [] 101 | for i in zip(b): 102 | r.extend(i) 103 | return ''.join(r).rstrip(padding) 104 | 105 | 106 | # ook! 107 | def parse_ook_to_brainfuckmap(string, abc=('!', '?', '.')): 108 | maps = { 109 | ('!', '?'): '[', 110 | ('?', '!'): ']', 111 | ('.', '.'): '+', 112 | ('!', '!'): '-', 113 | ('.', '?'): '>', 114 | ('?', '.'): '<', 115 | ('!', '.'): '.', 116 | ('.', '!'): ',', 117 | } 118 | a, b, c = [i if i not in r'$()*+.[]?\/^{}' else '\\'+i for i in abc] 119 | rexgep = '|'.join([a, b, c]) 120 | v = re.findall(rexgep, string) 121 | r = [] 122 | for i in zip(v[::2],v[1::2]): 123 | t = [j.replace(a[-1], '!')\ 124 | .replace(b[-1], '?')\ 125 | .replace(c[-1], '.') for j in i] 126 | t = tuple(t) 127 | r.append(maps.get(t)) 128 | return ''.join(r) 129 | 130 | -------------------------------------------------------------------------------- /lxpy/encoding.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # TODO: b36\b62\b58\b91编码 4 | 5 | import struct 6 | 7 | 8 | 9 | # b36 看往上的说明,貌似应用于将数字转化成字符串进行保存? 10 | def b36encode(num): 11 | alpha = '0123456789abcdefghijklmnopqrstuvwxyz' 12 | if not isinstance(num, int): 13 | raise TypeError('num must be an integer') 14 | if num < 0: 15 | return '-' + b36encode(-num) 16 | val = '' 17 | while num != 0: 18 | num, idx = divmod(num, len(alpha)) 19 | val = alpha[idx] + val 20 | return val or '0' 21 | 22 | def b36decode(val): 23 | return int(val, 36) 24 | 25 | # s = b36encode(1111111111111111) 26 | # print(s) 27 | # s = b36decode(s) 28 | # print(s) 29 | 30 | 31 | 32 | 33 | def b62encode(num): 34 | alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' 35 | if not isinstance(num, int): 36 | raise TypeError('num must be an integer') 37 | if num < 0: 38 | return '-' + b36encode(-num) 39 | val = '' 40 | while num != 0: 41 | num, idx = divmod(num, len(alpha)) 42 | val = alpha[idx] + val 43 | return val or '0' 44 | 45 | def b62decode(val): 46 | alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' 47 | r = 0 48 | for idx,i in enumerate(val[::-1]): 49 | r += alpha.index(i) * (len(alpha) ** idx) 50 | return r 51 | 52 | # s = b62encode(1111111111111111) 53 | # print(s) 54 | # s = b62decode(s) 55 | # print(s) 56 | 57 | 58 | 59 | 60 | 61 | 62 | base91_alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 63 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 64 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 65 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 66 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$', 67 | '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=', 68 | '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'] 69 | 70 | decode_table = dict((v, k) for k, v in enumerate(base91_alphabet)) 71 | 72 | def b91decode(encoded_str): 73 | ''' Decode Base91 string to a bytearray ''' 74 | v = -1 75 | b = 0 76 | n = 0 77 | out = b'' 78 | for strletter in encoded_str.decode(): 79 | if not strletter in decode_table: 80 | continue 81 | c = decode_table[strletter] 82 | if (v < 0): 83 | v = c 84 | else: 85 | v += c * 91 86 | b |= v << n 87 | n += 13 if (v & 8191) > 88 else 14 88 | while True: 89 | out += struct.pack('B', b & 255) 90 | b >>= 8 91 | n -= 8 92 | if not n > 7: 93 | break 94 | v = -1 95 | if v + 1: 96 | out += struct.pack('B', (b | v << n) & 255) 97 | return out 98 | 99 | def b91encode(bindata): 100 | ''' Encode a bytearray to a Base91 string ''' 101 | b = 0 102 | n = 0 103 | out = '' 104 | for count in range(len(bindata)): 105 | byte = bindata[count:count + 1] 106 | b |= struct.unpack('B', byte)[0] << n 107 | n += 8 108 | if n > 13: 109 | v = b & 8191 110 | if v > 88: 111 | b >>= 13 112 | n -= 13 113 | else: 114 | v = b & 16383 115 | b >>= 14 116 | n -= 14 117 | out += base91_alphabet[v % 91] + base91_alphabet[v // 91] 118 | if n: 119 | out += base91_alphabet[b % 91] 120 | if n > 7 or b > 90: 121 | out += base91_alphabet[b // 91] 122 | return out.encode() 123 | 124 | # 统一输入输出的格式 125 | # s = b91encode(b'asdfasdf') 126 | # print(s) 127 | # s = b91decode(s) 128 | # print(s) 129 | 130 | 131 | 132 | # b58 133 | # 没有0,大写的O,大写的I,以及小写的l 134 | alphabet = b'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' 135 | alphalen = len(alphabet) 136 | 137 | def b58encode_int(i, default_one=True): 138 | '''Encode an integer using Base58''' 139 | if not i and default_one: 140 | return alphabet[0:1] 141 | string = b"" 142 | while i: 143 | i, idx = divmod(i, alphalen) 144 | string = alphabet[idx:idx+1] + string 145 | return string 146 | 147 | def b58encode(v): 148 | nPad = len(v) 149 | v = v.lstrip(b'\0') 150 | nPad -= len(v) 151 | p, acc = 1, 0 152 | for c in reversed(v): 153 | acc += p * c 154 | p = p << 8 155 | result = b58encode_int(acc, default_one=False) 156 | return (alphabet[0:1] * nPad + result) 157 | 158 | def b58decode_int(v): 159 | decimal = 0 160 | for char in v: 161 | decimal = decimal * alphalen + alphabet.index(char) 162 | return decimal 163 | 164 | def b58decode(v): 165 | origlen = len(v) 166 | v = v.lstrip(alphabet[0:1]) 167 | newlen = len(v) 168 | acc = b58decode_int(v) 169 | result = [] 170 | while acc > 0: 171 | acc, mod = divmod(acc, 256) 172 | result.append(mod) 173 | return (b'\0' * (origlen - newlen) + bytes(reversed(result))) 174 | 175 | 176 | # s = b58encode(b'asdfasdf') 177 | # print(s) 178 | # s = b58decode(s) 179 | # print(s) 180 | -------------------------------------------------------------------------------- /lxpy/lxdate.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author : lx 3 | 4 | """ 5 | Datetime Library 6 | ~~~~~~~~~~~~~~~~~~~~~ 7 | """ 8 | 9 | import datetime 10 | import time 11 | import re 12 | 13 | 14 | class DateGo: 15 | @staticmethod 16 | def now_data(): 17 | """ 18 | 获取当前时间 19 | :return: %Y-%m-%d %H:%M:%S 20 | """ 21 | return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 22 | 23 | 24 | @staticmethod 25 | def now_ymd()->list: 26 | """ 27 | 获取当前 年,月,日 28 | :return: list:[年,月,日] 29 | """ 30 | now_date = datetime.datetime.now() 31 | y = str(now_date.year) 32 | m = str(now_date.month) 33 | d = str(now_date.day) 34 | return [y,m,d] 35 | 36 | 37 | @staticmethod # 把时间戳 转换为 年月日时分 格式 38 | def timec_change_dtime(time1): 39 | if len(str(time1))==13: 40 | time1 = int(time1) / 1000.0 41 | timeArray = time.localtime(int(time1)) 42 | otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) 43 | return otherStyleTime 44 | 45 | 46 | @staticmethod # 负数时间戳转换/转换1970年之前的时间戳 47 | def netimec_to_dtime(timestamp,valid=True): 48 | """ 49 | :param timestamp: 负数时间戳 50 | :param valid: 默认增加8小时 51 | :return: 年-月-日 时:分:秒 52 | if OverflowError , date value out of range: timestamp/1000 53 | """ 54 | if valid: 55 | timestamp = int(timestamp) + 8*3600 56 | result = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=int(timestamp)) 57 | return result 58 | 59 | 60 | 61 | @staticmethod 62 | def dtime_to_timec(tss1): 63 | """ 64 | 把 年月日时分 转换为 时间戳格式 65 | :param tss1: str 66 | :return: timeStamp:int 67 | """ 68 | timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S") 69 | timeStamp = int(time.mktime(timeArray)) 70 | return timeStamp 71 | 72 | 73 | @staticmethod 74 | def yesterday_timec(day=1): 75 | """ 76 | # 获取昨天开始的时间戳 77 | :param day: int 78 | """ 79 | yesterday = datetime.date.today() - datetime.timedelta(days=day) 80 | yesterday_timec = int(time.mktime(time.strptime(str(yesterday), '%Y-%m-%d'))) 81 | return yesterday_timec 82 | 83 | 84 | @staticmethod 85 | def difference_time(time1,time2): 86 | """ 87 | 两个时间的差 -> 秒 88 | """ 89 | t1 = datetime.datetime.utcfromtimestamp(time1) 90 | t2 = datetime.datetime.utcfromtimestamp(time2) 91 | time_poor = (t1 - t2).seconds 92 | return time_poor 93 | 94 | 95 | @staticmethod 96 | def weibo_date(raw): 97 | """ 98 | # 微博时间处理方法,转换为时间格式 99 | :param raw: str 100 | :return: %Y-%m-%d %H:%M:%S 101 | """ 102 | result = None 103 | if raw.find('分钟') != -1 or raw.find('小时') != -1 or raw.find('天') != -1: 104 | dn = datetime.datetime.now() 105 | dt = datetime.timedelta 106 | num = int(re.findall('\d{1,}', raw)[0]) 107 | if '分钟' in raw: 108 | result = dn - dt(minutes=num) 109 | elif '小时' in raw: 110 | result = dn - dt(hours=num) 111 | elif '天' in raw: 112 | result = dn - dt(days=num) 113 | result = result.strftime("%Y-%m-%d %H:%M:%S") 114 | return result 115 | elif raw == '刚刚': 116 | return DateGo.now_data() 117 | elif len(raw)== 5 and raw[2] == '-': 118 | result = DateGo.now_ymd()[0] +'-' +raw +' 00:00:00' 119 | return result 120 | else: 121 | if len(raw)==10: 122 | raw = raw + ' 00:00:00' 123 | return raw 124 | else: 125 | return raw 126 | 127 | 128 | @staticmethod 129 | def youku_date(raw): 130 | """ 131 | 优酷时间处理方法 132 | """ 133 | if raw == '昨天': 134 | return DateGo.date_befor_days(1) 135 | elif raw == '前天': 136 | return DateGo.date_befor_days(2) 137 | elif raw == '1周前' or raw=='一周前': 138 | return DateGo.date_befor_days(7) 139 | elif raw == '一月前': 140 | return DateGo.date_befor_days(30) 141 | elif '天前' in raw: 142 | return DateGo.youku_date_2(raw) 143 | elif '刚刚' == raw: 144 | return DateGo.now_data() 145 | elif '小时前' in raw: 146 | return DateGo.youku_date_2(raw) 147 | elif '分钟前' in raw: 148 | return DateGo.youku_date_2(raw) 149 | 150 | 151 | @staticmethod 152 | def youku_date_2(raw): 153 | if raw.find('分钟') != -1 or raw.find('小时') != -1 or raw.find('天') != -1: 154 | dn = datetime.datetime.now() 155 | dt = datetime.timedelta 156 | num = int(re.findall('\d{1,}', raw)[0]) 157 | if '分钟' in raw: 158 | result = dn - dt(minutes=num) 159 | elif '小时' in raw: 160 | result = dn - dt(hours=num) 161 | else: 162 | result = dn - dt(days=num) 163 | result = result.strftime("%Y-%m-%d %H:%M:%S") 164 | return result 165 | else: 166 | return raw 167 | 168 | 169 | @staticmethod 170 | def difference_timenow(date2): 171 | """ 172 | 当前时间和指定时间的差/-> 秒 173 | :param date2: 174 | :return: 175 | """ 176 | date1 = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 177 | date1 = datetime.datetime.strptime(date1, "%Y-%m-%d %H:%M:%S") 178 | date2 = datetime.datetime.strptime(date2, "%Y-%m-%d %H:%M:%S") 179 | difference = (date1 - date2).total_seconds() 180 | return difference 181 | 182 | 183 | @staticmethod 184 | def difference_time_two(date1,date2): 185 | """ 186 | 两个时间的差/-> 秒 187 | :return: 188 | """ 189 | date1 = datetime.datetime.strptime(date1, "%Y-%m-%d %H:%M:%S") 190 | date2 = datetime.datetime.strptime(date2, "%Y-%m-%d %H:%M:%S") 191 | difference = (date1 - date2).total_seconds() 192 | return difference 193 | 194 | 195 | @staticmethod 196 | def date_befor_minutes(value): 197 | """ 分钟 前/后 的时间 198 | :param value: 199 | :return: 200 | """ 201 | now_time = datetime.datetime.now() 202 | now_time = now_time - datetime.timedelta(minutes=int(value)) 203 | return now_time.strftime('%Y-%m-%d %H:%M:%S') 204 | 205 | 206 | @staticmethod 207 | def date_befor_hours(value): 208 | """ 小时前/后 的时间 209 | :param value: 210 | :return: 211 | """ 212 | now_time = datetime.datetime.now() 213 | now_time = now_time - datetime.timedelta(hours=int(value)) 214 | return now_time.strftime('%Y-%m-%d %H:%M:%S') 215 | 216 | 217 | @staticmethod 218 | def date_befor_days(beforeOfDay:int): 219 | """ 几天前/后 的时间 220 | :param beforeOfDay: 221 | :return: 222 | """ 223 | today = datetime.datetime.now() 224 | offset = datetime.timedelta(days=-beforeOfDay) 225 | re_date = (today + offset).strftime('%Y-%m-%d %H:%M:%S') 226 | return re_date 227 | 228 | 229 | @staticmethod 230 | def java_date(date,to_format="%Y-%m-%d %H:%M:%S",timezon ="CST"): 231 | """ java时间格式转换为python日期格式 232 | %a: 星期的缩写 233 | %b: 月份英文名的缩写 234 | %d: 日期(以01-31来表示) 235 | %Y: 年份(以四位数来表示) 236 | :param: data: Fri May 18 15:46:24 CST 2016 237 | :param: timezon:时区 "CST" 238 | :return: to_format="%Y-%m-%d %H:%M:%S" 239 | """ 240 | data_format = "%a %b %d %H:%M:%S {} %Y".format(timezon) 241 | time_struct = time.strptime(str(date),data_format) 242 | ctime = time.strftime(to_format,time_struct) 243 | return ctime 244 | 245 | 246 | @staticmethod 247 | def time_handler(target_time: str): 248 | """ 249 | UTC世界标准时间(包含T和Z) 转 北京时间 250 | :param target_time: 251 | :return: 252 | """ 253 | _date = datetime.strptime(target_time, "%Y-%m-%dT%H:%M:%S.%fZ") 254 | local_time = _date + timedelta(hours=8) 255 | end_time = local_time.strftime("%Y-%m-%d %H:%M:%S") 256 | return end_time 257 | -------------------------------------------------------------------------------- /lxpy/encrypt/serpent.py: -------------------------------------------------------------------------------- 1 | ## serpent.py - pure Python implementation of the Serpent algorithm. 2 | 3 | import binascii 4 | import base64 5 | 6 | block_size = 16 7 | key_size = 32 8 | 9 | 10 | class Serpent: 11 | 12 | def __init__(self, key=None): 13 | """Serpent.""" 14 | 15 | if key: 16 | self.set_key(key) 17 | 18 | def set_key(self, key): 19 | """Init.""" 20 | 21 | key_len = len(key) 22 | if key_len % 4: 23 | # XXX: add padding? 24 | raise KeyError("key not a multiple of 4") 25 | if key_len > 32: 26 | # XXX: prune? 27 | raise KeyError("key_len > 32") 28 | 29 | self.key_context = [0] * 140 30 | 31 | key_word32 = [0] * 32 32 | i = 0 33 | while key: 34 | key_word32[i] = struct.unpack("> n) | ((x << (32 - n)) & 0xFFFFFFFF) 105 | 106 | 107 | def rotl32(x, n): 108 | return ((x << n) & 0xFFFFFFFF) | (x >> (32 - n)) 109 | 110 | 111 | def byteswap32(x): 112 | return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | \ 113 | (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff) 114 | 115 | 116 | def set_key(l_key, key, key_len): 117 | key_len *= 8 118 | if key_len > 256: 119 | return False 120 | 121 | i = 0 122 | lk = (key_len + 31) / 32 123 | while i < lk: 124 | l_key[i] = key[i] 125 | if WORD_BIGENDIAN: 126 | l_key[i] = byteswap32(key[i]) 127 | i += 1 128 | 129 | if key_len < 256: 130 | while i < 8: 131 | l_key[i] = 0 132 | i += 1 133 | i = key_len // 32 134 | lk = 1 << (key_len % 32) 135 | l_key[i] = (l_key[i] & (lk - 1)) | lk 136 | for i in range(132): 137 | lk = l_key[i] ^ l_key[i + 3] ^ l_key[i + 5] ^ l_key[i + 7] ^ 0x9e3779b9 ^ i 138 | l_key[i + 8] = ((lk << 11) & 0xFFFFFFFF) | (lk >> 21) 139 | 140 | key = l_key 141 | # serpent_generate.py 142 | a = key[4 * 0 + 8] 143 | b = key[4 * 0 + 9] 144 | c = key[4 * 0 + 10] 145 | d = key[4 * 0 + 11] 146 | e = 0 147 | f = 0 148 | g = 0 149 | h = 0 150 | t1 = 0 151 | t2 = 0 152 | t3 = 0 153 | t4 = 0 154 | t5 = 0 155 | t6 = 0 156 | t7 = 0 157 | t8 = 0 158 | t9 = 0 159 | t10 = 0 160 | t11 = 0 161 | t12 = 0 162 | t13 = 0 163 | t14 = 0 164 | t15 = 0 165 | t16 = 0 166 | t1 = a ^ c; 167 | t2 = d ^ t1; 168 | t3 = a & t2; 169 | t4 = d ^ t3; 170 | t5 = b & t4; 171 | g = t2 ^ t5; 172 | t7 = a | g; 173 | t8 = b | d; 174 | t11 = a | d; 175 | t9 = t4 & t7; 176 | f = t8 ^ t9; 177 | t12 = b ^ t11; 178 | t13 = g ^ t9; 179 | t15 = t3 ^ t8; 180 | h = t12 ^ t13; 181 | t16 = c & t15; 182 | e = t12 ^ t16 183 | key[4 * 0 + 8] = e 184 | key[4 * 0 + 9] = f 185 | key[4 * 0 + 10] = g 186 | key[4 * 0 + 11] = h 187 | a = key[4 * 1 + 8] 188 | b = key[4 * 1 + 9] 189 | c = key[4 * 1 + 10] 190 | d = key[4 * 1 + 11] 191 | t1 = (~a) % 0x100000000; 192 | t2 = b ^ d; 193 | t3 = c & t1; 194 | t13 = d | t1; 195 | e = t2 ^ t3; 196 | t5 = c ^ t1; 197 | t6 = c ^ e; 198 | t7 = b & t6; 199 | t10 = e | t5; 200 | h = t5 ^ t7; 201 | t9 = d | t7; 202 | t11 = t9 & t10; 203 | t14 = t2 ^ h; 204 | g = a ^ t11; 205 | t15 = g ^ t13; 206 | f = t14 ^ t15 207 | key[4 * 1 + 8] = e 208 | key[4 * 1 + 9] = f 209 | key[4 * 1 + 10] = g 210 | key[4 * 1 + 11] = h 211 | a = key[4 * 2 + 8] 212 | b = key[4 * 2 + 9] 213 | c = key[4 * 2 + 10] 214 | d = key[4 * 2 + 11] 215 | t1 = (~a) % 0x100000000; 216 | t2 = b ^ t1; 217 | t3 = a | t2; 218 | t4 = d | t2; 219 | t5 = c ^ t3; 220 | g = d ^ t5; 221 | t7 = b ^ t4; 222 | t8 = t2 ^ g; 223 | t9 = t5 & t7; 224 | h = t8 ^ t9; 225 | t11 = t5 ^ t7; 226 | f = h ^ t11; 227 | t13 = t8 & t11; 228 | e = t5 ^ t13 229 | key[4 * 2 + 8] = e 230 | key[4 * 2 + 9] = f 231 | key[4 * 2 + 10] = g 232 | key[4 * 2 + 11] = h 233 | a = key[4 * 3 + 8] 234 | b = key[4 * 3 + 9] 235 | c = key[4 * 3 + 10] 236 | d = key[4 * 3 + 11] 237 | t1 = a ^ d; 238 | t2 = a & d; 239 | t3 = c ^ t1; 240 | t6 = b & t1; 241 | t4 = b ^ t3; 242 | t10 = (~t3) % 0x100000000; 243 | h = t2 ^ t4; 244 | t7 = a ^ t6; 245 | t14 = (~t7) % 0x100000000; 246 | t8 = c | t7; 247 | t11 = t3 ^ t7; 248 | g = t4 ^ t8; 249 | t12 = h & t11; 250 | f = t10 ^ t12; 251 | e = t12 ^ t14 252 | key[4 * 3 + 8] = e 253 | key[4 * 3 + 9] = f 254 | key[4 * 3 + 10] = g 255 | key[4 * 3 + 11] = h 256 | a = key[4 * 4 + 8] 257 | b = key[4 * 4 + 9] 258 | c = key[4 * 4 + 10] 259 | d = key[4 * 4 + 11] 260 | t1 = (~c) % 0x100000000; 261 | t2 = b ^ c; 262 | t3 = b | t1; 263 | t4 = d ^ t3; 264 | t5 = a & t4; 265 | t7 = a ^ d; 266 | h = t2 ^ t5; 267 | t8 = b ^ t5; 268 | t9 = t2 | t8; 269 | t11 = d & t3; 270 | f = t7 ^ t9; 271 | t12 = t5 ^ f; 272 | t15 = t1 | t4; 273 | t13 = h & t12; 274 | g = t11 ^ t13; 275 | t16 = t12 ^ g; 276 | e = t15 ^ t16 277 | key[4 * 4 + 8] = e 278 | key[4 * 4 + 9] = f 279 | key[4 * 4 + 10] = g 280 | key[4 * 4 + 11] = h 281 | a = key[4 * 5 + 8] 282 | b = key[4 * 5 + 9] 283 | c = key[4 * 5 + 10] 284 | d = key[4 * 5 + 11] 285 | t1 = (~a) % 0x100000000; 286 | t2 = a ^ d; 287 | t3 = b ^ t2; 288 | t4 = t1 | t2; 289 | t5 = c ^ t4; 290 | f = b ^ t5; 291 | t13 = (~t5) % 0x100000000; 292 | t7 = t2 | f; 293 | t8 = d ^ t7; 294 | t9 = t5 & t8; 295 | g = t3 ^ t9; 296 | t11 = t5 ^ t8; 297 | e = g ^ t11; 298 | t14 = t3 & t11; 299 | h = t13 ^ t14 300 | key[4 * 5 + 8] = e 301 | key[4 * 5 + 9] = f 302 | key[4 * 5 + 10] = g 303 | key[4 * 5 + 11] = h 304 | a = key[4 * 6 + 8] 305 | b = key[4 * 6 + 9] 306 | c = key[4 * 6 + 10] 307 | d = key[4 * 6 + 11] 308 | t1 = (~a) % 0x100000000; 309 | t2 = a ^ b; 310 | t3 = a ^ d; 311 | t4 = c ^ t1; 312 | t5 = t2 | t3; 313 | e = t4 ^ t5; 314 | t7 = d & e; 315 | t8 = t2 ^ e; 316 | t10 = t1 | e; 317 | f = t7 ^ t8; 318 | t11 = t2 | t7; 319 | t12 = t3 ^ t10; 320 | t14 = b ^ t7; 321 | g = t11 ^ t12; 322 | t15 = f & t12; 323 | h = t14 ^ t15 324 | key[4 * 6 + 8] = e 325 | key[4 * 6 + 9] = f 326 | key[4 * 6 + 10] = g 327 | key[4 * 6 + 11] = h 328 | a = key[4 * 7 + 8] 329 | b = key[4 * 7 + 9] 330 | c = key[4 * 7 + 10] 331 | d = key[4 * 7 + 11] 332 | t1 = a ^ d; 333 | t2 = d & t1; 334 | t3 = c ^ t2; 335 | t4 = b | t3; 336 | h = t1 ^ t4; 337 | t6 = (~b) % 0x100000000; 338 | t7 = t1 | t6; 339 | e = t3 ^ t7; 340 | t9 = a & e; 341 | t10 = t1 ^ t6; 342 | t11 = t4 & t10; 343 | g = t9 ^ t11; 344 | t13 = a ^ t3; 345 | t14 = t10 & g; 346 | f = t13 ^ t14 347 | key[4 * 7 + 8] = e 348 | key[4 * 7 + 9] = f 349 | key[4 * 7 + 10] = g 350 | key[4 * 7 + 11] = h 351 | a = key[4 * 8 + 8] 352 | b = key[4 * 8 + 9] 353 | c = key[4 * 8 + 10] 354 | d = key[4 * 8 + 11] 355 | t1 = a ^ c; 356 | t2 = d ^ t1; 357 | t3 = a & t2; 358 | t4 = d ^ t3; 359 | t5 = b & t4; 360 | g = t2 ^ t5; 361 | t7 = a | g; 362 | t8 = b | d; 363 | t11 = a | d; 364 | t9 = t4 & t7; 365 | f = t8 ^ t9; 366 | t12 = b ^ t11; 367 | t13 = g ^ t9; 368 | t15 = t3 ^ t8; 369 | h = t12 ^ t13; 370 | t16 = c & t15; 371 | e = t12 ^ t16 372 | key[4 * 8 + 8] = e 373 | key[4 * 8 + 9] = f 374 | key[4 * 8 + 10] = g 375 | key[4 * 8 + 11] = h 376 | a = key[4 * 9 + 8] 377 | b = key[4 * 9 + 9] 378 | c = key[4 * 9 + 10] 379 | d = key[4 * 9 + 11] 380 | t1 = (~a) % 0x100000000; 381 | t2 = b ^ d; 382 | t3 = c & t1; 383 | t13 = d | t1; 384 | e = t2 ^ t3; 385 | t5 = c ^ t1; 386 | t6 = c ^ e; 387 | t7 = b & t6; 388 | t10 = e | t5; 389 | h = t5 ^ t7; 390 | t9 = d | t7; 391 | t11 = t9 & t10; 392 | t14 = t2 ^ h; 393 | g = a ^ t11; 394 | t15 = g ^ t13; 395 | f = t14 ^ t15 396 | key[4 * 9 + 8] = e 397 | key[4 * 9 + 9] = f 398 | key[4 * 9 + 10] = g 399 | key[4 * 9 + 11] = h 400 | a = key[4 * 10 + 8] 401 | b = key[4 * 10 + 9] 402 | c = key[4 * 10 + 10] 403 | d = key[4 * 10 + 11] 404 | t1 = (~a) % 0x100000000; 405 | t2 = b ^ t1; 406 | t3 = a | t2; 407 | t4 = d | t2; 408 | t5 = c ^ t3; 409 | g = d ^ t5; 410 | t7 = b ^ t4; 411 | t8 = t2 ^ g; 412 | t9 = t5 & t7; 413 | h = t8 ^ t9; 414 | t11 = t5 ^ t7; 415 | f = h ^ t11; 416 | t13 = t8 & t11; 417 | e = t5 ^ t13 418 | key[4 * 10 + 8] = e 419 | key[4 * 10 + 9] = f 420 | key[4 * 10 + 10] = g 421 | key[4 * 10 + 11] = h 422 | a = key[4 * 11 + 8] 423 | b = key[4 * 11 + 9] 424 | c = key[4 * 11 + 10] 425 | d = key[4 * 11 + 11] 426 | t1 = a ^ d; 427 | t2 = a & d; 428 | t3 = c ^ t1; 429 | t6 = b & t1; 430 | t4 = b ^ t3; 431 | t10 = (~t3) % 0x100000000; 432 | h = t2 ^ t4; 433 | t7 = a ^ t6; 434 | t14 = (~t7) % 0x100000000; 435 | t8 = c | t7; 436 | t11 = t3 ^ t7; 437 | g = t4 ^ t8; 438 | t12 = h & t11; 439 | f = t10 ^ t12; 440 | e = t12 ^ t14 441 | key[4 * 11 + 8] = e 442 | key[4 * 11 + 9] = f 443 | key[4 * 11 + 10] = g 444 | key[4 * 11 + 11] = h 445 | a = key[4 * 12 + 8] 446 | b = key[4 * 12 + 9] 447 | c = key[4 * 12 + 10] 448 | d = key[4 * 12 + 11] 449 | t1 = (~c) % 0x100000000; 450 | t2 = b ^ c; 451 | t3 = b | t1; 452 | t4 = d ^ t3; 453 | t5 = a & t4; 454 | t7 = a ^ d; 455 | h = t2 ^ t5; 456 | t8 = b ^ t5; 457 | t9 = t2 | t8; 458 | t11 = d & t3; 459 | f = t7 ^ t9; 460 | t12 = t5 ^ f; 461 | t15 = t1 | t4; 462 | t13 = h & t12; 463 | g = t11 ^ t13; 464 | t16 = t12 ^ g; 465 | e = t15 ^ t16 466 | key[4 * 12 + 8] = e 467 | key[4 * 12 + 9] = f 468 | key[4 * 12 + 10] = g 469 | key[4 * 12 + 11] = h 470 | a = key[4 * 13 + 8] 471 | b = key[4 * 13 + 9] 472 | c = key[4 * 13 + 10] 473 | d = key[4 * 13 + 11] 474 | t1 = (~a) % 0x100000000; 475 | t2 = a ^ d; 476 | t3 = b ^ t2; 477 | t4 = t1 | t2; 478 | t5 = c ^ t4; 479 | f = b ^ t5; 480 | t13 = (~t5) % 0x100000000; 481 | t7 = t2 | f; 482 | t8 = d ^ t7; 483 | t9 = t5 & t8; 484 | g = t3 ^ t9; 485 | t11 = t5 ^ t8; 486 | e = g ^ t11; 487 | t14 = t3 & t11; 488 | h = t13 ^ t14 489 | key[4 * 13 + 8] = e 490 | key[4 * 13 + 9] = f 491 | key[4 * 13 + 10] = g 492 | key[4 * 13 + 11] = h 493 | a = key[4 * 14 + 8] 494 | b = key[4 * 14 + 9] 495 | c = key[4 * 14 + 10] 496 | d = key[4 * 14 + 11] 497 | t1 = (~a) % 0x100000000; 498 | t2 = a ^ b; 499 | t3 = a ^ d; 500 | t4 = c ^ t1; 501 | t5 = t2 | t3; 502 | e = t4 ^ t5; 503 | t7 = d & e; 504 | t8 = t2 ^ e; 505 | t10 = t1 | e; 506 | f = t7 ^ t8; 507 | t11 = t2 | t7; 508 | t12 = t3 ^ t10; 509 | t14 = b ^ t7; 510 | g = t11 ^ t12; 511 | t15 = f & t12; 512 | h = t14 ^ t15 513 | key[4 * 14 + 8] = e 514 | key[4 * 14 + 9] = f 515 | key[4 * 14 + 10] = g 516 | key[4 * 14 + 11] = h 517 | a = key[4 * 15 + 8] 518 | b = key[4 * 15 + 9] 519 | c = key[4 * 15 + 10] 520 | d = key[4 * 15 + 11] 521 | t1 = a ^ d; 522 | t2 = d & t1; 523 | t3 = c ^ t2; 524 | t4 = b | t3; 525 | h = t1 ^ t4; 526 | t6 = (~b) % 0x100000000; 527 | t7 = t1 | t6; 528 | e = t3 ^ t7; 529 | t9 = a & e; 530 | t10 = t1 ^ t6; 531 | t11 = t4 & t10; 532 | g = t9 ^ t11; 533 | t13 = a ^ t3; 534 | t14 = t10 & g; 535 | f = t13 ^ t14 536 | key[4 * 15 + 8] = e 537 | key[4 * 15 + 9] = f 538 | key[4 * 15 + 10] = g 539 | key[4 * 15 + 11] = h 540 | a = key[4 * 16 + 8] 541 | b = key[4 * 16 + 9] 542 | c = key[4 * 16 + 10] 543 | d = key[4 * 16 + 11] 544 | t1 = a ^ c; 545 | t2 = d ^ t1; 546 | t3 = a & t2; 547 | t4 = d ^ t3; 548 | t5 = b & t4; 549 | g = t2 ^ t5; 550 | t7 = a | g; 551 | t8 = b | d; 552 | t11 = a | d; 553 | t9 = t4 & t7; 554 | f = t8 ^ t9; 555 | t12 = b ^ t11; 556 | t13 = g ^ t9; 557 | t15 = t3 ^ t8; 558 | h = t12 ^ t13; 559 | t16 = c & t15; 560 | e = t12 ^ t16 561 | key[4 * 16 + 8] = e 562 | key[4 * 16 + 9] = f 563 | key[4 * 16 + 10] = g 564 | key[4 * 16 + 11] = h 565 | a = key[4 * 17 + 8] 566 | b = key[4 * 17 + 9] 567 | c = key[4 * 17 + 10] 568 | d = key[4 * 17 + 11] 569 | t1 = (~a) % 0x100000000; 570 | t2 = b ^ d; 571 | t3 = c & t1; 572 | t13 = d | t1; 573 | e = t2 ^ t3; 574 | t5 = c ^ t1; 575 | t6 = c ^ e; 576 | t7 = b & t6; 577 | t10 = e | t5; 578 | h = t5 ^ t7; 579 | t9 = d | t7; 580 | t11 = t9 & t10; 581 | t14 = t2 ^ h; 582 | g = a ^ t11; 583 | t15 = g ^ t13; 584 | f = t14 ^ t15 585 | key[4 * 17 + 8] = e 586 | key[4 * 17 + 9] = f 587 | key[4 * 17 + 10] = g 588 | key[4 * 17 + 11] = h 589 | a = key[4 * 18 + 8] 590 | b = key[4 * 18 + 9] 591 | c = key[4 * 18 + 10] 592 | d = key[4 * 18 + 11] 593 | t1 = (~a) % 0x100000000; 594 | t2 = b ^ t1; 595 | t3 = a | t2; 596 | t4 = d | t2; 597 | t5 = c ^ t3; 598 | g = d ^ t5; 599 | t7 = b ^ t4; 600 | t8 = t2 ^ g; 601 | t9 = t5 & t7; 602 | h = t8 ^ t9; 603 | t11 = t5 ^ t7; 604 | f = h ^ t11; 605 | t13 = t8 & t11; 606 | e = t5 ^ t13 607 | key[4 * 18 + 8] = e 608 | key[4 * 18 + 9] = f 609 | key[4 * 18 + 10] = g 610 | key[4 * 18 + 11] = h 611 | a = key[4 * 19 + 8] 612 | b = key[4 * 19 + 9] 613 | c = key[4 * 19 + 10] 614 | d = key[4 * 19 + 11] 615 | t1 = a ^ d; 616 | t2 = a & d; 617 | t3 = c ^ t1; 618 | t6 = b & t1; 619 | t4 = b ^ t3; 620 | t10 = (~t3) % 0x100000000; 621 | h = t2 ^ t4; 622 | t7 = a ^ t6; 623 | t14 = (~t7) % 0x100000000; 624 | t8 = c | t7; 625 | t11 = t3 ^ t7; 626 | g = t4 ^ t8; 627 | t12 = h & t11; 628 | f = t10 ^ t12; 629 | e = t12 ^ t14 630 | key[4 * 19 + 8] = e 631 | key[4 * 19 + 9] = f 632 | key[4 * 19 + 10] = g 633 | key[4 * 19 + 11] = h 634 | a = key[4 * 20 + 8] 635 | b = key[4 * 20 + 9] 636 | c = key[4 * 20 + 10] 637 | d = key[4 * 20 + 11] 638 | t1 = (~c) % 0x100000000; 639 | t2 = b ^ c; 640 | t3 = b | t1; 641 | t4 = d ^ t3; 642 | t5 = a & t4; 643 | t7 = a ^ d; 644 | h = t2 ^ t5; 645 | t8 = b ^ t5; 646 | t9 = t2 | t8; 647 | t11 = d & t3; 648 | f = t7 ^ t9; 649 | t12 = t5 ^ f; 650 | t15 = t1 | t4; 651 | t13 = h & t12; 652 | g = t11 ^ t13; 653 | t16 = t12 ^ g; 654 | e = t15 ^ t16 655 | key[4 * 20 + 8] = e 656 | key[4 * 20 + 9] = f 657 | key[4 * 20 + 10] = g 658 | key[4 * 20 + 11] = h 659 | a = key[4 * 21 + 8] 660 | b = key[4 * 21 + 9] 661 | c = key[4 * 21 + 10] 662 | d = key[4 * 21 + 11] 663 | t1 = (~a) % 0x100000000; 664 | t2 = a ^ d; 665 | t3 = b ^ t2; 666 | t4 = t1 | t2; 667 | t5 = c ^ t4; 668 | f = b ^ t5; 669 | t13 = (~t5) % 0x100000000; 670 | t7 = t2 | f; 671 | t8 = d ^ t7; 672 | t9 = t5 & t8; 673 | g = t3 ^ t9; 674 | t11 = t5 ^ t8; 675 | e = g ^ t11; 676 | t14 = t3 & t11; 677 | h = t13 ^ t14 678 | key[4 * 21 + 8] = e 679 | key[4 * 21 + 9] = f 680 | key[4 * 21 + 10] = g 681 | key[4 * 21 + 11] = h 682 | a = key[4 * 22 + 8] 683 | b = key[4 * 22 + 9] 684 | c = key[4 * 22 + 10] 685 | d = key[4 * 22 + 11] 686 | t1 = (~a) % 0x100000000; 687 | t2 = a ^ b; 688 | t3 = a ^ d; 689 | t4 = c ^ t1; 690 | t5 = t2 | t3; 691 | e = t4 ^ t5; 692 | t7 = d & e; 693 | t8 = t2 ^ e; 694 | t10 = t1 | e; 695 | f = t7 ^ t8; 696 | t11 = t2 | t7; 697 | t12 = t3 ^ t10; 698 | t14 = b ^ t7; 699 | g = t11 ^ t12; 700 | t15 = f & t12; 701 | h = t14 ^ t15 702 | key[4 * 22 + 8] = e 703 | key[4 * 22 + 9] = f 704 | key[4 * 22 + 10] = g 705 | key[4 * 22 + 11] = h 706 | a = key[4 * 23 + 8] 707 | b = key[4 * 23 + 9] 708 | c = key[4 * 23 + 10] 709 | d = key[4 * 23 + 11] 710 | t1 = a ^ d; 711 | t2 = d & t1; 712 | t3 = c ^ t2; 713 | t4 = b | t3; 714 | h = t1 ^ t4; 715 | t6 = (~b) % 0x100000000; 716 | t7 = t1 | t6; 717 | e = t3 ^ t7; 718 | t9 = a & e; 719 | t10 = t1 ^ t6; 720 | t11 = t4 & t10; 721 | g = t9 ^ t11; 722 | t13 = a ^ t3; 723 | t14 = t10 & g; 724 | f = t13 ^ t14 725 | key[4 * 23 + 8] = e 726 | key[4 * 23 + 9] = f 727 | key[4 * 23 + 10] = g 728 | key[4 * 23 + 11] = h 729 | a = key[4 * 24 + 8] 730 | b = key[4 * 24 + 9] 731 | c = key[4 * 24 + 10] 732 | d = key[4 * 24 + 11] 733 | t1 = a ^ c; 734 | t2 = d ^ t1; 735 | t3 = a & t2; 736 | t4 = d ^ t3; 737 | t5 = b & t4; 738 | g = t2 ^ t5; 739 | t7 = a | g; 740 | t8 = b | d; 741 | t11 = a | d; 742 | t9 = t4 & t7; 743 | f = t8 ^ t9; 744 | t12 = b ^ t11; 745 | t13 = g ^ t9; 746 | t15 = t3 ^ t8; 747 | h = t12 ^ t13; 748 | t16 = c & t15; 749 | e = t12 ^ t16 750 | key[4 * 24 + 8] = e 751 | key[4 * 24 + 9] = f 752 | key[4 * 24 + 10] = g 753 | key[4 * 24 + 11] = h 754 | a = key[4 * 25 + 8] 755 | b = key[4 * 25 + 9] 756 | c = key[4 * 25 + 10] 757 | d = key[4 * 25 + 11] 758 | t1 = (~a) % 0x100000000; 759 | t2 = b ^ d; 760 | t3 = c & t1; 761 | t13 = d | t1; 762 | e = t2 ^ t3; 763 | t5 = c ^ t1; 764 | t6 = c ^ e; 765 | t7 = b & t6; 766 | t10 = e | t5; 767 | h = t5 ^ t7; 768 | t9 = d | t7; 769 | t11 = t9 & t10; 770 | t14 = t2 ^ h; 771 | g = a ^ t11; 772 | t15 = g ^ t13; 773 | f = t14 ^ t15 774 | key[4 * 25 + 8] = e 775 | key[4 * 25 + 9] = f 776 | key[4 * 25 + 10] = g 777 | key[4 * 25 + 11] = h 778 | a = key[4 * 26 + 8] 779 | b = key[4 * 26 + 9] 780 | c = key[4 * 26 + 10] 781 | d = key[4 * 26 + 11] 782 | t1 = (~a) % 0x100000000; 783 | t2 = b ^ t1; 784 | t3 = a | t2; 785 | t4 = d | t2; 786 | t5 = c ^ t3; 787 | g = d ^ t5; 788 | t7 = b ^ t4; 789 | t8 = t2 ^ g; 790 | t9 = t5 & t7; 791 | h = t8 ^ t9; 792 | t11 = t5 ^ t7; 793 | f = h ^ t11; 794 | t13 = t8 & t11; 795 | e = t5 ^ t13 796 | key[4 * 26 + 8] = e 797 | key[4 * 26 + 9] = f 798 | key[4 * 26 + 10] = g 799 | key[4 * 26 + 11] = h 800 | a = key[4 * 27 + 8] 801 | b = key[4 * 27 + 9] 802 | c = key[4 * 27 + 10] 803 | d = key[4 * 27 + 11] 804 | t1 = a ^ d; 805 | t2 = a & d; 806 | t3 = c ^ t1; 807 | t6 = b & t1; 808 | t4 = b ^ t3; 809 | t10 = (~t3) % 0x100000000; 810 | h = t2 ^ t4; 811 | t7 = a ^ t6; 812 | t14 = (~t7) % 0x100000000; 813 | t8 = c | t7; 814 | t11 = t3 ^ t7; 815 | g = t4 ^ t8; 816 | t12 = h & t11; 817 | f = t10 ^ t12; 818 | e = t12 ^ t14 819 | key[4 * 27 + 8] = e 820 | key[4 * 27 + 9] = f 821 | key[4 * 27 + 10] = g 822 | key[4 * 27 + 11] = h 823 | a = key[4 * 28 + 8] 824 | b = key[4 * 28 + 9] 825 | c = key[4 * 28 + 10] 826 | d = key[4 * 28 + 11] 827 | t1 = (~c) % 0x100000000; 828 | t2 = b ^ c; 829 | t3 = b | t1; 830 | t4 = d ^ t3; 831 | t5 = a & t4; 832 | t7 = a ^ d; 833 | h = t2 ^ t5; 834 | t8 = b ^ t5; 835 | t9 = t2 | t8; 836 | t11 = d & t3; 837 | f = t7 ^ t9; 838 | t12 = t5 ^ f; 839 | t15 = t1 | t4; 840 | t13 = h & t12; 841 | g = t11 ^ t13; 842 | t16 = t12 ^ g; 843 | e = t15 ^ t16 844 | key[4 * 28 + 8] = e 845 | key[4 * 28 + 9] = f 846 | key[4 * 28 + 10] = g 847 | key[4 * 28 + 11] = h 848 | a = key[4 * 29 + 8] 849 | b = key[4 * 29 + 9] 850 | c = key[4 * 29 + 10] 851 | d = key[4 * 29 + 11] 852 | t1 = (~a) % 0x100000000; 853 | t2 = a ^ d; 854 | t3 = b ^ t2; 855 | t4 = t1 | t2; 856 | t5 = c ^ t4; 857 | f = b ^ t5; 858 | t13 = (~t5) % 0x100000000; 859 | t7 = t2 | f; 860 | t8 = d ^ t7; 861 | t9 = t5 & t8; 862 | g = t3 ^ t9; 863 | t11 = t5 ^ t8; 864 | e = g ^ t11; 865 | t14 = t3 & t11; 866 | h = t13 ^ t14 867 | key[4 * 29 + 8] = e 868 | key[4 * 29 + 9] = f 869 | key[4 * 29 + 10] = g 870 | key[4 * 29 + 11] = h 871 | a = key[4 * 30 + 8] 872 | b = key[4 * 30 + 9] 873 | c = key[4 * 30 + 10] 874 | d = key[4 * 30 + 11] 875 | t1 = (~a) % 0x100000000; 876 | t2 = a ^ b; 877 | t3 = a ^ d; 878 | t4 = c ^ t1; 879 | t5 = t2 | t3; 880 | e = t4 ^ t5; 881 | t7 = d & e; 882 | t8 = t2 ^ e; 883 | t10 = t1 | e; 884 | f = t7 ^ t8; 885 | t11 = t2 | t7; 886 | t12 = t3 ^ t10; 887 | t14 = b ^ t7; 888 | g = t11 ^ t12; 889 | t15 = f & t12; 890 | h = t14 ^ t15 891 | key[4 * 30 + 8] = e 892 | key[4 * 30 + 9] = f 893 | key[4 * 30 + 10] = g 894 | key[4 * 30 + 11] = h 895 | a = key[4 * 31 + 8] 896 | b = key[4 * 31 + 9] 897 | c = key[4 * 31 + 10] 898 | d = key[4 * 31 + 11] 899 | t1 = a ^ d; 900 | t2 = d & t1; 901 | t3 = c ^ t2; 902 | t4 = b | t3; 903 | h = t1 ^ t4; 904 | t6 = (~b) % 0x100000000; 905 | t7 = t1 | t6; 906 | e = t3 ^ t7; 907 | t9 = a & e; 908 | t10 = t1 ^ t6; 909 | t11 = t4 & t10; 910 | g = t9 ^ t11; 911 | t13 = a ^ t3; 912 | t14 = t10 & g; 913 | f = t13 ^ t14 914 | key[4 * 31 + 8] = e 915 | key[4 * 31 + 9] = f 916 | key[4 * 31 + 10] = g 917 | key[4 * 31 + 11] = h 918 | a = key[4 * 32 + 8] 919 | b = key[4 * 32 + 9] 920 | c = key[4 * 32 + 10] 921 | d = key[4 * 32 + 11] 922 | t1 = a ^ c; 923 | t2 = d ^ t1; 924 | t3 = a & t2; 925 | t4 = d ^ t3; 926 | t5 = b & t4; 927 | g = t2 ^ t5; 928 | t7 = a | g; 929 | t8 = b | d; 930 | t11 = a | d; 931 | t9 = t4 & t7; 932 | f = t8 ^ t9; 933 | t12 = b ^ t11; 934 | t13 = g ^ t9; 935 | t15 = t3 ^ t8; 936 | h = t12 ^ t13; 937 | t16 = c & t15; 938 | e = t12 ^ t16 939 | key[4 * 32 + 8] = e 940 | key[4 * 32 + 9] = f 941 | key[4 * 32 + 10] = g 942 | key[4 * 32 + 11] = h 943 | 944 | 945 | def encrypt(key, in_blk): 946 | # serpent_generate.py 947 | a = in_blk[0] 948 | b = in_blk[1] 949 | c = in_blk[2] 950 | d = in_blk[3] 951 | if WORD_BIGENDIAN: 952 | a = byteswap32(a) 953 | b = byteswap32(b) 954 | c = byteswap32(c) 955 | d = byteswap32(d) 956 | e = 0 957 | f = 0 958 | g = 0 959 | h = 0 960 | t1 = 0 961 | t2 = 0 962 | t3 = 0 963 | t4 = 0 964 | t5 = 0 965 | t6 = 0 966 | t7 = 0 967 | t8 = 0 968 | t9 = 0 969 | t10 = 0 970 | t11 = 0 971 | t12 = 0 972 | t13 = 0 973 | t14 = 0 974 | t15 = 0 975 | t16 = 0 976 | a ^= key[4 * 0 + 8] 977 | b ^= key[4 * 0 + 9] 978 | c ^= key[4 * 0 + 10] 979 | d ^= key[4 * 0 + 11] 980 | t1 = a ^ d; 981 | t2 = a & d; 982 | t3 = c ^ t1; 983 | t6 = b & t1; 984 | t4 = b ^ t3; 985 | t10 = (~t3) % 0x100000000; 986 | h = t2 ^ t4; 987 | t7 = a ^ t6; 988 | t14 = (~t7) % 0x100000000; 989 | t8 = c | t7; 990 | t11 = t3 ^ t7; 991 | g = t4 ^ t8; 992 | t12 = h & t11; 993 | f = t10 ^ t12; 994 | e = t12 ^ t14 995 | e = rotl32(e, 13) 996 | g = rotl32(g, 3) 997 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 998 | f ^= e ^ g 999 | h = rotl32(h, 7) 1000 | f = rotl32(f, 1) 1001 | e ^= f ^ h 1002 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1003 | e = rotl32(e, 5) 1004 | g = rotl32(g, 22) 1005 | e ^= key[4 * 1 + 8] 1006 | f ^= key[4 * 1 + 9] 1007 | g ^= key[4 * 1 + 10] 1008 | h ^= key[4 * 1 + 11] 1009 | t1 = (~e) % 0x100000000; 1010 | t2 = f ^ t1; 1011 | t3 = e | t2; 1012 | t4 = h | t2; 1013 | t5 = g ^ t3; 1014 | c = h ^ t5; 1015 | t7 = f ^ t4; 1016 | t8 = t2 ^ c; 1017 | t9 = t5 & t7; 1018 | d = t8 ^ t9; 1019 | t11 = t5 ^ t7; 1020 | b = d ^ t11; 1021 | t13 = t8 & t11; 1022 | a = t5 ^ t13 1023 | a = rotl32(a, 13) 1024 | c = rotl32(c, 3) 1025 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1026 | b ^= a ^ c 1027 | d = rotl32(d, 7) 1028 | b = rotl32(b, 1) 1029 | a ^= b ^ d 1030 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1031 | a = rotl32(a, 5) 1032 | c = rotl32(c, 22) 1033 | a ^= key[4 * 2 + 8] 1034 | b ^= key[4 * 2 + 9] 1035 | c ^= key[4 * 2 + 10] 1036 | d ^= key[4 * 2 + 11] 1037 | t1 = (~a) % 0x100000000; 1038 | t2 = b ^ d; 1039 | t3 = c & t1; 1040 | t13 = d | t1; 1041 | e = t2 ^ t3; 1042 | t5 = c ^ t1; 1043 | t6 = c ^ e; 1044 | t7 = b & t6; 1045 | t10 = e | t5; 1046 | h = t5 ^ t7; 1047 | t9 = d | t7; 1048 | t11 = t9 & t10; 1049 | t14 = t2 ^ h; 1050 | g = a ^ t11; 1051 | t15 = g ^ t13; 1052 | f = t14 ^ t15 1053 | e = rotl32(e, 13) 1054 | g = rotl32(g, 3) 1055 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1056 | f ^= e ^ g 1057 | h = rotl32(h, 7) 1058 | f = rotl32(f, 1) 1059 | e ^= f ^ h 1060 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1061 | e = rotl32(e, 5) 1062 | g = rotl32(g, 22) 1063 | e ^= key[4 * 3 + 8] 1064 | f ^= key[4 * 3 + 9] 1065 | g ^= key[4 * 3 + 10] 1066 | h ^= key[4 * 3 + 11] 1067 | t1 = e ^ g; 1068 | t2 = h ^ t1; 1069 | t3 = e & t2; 1070 | t4 = h ^ t3; 1071 | t5 = f & t4; 1072 | c = t2 ^ t5; 1073 | t7 = e | c; 1074 | t8 = f | h; 1075 | t11 = e | h; 1076 | t9 = t4 & t7; 1077 | b = t8 ^ t9; 1078 | t12 = f ^ t11; 1079 | t13 = c ^ t9; 1080 | t15 = t3 ^ t8; 1081 | d = t12 ^ t13; 1082 | t16 = g & t15; 1083 | a = t12 ^ t16 1084 | a = rotl32(a, 13) 1085 | c = rotl32(c, 3) 1086 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1087 | b ^= a ^ c 1088 | d = rotl32(d, 7) 1089 | b = rotl32(b, 1) 1090 | a ^= b ^ d 1091 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1092 | a = rotl32(a, 5) 1093 | c = rotl32(c, 22) 1094 | a ^= key[4 * 4 + 8] 1095 | b ^= key[4 * 4 + 9] 1096 | c ^= key[4 * 4 + 10] 1097 | d ^= key[4 * 4 + 11] 1098 | t1 = a ^ d; 1099 | t2 = d & t1; 1100 | t3 = c ^ t2; 1101 | t4 = b | t3; 1102 | h = t1 ^ t4; 1103 | t6 = (~b) % 0x100000000; 1104 | t7 = t1 | t6; 1105 | e = t3 ^ t7; 1106 | t9 = a & e; 1107 | t10 = t1 ^ t6; 1108 | t11 = t4 & t10; 1109 | g = t9 ^ t11; 1110 | t13 = a ^ t3; 1111 | t14 = t10 & g; 1112 | f = t13 ^ t14 1113 | e = rotl32(e, 13) 1114 | g = rotl32(g, 3) 1115 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1116 | f ^= e ^ g 1117 | h = rotl32(h, 7) 1118 | f = rotl32(f, 1) 1119 | e ^= f ^ h 1120 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1121 | e = rotl32(e, 5) 1122 | g = rotl32(g, 22) 1123 | e ^= key[4 * 5 + 8] 1124 | f ^= key[4 * 5 + 9] 1125 | g ^= key[4 * 5 + 10] 1126 | h ^= key[4 * 5 + 11] 1127 | t1 = (~e) % 0x100000000; 1128 | t2 = e ^ f; 1129 | t3 = e ^ h; 1130 | t4 = g ^ t1; 1131 | t5 = t2 | t3; 1132 | a = t4 ^ t5; 1133 | t7 = h & a; 1134 | t8 = t2 ^ a; 1135 | t10 = t1 | a; 1136 | b = t7 ^ t8; 1137 | t11 = t2 | t7; 1138 | t12 = t3 ^ t10; 1139 | t14 = f ^ t7; 1140 | c = t11 ^ t12; 1141 | t15 = b & t12; 1142 | d = t14 ^ t15 1143 | a = rotl32(a, 13) 1144 | c = rotl32(c, 3) 1145 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1146 | b ^= a ^ c 1147 | d = rotl32(d, 7) 1148 | b = rotl32(b, 1) 1149 | a ^= b ^ d 1150 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1151 | a = rotl32(a, 5) 1152 | c = rotl32(c, 22) 1153 | a ^= key[4 * 6 + 8] 1154 | b ^= key[4 * 6 + 9] 1155 | c ^= key[4 * 6 + 10] 1156 | d ^= key[4 * 6 + 11] 1157 | t1 = (~a) % 0x100000000; 1158 | t2 = a ^ d; 1159 | t3 = b ^ t2; 1160 | t4 = t1 | t2; 1161 | t5 = c ^ t4; 1162 | f = b ^ t5; 1163 | t13 = (~t5) % 0x100000000; 1164 | t7 = t2 | f; 1165 | t8 = d ^ t7; 1166 | t9 = t5 & t8; 1167 | g = t3 ^ t9; 1168 | t11 = t5 ^ t8; 1169 | e = g ^ t11; 1170 | t14 = t3 & t11; 1171 | h = t13 ^ t14 1172 | e = rotl32(e, 13) 1173 | g = rotl32(g, 3) 1174 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1175 | f ^= e ^ g 1176 | h = rotl32(h, 7) 1177 | f = rotl32(f, 1) 1178 | e ^= f ^ h 1179 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1180 | e = rotl32(e, 5) 1181 | g = rotl32(g, 22) 1182 | e ^= key[4 * 7 + 8] 1183 | f ^= key[4 * 7 + 9] 1184 | g ^= key[4 * 7 + 10] 1185 | h ^= key[4 * 7 + 11] 1186 | t1 = (~g) % 0x100000000; 1187 | t2 = f ^ g; 1188 | t3 = f | t1; 1189 | t4 = h ^ t3; 1190 | t5 = e & t4; 1191 | t7 = e ^ h; 1192 | d = t2 ^ t5; 1193 | t8 = f ^ t5; 1194 | t9 = t2 | t8; 1195 | t11 = h & t3; 1196 | b = t7 ^ t9; 1197 | t12 = t5 ^ b; 1198 | t15 = t1 | t4; 1199 | t13 = d & t12; 1200 | c = t11 ^ t13; 1201 | t16 = t12 ^ c; 1202 | a = t15 ^ t16 1203 | a = rotl32(a, 13) 1204 | c = rotl32(c, 3) 1205 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1206 | b ^= a ^ c 1207 | d = rotl32(d, 7) 1208 | b = rotl32(b, 1) 1209 | a ^= b ^ d 1210 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1211 | a = rotl32(a, 5) 1212 | c = rotl32(c, 22) 1213 | a ^= key[4 * 8 + 8] 1214 | b ^= key[4 * 8 + 9] 1215 | c ^= key[4 * 8 + 10] 1216 | d ^= key[4 * 8 + 11] 1217 | t1 = a ^ d; 1218 | t2 = a & d; 1219 | t3 = c ^ t1; 1220 | t6 = b & t1; 1221 | t4 = b ^ t3; 1222 | t10 = (~t3) % 0x100000000; 1223 | h = t2 ^ t4; 1224 | t7 = a ^ t6; 1225 | t14 = (~t7) % 0x100000000; 1226 | t8 = c | t7; 1227 | t11 = t3 ^ t7; 1228 | g = t4 ^ t8; 1229 | t12 = h & t11; 1230 | f = t10 ^ t12; 1231 | e = t12 ^ t14 1232 | e = rotl32(e, 13) 1233 | g = rotl32(g, 3) 1234 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1235 | f ^= e ^ g 1236 | h = rotl32(h, 7) 1237 | f = rotl32(f, 1) 1238 | e ^= f ^ h 1239 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1240 | e = rotl32(e, 5) 1241 | g = rotl32(g, 22) 1242 | e ^= key[4 * 9 + 8] 1243 | f ^= key[4 * 9 + 9] 1244 | g ^= key[4 * 9 + 10] 1245 | h ^= key[4 * 9 + 11] 1246 | t1 = (~e) % 0x100000000; 1247 | t2 = f ^ t1; 1248 | t3 = e | t2; 1249 | t4 = h | t2; 1250 | t5 = g ^ t3; 1251 | c = h ^ t5; 1252 | t7 = f ^ t4; 1253 | t8 = t2 ^ c; 1254 | t9 = t5 & t7; 1255 | d = t8 ^ t9; 1256 | t11 = t5 ^ t7; 1257 | b = d ^ t11; 1258 | t13 = t8 & t11; 1259 | a = t5 ^ t13 1260 | a = rotl32(a, 13) 1261 | c = rotl32(c, 3) 1262 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1263 | b ^= a ^ c 1264 | d = rotl32(d, 7) 1265 | b = rotl32(b, 1) 1266 | a ^= b ^ d 1267 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1268 | a = rotl32(a, 5) 1269 | c = rotl32(c, 22) 1270 | a ^= key[4 * 10 + 8] 1271 | b ^= key[4 * 10 + 9] 1272 | c ^= key[4 * 10 + 10] 1273 | d ^= key[4 * 10 + 11] 1274 | t1 = (~a) % 0x100000000; 1275 | t2 = b ^ d; 1276 | t3 = c & t1; 1277 | t13 = d | t1; 1278 | e = t2 ^ t3; 1279 | t5 = c ^ t1; 1280 | t6 = c ^ e; 1281 | t7 = b & t6; 1282 | t10 = e | t5; 1283 | h = t5 ^ t7; 1284 | t9 = d | t7; 1285 | t11 = t9 & t10; 1286 | t14 = t2 ^ h; 1287 | g = a ^ t11; 1288 | t15 = g ^ t13; 1289 | f = t14 ^ t15 1290 | e = rotl32(e, 13) 1291 | g = rotl32(g, 3) 1292 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1293 | f ^= e ^ g 1294 | h = rotl32(h, 7) 1295 | f = rotl32(f, 1) 1296 | e ^= f ^ h 1297 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1298 | e = rotl32(e, 5) 1299 | g = rotl32(g, 22) 1300 | e ^= key[4 * 11 + 8] 1301 | f ^= key[4 * 11 + 9] 1302 | g ^= key[4 * 11 + 10] 1303 | h ^= key[4 * 11 + 11] 1304 | t1 = e ^ g; 1305 | t2 = h ^ t1; 1306 | t3 = e & t2; 1307 | t4 = h ^ t3; 1308 | t5 = f & t4; 1309 | c = t2 ^ t5; 1310 | t7 = e | c; 1311 | t8 = f | h; 1312 | t11 = e | h; 1313 | t9 = t4 & t7; 1314 | b = t8 ^ t9; 1315 | t12 = f ^ t11; 1316 | t13 = c ^ t9; 1317 | t15 = t3 ^ t8; 1318 | d = t12 ^ t13; 1319 | t16 = g & t15; 1320 | a = t12 ^ t16 1321 | a = rotl32(a, 13) 1322 | c = rotl32(c, 3) 1323 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1324 | b ^= a ^ c 1325 | d = rotl32(d, 7) 1326 | b = rotl32(b, 1) 1327 | a ^= b ^ d 1328 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1329 | a = rotl32(a, 5) 1330 | c = rotl32(c, 22) 1331 | a ^= key[4 * 12 + 8] 1332 | b ^= key[4 * 12 + 9] 1333 | c ^= key[4 * 12 + 10] 1334 | d ^= key[4 * 12 + 11] 1335 | t1 = a ^ d; 1336 | t2 = d & t1; 1337 | t3 = c ^ t2; 1338 | t4 = b | t3; 1339 | h = t1 ^ t4; 1340 | t6 = (~b) % 0x100000000; 1341 | t7 = t1 | t6; 1342 | e = t3 ^ t7; 1343 | t9 = a & e; 1344 | t10 = t1 ^ t6; 1345 | t11 = t4 & t10; 1346 | g = t9 ^ t11; 1347 | t13 = a ^ t3; 1348 | t14 = t10 & g; 1349 | f = t13 ^ t14 1350 | e = rotl32(e, 13) 1351 | g = rotl32(g, 3) 1352 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1353 | f ^= e ^ g 1354 | h = rotl32(h, 7) 1355 | f = rotl32(f, 1) 1356 | e ^= f ^ h 1357 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1358 | e = rotl32(e, 5) 1359 | g = rotl32(g, 22) 1360 | e ^= key[4 * 13 + 8] 1361 | f ^= key[4 * 13 + 9] 1362 | g ^= key[4 * 13 + 10] 1363 | h ^= key[4 * 13 + 11] 1364 | t1 = (~e) % 0x100000000; 1365 | t2 = e ^ f; 1366 | t3 = e ^ h; 1367 | t4 = g ^ t1; 1368 | t5 = t2 | t3; 1369 | a = t4 ^ t5; 1370 | t7 = h & a; 1371 | t8 = t2 ^ a; 1372 | t10 = t1 | a; 1373 | b = t7 ^ t8; 1374 | t11 = t2 | t7; 1375 | t12 = t3 ^ t10; 1376 | t14 = f ^ t7; 1377 | c = t11 ^ t12; 1378 | t15 = b & t12; 1379 | d = t14 ^ t15 1380 | a = rotl32(a, 13) 1381 | c = rotl32(c, 3) 1382 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1383 | b ^= a ^ c 1384 | d = rotl32(d, 7) 1385 | b = rotl32(b, 1) 1386 | a ^= b ^ d 1387 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1388 | a = rotl32(a, 5) 1389 | c = rotl32(c, 22) 1390 | a ^= key[4 * 14 + 8] 1391 | b ^= key[4 * 14 + 9] 1392 | c ^= key[4 * 14 + 10] 1393 | d ^= key[4 * 14 + 11] 1394 | t1 = (~a) % 0x100000000; 1395 | t2 = a ^ d; 1396 | t3 = b ^ t2; 1397 | t4 = t1 | t2; 1398 | t5 = c ^ t4; 1399 | f = b ^ t5; 1400 | t13 = (~t5) % 0x100000000; 1401 | t7 = t2 | f; 1402 | t8 = d ^ t7; 1403 | t9 = t5 & t8; 1404 | g = t3 ^ t9; 1405 | t11 = t5 ^ t8; 1406 | e = g ^ t11; 1407 | t14 = t3 & t11; 1408 | h = t13 ^ t14 1409 | e = rotl32(e, 13) 1410 | g = rotl32(g, 3) 1411 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1412 | f ^= e ^ g 1413 | h = rotl32(h, 7) 1414 | f = rotl32(f, 1) 1415 | e ^= f ^ h 1416 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1417 | e = rotl32(e, 5) 1418 | g = rotl32(g, 22) 1419 | e ^= key[4 * 15 + 8] 1420 | f ^= key[4 * 15 + 9] 1421 | g ^= key[4 * 15 + 10] 1422 | h ^= key[4 * 15 + 11] 1423 | t1 = (~g) % 0x100000000; 1424 | t2 = f ^ g; 1425 | t3 = f | t1; 1426 | t4 = h ^ t3; 1427 | t5 = e & t4; 1428 | t7 = e ^ h; 1429 | d = t2 ^ t5; 1430 | t8 = f ^ t5; 1431 | t9 = t2 | t8; 1432 | t11 = h & t3; 1433 | b = t7 ^ t9; 1434 | t12 = t5 ^ b; 1435 | t15 = t1 | t4; 1436 | t13 = d & t12; 1437 | c = t11 ^ t13; 1438 | t16 = t12 ^ c; 1439 | a = t15 ^ t16 1440 | a = rotl32(a, 13) 1441 | c = rotl32(c, 3) 1442 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1443 | b ^= a ^ c 1444 | d = rotl32(d, 7) 1445 | b = rotl32(b, 1) 1446 | a ^= b ^ d 1447 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1448 | a = rotl32(a, 5) 1449 | c = rotl32(c, 22) 1450 | a ^= key[4 * 16 + 8] 1451 | b ^= key[4 * 16 + 9] 1452 | c ^= key[4 * 16 + 10] 1453 | d ^= key[4 * 16 + 11] 1454 | t1 = a ^ d; 1455 | t2 = a & d; 1456 | t3 = c ^ t1; 1457 | t6 = b & t1; 1458 | t4 = b ^ t3; 1459 | t10 = (~t3) % 0x100000000; 1460 | h = t2 ^ t4; 1461 | t7 = a ^ t6; 1462 | t14 = (~t7) % 0x100000000; 1463 | t8 = c | t7; 1464 | t11 = t3 ^ t7; 1465 | g = t4 ^ t8; 1466 | t12 = h & t11; 1467 | f = t10 ^ t12; 1468 | e = t12 ^ t14 1469 | e = rotl32(e, 13) 1470 | g = rotl32(g, 3) 1471 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1472 | f ^= e ^ g 1473 | h = rotl32(h, 7) 1474 | f = rotl32(f, 1) 1475 | e ^= f ^ h 1476 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1477 | e = rotl32(e, 5) 1478 | g = rotl32(g, 22) 1479 | e ^= key[4 * 17 + 8] 1480 | f ^= key[4 * 17 + 9] 1481 | g ^= key[4 * 17 + 10] 1482 | h ^= key[4 * 17 + 11] 1483 | t1 = (~e) % 0x100000000; 1484 | t2 = f ^ t1; 1485 | t3 = e | t2; 1486 | t4 = h | t2; 1487 | t5 = g ^ t3; 1488 | c = h ^ t5; 1489 | t7 = f ^ t4; 1490 | t8 = t2 ^ c; 1491 | t9 = t5 & t7; 1492 | d = t8 ^ t9; 1493 | t11 = t5 ^ t7; 1494 | b = d ^ t11; 1495 | t13 = t8 & t11; 1496 | a = t5 ^ t13 1497 | a = rotl32(a, 13) 1498 | c = rotl32(c, 3) 1499 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1500 | b ^= a ^ c 1501 | d = rotl32(d, 7) 1502 | b = rotl32(b, 1) 1503 | a ^= b ^ d 1504 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1505 | a = rotl32(a, 5) 1506 | c = rotl32(c, 22) 1507 | a ^= key[4 * 18 + 8] 1508 | b ^= key[4 * 18 + 9] 1509 | c ^= key[4 * 18 + 10] 1510 | d ^= key[4 * 18 + 11] 1511 | t1 = (~a) % 0x100000000; 1512 | t2 = b ^ d; 1513 | t3 = c & t1; 1514 | t13 = d | t1; 1515 | e = t2 ^ t3; 1516 | t5 = c ^ t1; 1517 | t6 = c ^ e; 1518 | t7 = b & t6; 1519 | t10 = e | t5; 1520 | h = t5 ^ t7; 1521 | t9 = d | t7; 1522 | t11 = t9 & t10; 1523 | t14 = t2 ^ h; 1524 | g = a ^ t11; 1525 | t15 = g ^ t13; 1526 | f = t14 ^ t15 1527 | e = rotl32(e, 13) 1528 | g = rotl32(g, 3) 1529 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1530 | f ^= e ^ g 1531 | h = rotl32(h, 7) 1532 | f = rotl32(f, 1) 1533 | e ^= f ^ h 1534 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1535 | e = rotl32(e, 5) 1536 | g = rotl32(g, 22) 1537 | e ^= key[4 * 19 + 8] 1538 | f ^= key[4 * 19 + 9] 1539 | g ^= key[4 * 19 + 10] 1540 | h ^= key[4 * 19 + 11] 1541 | t1 = e ^ g; 1542 | t2 = h ^ t1; 1543 | t3 = e & t2; 1544 | t4 = h ^ t3; 1545 | t5 = f & t4; 1546 | c = t2 ^ t5; 1547 | t7 = e | c; 1548 | t8 = f | h; 1549 | t11 = e | h; 1550 | t9 = t4 & t7; 1551 | b = t8 ^ t9; 1552 | t12 = f ^ t11; 1553 | t13 = c ^ t9; 1554 | t15 = t3 ^ t8; 1555 | d = t12 ^ t13; 1556 | t16 = g & t15; 1557 | a = t12 ^ t16 1558 | a = rotl32(a, 13) 1559 | c = rotl32(c, 3) 1560 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1561 | b ^= a ^ c 1562 | d = rotl32(d, 7) 1563 | b = rotl32(b, 1) 1564 | a ^= b ^ d 1565 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1566 | a = rotl32(a, 5) 1567 | c = rotl32(c, 22) 1568 | a ^= key[4 * 20 + 8] 1569 | b ^= key[4 * 20 + 9] 1570 | c ^= key[4 * 20 + 10] 1571 | d ^= key[4 * 20 + 11] 1572 | t1 = a ^ d; 1573 | t2 = d & t1; 1574 | t3 = c ^ t2; 1575 | t4 = b | t3; 1576 | h = t1 ^ t4; 1577 | t6 = (~b) % 0x100000000; 1578 | t7 = t1 | t6; 1579 | e = t3 ^ t7; 1580 | t9 = a & e; 1581 | t10 = t1 ^ t6; 1582 | t11 = t4 & t10; 1583 | g = t9 ^ t11; 1584 | t13 = a ^ t3; 1585 | t14 = t10 & g; 1586 | f = t13 ^ t14 1587 | e = rotl32(e, 13) 1588 | g = rotl32(g, 3) 1589 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1590 | f ^= e ^ g 1591 | h = rotl32(h, 7) 1592 | f = rotl32(f, 1) 1593 | e ^= f ^ h 1594 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1595 | e = rotl32(e, 5) 1596 | g = rotl32(g, 22) 1597 | e ^= key[4 * 21 + 8] 1598 | f ^= key[4 * 21 + 9] 1599 | g ^= key[4 * 21 + 10] 1600 | h ^= key[4 * 21 + 11] 1601 | t1 = (~e) % 0x100000000; 1602 | t2 = e ^ f; 1603 | t3 = e ^ h; 1604 | t4 = g ^ t1; 1605 | t5 = t2 | t3; 1606 | a = t4 ^ t5; 1607 | t7 = h & a; 1608 | t8 = t2 ^ a; 1609 | t10 = t1 | a; 1610 | b = t7 ^ t8; 1611 | t11 = t2 | t7; 1612 | t12 = t3 ^ t10; 1613 | t14 = f ^ t7; 1614 | c = t11 ^ t12; 1615 | t15 = b & t12; 1616 | d = t14 ^ t15 1617 | a = rotl32(a, 13) 1618 | c = rotl32(c, 3) 1619 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1620 | b ^= a ^ c 1621 | d = rotl32(d, 7) 1622 | b = rotl32(b, 1) 1623 | a ^= b ^ d 1624 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1625 | a = rotl32(a, 5) 1626 | c = rotl32(c, 22) 1627 | a ^= key[4 * 22 + 8] 1628 | b ^= key[4 * 22 + 9] 1629 | c ^= key[4 * 22 + 10] 1630 | d ^= key[4 * 22 + 11] 1631 | t1 = (~a) % 0x100000000; 1632 | t2 = a ^ d; 1633 | t3 = b ^ t2; 1634 | t4 = t1 | t2; 1635 | t5 = c ^ t4; 1636 | f = b ^ t5; 1637 | t13 = (~t5) % 0x100000000; 1638 | t7 = t2 | f; 1639 | t8 = d ^ t7; 1640 | t9 = t5 & t8; 1641 | g = t3 ^ t9; 1642 | t11 = t5 ^ t8; 1643 | e = g ^ t11; 1644 | t14 = t3 & t11; 1645 | h = t13 ^ t14 1646 | e = rotl32(e, 13) 1647 | g = rotl32(g, 3) 1648 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1649 | f ^= e ^ g 1650 | h = rotl32(h, 7) 1651 | f = rotl32(f, 1) 1652 | e ^= f ^ h 1653 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1654 | e = rotl32(e, 5) 1655 | g = rotl32(g, 22) 1656 | e ^= key[4 * 23 + 8] 1657 | f ^= key[4 * 23 + 9] 1658 | g ^= key[4 * 23 + 10] 1659 | h ^= key[4 * 23 + 11] 1660 | t1 = (~g) % 0x100000000; 1661 | t2 = f ^ g; 1662 | t3 = f | t1; 1663 | t4 = h ^ t3; 1664 | t5 = e & t4; 1665 | t7 = e ^ h; 1666 | d = t2 ^ t5; 1667 | t8 = f ^ t5; 1668 | t9 = t2 | t8; 1669 | t11 = h & t3; 1670 | b = t7 ^ t9; 1671 | t12 = t5 ^ b; 1672 | t15 = t1 | t4; 1673 | t13 = d & t12; 1674 | c = t11 ^ t13; 1675 | t16 = t12 ^ c; 1676 | a = t15 ^ t16 1677 | a = rotl32(a, 13) 1678 | c = rotl32(c, 3) 1679 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1680 | b ^= a ^ c 1681 | d = rotl32(d, 7) 1682 | b = rotl32(b, 1) 1683 | a ^= b ^ d 1684 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1685 | a = rotl32(a, 5) 1686 | c = rotl32(c, 22) 1687 | a ^= key[4 * 24 + 8] 1688 | b ^= key[4 * 24 + 9] 1689 | c ^= key[4 * 24 + 10] 1690 | d ^= key[4 * 24 + 11] 1691 | t1 = a ^ d; 1692 | t2 = a & d; 1693 | t3 = c ^ t1; 1694 | t6 = b & t1; 1695 | t4 = b ^ t3; 1696 | t10 = (~t3) % 0x100000000; 1697 | h = t2 ^ t4; 1698 | t7 = a ^ t6; 1699 | t14 = (~t7) % 0x100000000; 1700 | t8 = c | t7; 1701 | t11 = t3 ^ t7; 1702 | g = t4 ^ t8; 1703 | t12 = h & t11; 1704 | f = t10 ^ t12; 1705 | e = t12 ^ t14 1706 | e = rotl32(e, 13) 1707 | g = rotl32(g, 3) 1708 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1709 | f ^= e ^ g 1710 | h = rotl32(h, 7) 1711 | f = rotl32(f, 1) 1712 | e ^= f ^ h 1713 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1714 | e = rotl32(e, 5) 1715 | g = rotl32(g, 22) 1716 | e ^= key[4 * 25 + 8] 1717 | f ^= key[4 * 25 + 9] 1718 | g ^= key[4 * 25 + 10] 1719 | h ^= key[4 * 25 + 11] 1720 | t1 = (~e) % 0x100000000; 1721 | t2 = f ^ t1; 1722 | t3 = e | t2; 1723 | t4 = h | t2; 1724 | t5 = g ^ t3; 1725 | c = h ^ t5; 1726 | t7 = f ^ t4; 1727 | t8 = t2 ^ c; 1728 | t9 = t5 & t7; 1729 | d = t8 ^ t9; 1730 | t11 = t5 ^ t7; 1731 | b = d ^ t11; 1732 | t13 = t8 & t11; 1733 | a = t5 ^ t13 1734 | a = rotl32(a, 13) 1735 | c = rotl32(c, 3) 1736 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1737 | b ^= a ^ c 1738 | d = rotl32(d, 7) 1739 | b = rotl32(b, 1) 1740 | a ^= b ^ d 1741 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1742 | a = rotl32(a, 5) 1743 | c = rotl32(c, 22) 1744 | a ^= key[4 * 26 + 8] 1745 | b ^= key[4 * 26 + 9] 1746 | c ^= key[4 * 26 + 10] 1747 | d ^= key[4 * 26 + 11] 1748 | t1 = (~a) % 0x100000000; 1749 | t2 = b ^ d; 1750 | t3 = c & t1; 1751 | t13 = d | t1; 1752 | e = t2 ^ t3; 1753 | t5 = c ^ t1; 1754 | t6 = c ^ e; 1755 | t7 = b & t6; 1756 | t10 = e | t5; 1757 | h = t5 ^ t7; 1758 | t9 = d | t7; 1759 | t11 = t9 & t10; 1760 | t14 = t2 ^ h; 1761 | g = a ^ t11; 1762 | t15 = g ^ t13; 1763 | f = t14 ^ t15 1764 | e = rotl32(e, 13) 1765 | g = rotl32(g, 3) 1766 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1767 | f ^= e ^ g 1768 | h = rotl32(h, 7) 1769 | f = rotl32(f, 1) 1770 | e ^= f ^ h 1771 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1772 | e = rotl32(e, 5) 1773 | g = rotl32(g, 22) 1774 | e ^= key[4 * 27 + 8] 1775 | f ^= key[4 * 27 + 9] 1776 | g ^= key[4 * 27 + 10] 1777 | h ^= key[4 * 27 + 11] 1778 | t1 = e ^ g; 1779 | t2 = h ^ t1; 1780 | t3 = e & t2; 1781 | t4 = h ^ t3; 1782 | t5 = f & t4; 1783 | c = t2 ^ t5; 1784 | t7 = e | c; 1785 | t8 = f | h; 1786 | t11 = e | h; 1787 | t9 = t4 & t7; 1788 | b = t8 ^ t9; 1789 | t12 = f ^ t11; 1790 | t13 = c ^ t9; 1791 | t15 = t3 ^ t8; 1792 | d = t12 ^ t13; 1793 | t16 = g & t15; 1794 | a = t12 ^ t16 1795 | a = rotl32(a, 13) 1796 | c = rotl32(c, 3) 1797 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1798 | b ^= a ^ c 1799 | d = rotl32(d, 7) 1800 | b = rotl32(b, 1) 1801 | a ^= b ^ d 1802 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1803 | a = rotl32(a, 5) 1804 | c = rotl32(c, 22) 1805 | a ^= key[4 * 28 + 8] 1806 | b ^= key[4 * 28 + 9] 1807 | c ^= key[4 * 28 + 10] 1808 | d ^= key[4 * 28 + 11] 1809 | t1 = a ^ d; 1810 | t2 = d & t1; 1811 | t3 = c ^ t2; 1812 | t4 = b | t3; 1813 | h = t1 ^ t4; 1814 | t6 = (~b) % 0x100000000; 1815 | t7 = t1 | t6; 1816 | e = t3 ^ t7; 1817 | t9 = a & e; 1818 | t10 = t1 ^ t6; 1819 | t11 = t4 & t10; 1820 | g = t9 ^ t11; 1821 | t13 = a ^ t3; 1822 | t14 = t10 & g; 1823 | f = t13 ^ t14 1824 | e = rotl32(e, 13) 1825 | g = rotl32(g, 3) 1826 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1827 | f ^= e ^ g 1828 | h = rotl32(h, 7) 1829 | f = rotl32(f, 1) 1830 | e ^= f ^ h 1831 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1832 | e = rotl32(e, 5) 1833 | g = rotl32(g, 22) 1834 | e ^= key[4 * 29 + 8] 1835 | f ^= key[4 * 29 + 9] 1836 | g ^= key[4 * 29 + 10] 1837 | h ^= key[4 * 29 + 11] 1838 | t1 = (~e) % 0x100000000; 1839 | t2 = e ^ f; 1840 | t3 = e ^ h; 1841 | t4 = g ^ t1; 1842 | t5 = t2 | t3; 1843 | a = t4 ^ t5; 1844 | t7 = h & a; 1845 | t8 = t2 ^ a; 1846 | t10 = t1 | a; 1847 | b = t7 ^ t8; 1848 | t11 = t2 | t7; 1849 | t12 = t3 ^ t10; 1850 | t14 = f ^ t7; 1851 | c = t11 ^ t12; 1852 | t15 = b & t12; 1853 | d = t14 ^ t15 1854 | a = rotl32(a, 13) 1855 | c = rotl32(c, 3) 1856 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 1857 | b ^= a ^ c 1858 | d = rotl32(d, 7) 1859 | b = rotl32(b, 1) 1860 | a ^= b ^ d 1861 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 1862 | a = rotl32(a, 5) 1863 | c = rotl32(c, 22) 1864 | a ^= key[4 * 30 + 8] 1865 | b ^= key[4 * 30 + 9] 1866 | c ^= key[4 * 30 + 10] 1867 | d ^= key[4 * 30 + 11] 1868 | t1 = (~a) % 0x100000000; 1869 | t2 = a ^ d; 1870 | t3 = b ^ t2; 1871 | t4 = t1 | t2; 1872 | t5 = c ^ t4; 1873 | f = b ^ t5; 1874 | t13 = (~t5) % 0x100000000; 1875 | t7 = t2 | f; 1876 | t8 = d ^ t7; 1877 | t9 = t5 & t8; 1878 | g = t3 ^ t9; 1879 | t11 = t5 ^ t8; 1880 | e = g ^ t11; 1881 | t14 = t3 & t11; 1882 | h = t13 ^ t14 1883 | e = rotl32(e, 13) 1884 | g = rotl32(g, 3) 1885 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1886 | f ^= e ^ g 1887 | h = rotl32(h, 7) 1888 | f = rotl32(f, 1) 1889 | e ^= f ^ h 1890 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1891 | e = rotl32(e, 5) 1892 | g = rotl32(g, 22) 1893 | e ^= key[4 * 31 + 8] 1894 | f ^= key[4 * 31 + 9] 1895 | g ^= key[4 * 31 + 10] 1896 | h ^= key[4 * 31 + 11] 1897 | t1 = (~g) % 0x100000000; 1898 | t2 = f ^ g; 1899 | t3 = f | t1; 1900 | t4 = h ^ t3; 1901 | t5 = e & t4; 1902 | t7 = e ^ h; 1903 | d = t2 ^ t5; 1904 | t8 = f ^ t5; 1905 | t9 = t2 | t8; 1906 | t11 = h & t3; 1907 | b = t7 ^ t9; 1908 | t12 = t5 ^ b; 1909 | t15 = t1 | t4; 1910 | t13 = d & t12; 1911 | c = t11 ^ t13; 1912 | t16 = t12 ^ c; 1913 | a = t15 ^ t16 1914 | a ^= key[4 * 32 + 8] 1915 | b ^= key[4 * 32 + 9] 1916 | c ^= key[4 * 32 + 10] 1917 | d ^= key[4 * 32 + 11] 1918 | if WORD_BIGENDIAN: 1919 | a = byteswap32(a) 1920 | b = byteswap32(b) 1921 | c = byteswap32(c) 1922 | d = byteswap32(d) 1923 | in_blk[0] = a 1924 | in_blk[1] = b 1925 | in_blk[2] = c 1926 | in_blk[3] = d 1927 | 1928 | 1929 | def decrypt(key, in_blk): 1930 | # serpent_generate.py 1931 | a = in_blk[0] 1932 | b = in_blk[1] 1933 | c = in_blk[2] 1934 | d = in_blk[3] 1935 | if WORD_BIGENDIAN: 1936 | a = byteswap32(a) 1937 | b = byteswap32(b) 1938 | c = byteswap32(c) 1939 | d = byteswap32(d) 1940 | e = 0 1941 | f = 0 1942 | g = 0 1943 | h = 0 1944 | t1 = 0 1945 | t2 = 0 1946 | t3 = 0 1947 | t4 = 0 1948 | t5 = 0 1949 | t6 = 0 1950 | t7 = 0 1951 | t8 = 0 1952 | t9 = 0 1953 | t10 = 0 1954 | t11 = 0 1955 | t12 = 0 1956 | t13 = 0 1957 | t14 = 0 1958 | t15 = 0 1959 | t16 = 0 1960 | a ^= key[4 * 32 + 8] 1961 | b ^= key[4 * 32 + 9] 1962 | c ^= key[4 * 32 + 10] 1963 | d ^= key[4 * 32 + 11] 1964 | t1 = a & b; 1965 | t2 = a | b; 1966 | t3 = c | t1; 1967 | t4 = d & t2; 1968 | h = t3 ^ t4; 1969 | t6 = (~d) % 0x100000000; 1970 | t7 = b ^ t4; 1971 | t8 = h ^ t6; 1972 | t11 = c ^ t7; 1973 | t9 = t7 | t8; 1974 | f = a ^ t9; 1975 | t12 = d | f; 1976 | e = t11 ^ t12; 1977 | t14 = a & h; 1978 | t15 = t3 ^ f; 1979 | t16 = e ^ t14; 1980 | g = t15 ^ t16 1981 | e ^= key[4 * 31 + 8] 1982 | f ^= key[4 * 31 + 9] 1983 | g ^= key[4 * 31 + 10] 1984 | h ^= key[4 * 31 + 11] 1985 | g = rotr32(g, 22) 1986 | e = rotr32(e, 5) 1987 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 1988 | e ^= f ^ h 1989 | h = rotr32(h, 7) 1990 | f = rotr32(f, 1) 1991 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 1992 | f ^= e ^ g 1993 | g = rotr32(g, 3) 1994 | e = rotr32(e, 13) 1995 | t1 = (~e) % 0x100000000; 1996 | t2 = e ^ f; 1997 | t3 = g ^ t2; 1998 | t4 = g | t1; 1999 | t5 = h ^ t4; 2000 | t13 = h & t1; 2001 | b = t3 ^ t5; 2002 | t7 = t3 & t5; 2003 | t8 = t2 ^ t7; 2004 | t9 = f | t8; 2005 | d = t5 ^ t9; 2006 | t11 = f | d; 2007 | a = t8 ^ t11; 2008 | t14 = t3 ^ t11; 2009 | c = t13 ^ t14 2010 | a ^= key[4 * 30 + 8] 2011 | b ^= key[4 * 30 + 9] 2012 | c ^= key[4 * 30 + 10] 2013 | d ^= key[4 * 30 + 11] 2014 | c = rotr32(c, 22) 2015 | a = rotr32(a, 5) 2016 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2017 | a ^= b ^ d 2018 | d = rotr32(d, 7) 2019 | b = rotr32(b, 1) 2020 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2021 | b ^= a ^ c 2022 | c = rotr32(c, 3) 2023 | a = rotr32(a, 13) 2024 | t1 = (~c) % 0x100000000; 2025 | t2 = b & t1; 2026 | t3 = d ^ t2; 2027 | t4 = a & t3; 2028 | t5 = b ^ t1; 2029 | h = t4 ^ t5; 2030 | t7 = b | h; 2031 | t8 = a & t7; 2032 | f = t3 ^ t8; 2033 | t10 = a | d; 2034 | t11 = t1 ^ t7; 2035 | e = t10 ^ t11; 2036 | t13 = a ^ c; 2037 | t14 = b & t10; 2038 | t15 = t4 | t13; 2039 | g = t14 ^ t15 2040 | e ^= key[4 * 29 + 8] 2041 | f ^= key[4 * 29 + 9] 2042 | g ^= key[4 * 29 + 10] 2043 | h ^= key[4 * 29 + 11] 2044 | g = rotr32(g, 22) 2045 | e = rotr32(e, 5) 2046 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2047 | e ^= f ^ h 2048 | h = rotr32(h, 7) 2049 | f = rotr32(f, 1) 2050 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2051 | f ^= e ^ g 2052 | g = rotr32(g, 3) 2053 | e = rotr32(e, 13) 2054 | t1 = g ^ h; 2055 | t2 = g | h; 2056 | t3 = f ^ t2; 2057 | t4 = e & t3; 2058 | b = t1 ^ t4; 2059 | t6 = e ^ h; 2060 | t7 = f | h; 2061 | t8 = t6 & t7; 2062 | d = t3 ^ t8; 2063 | t10 = (~e) % 0x100000000; 2064 | t11 = g ^ d; 2065 | t12 = t10 | t11; 2066 | a = t3 ^ t12; 2067 | t14 = g | t4; 2068 | t15 = t7 ^ t14; 2069 | t16 = d | t10; 2070 | c = t15 ^ t16 2071 | a ^= key[4 * 28 + 8] 2072 | b ^= key[4 * 28 + 9] 2073 | c ^= key[4 * 28 + 10] 2074 | d ^= key[4 * 28 + 11] 2075 | c = rotr32(c, 22) 2076 | a = rotr32(a, 5) 2077 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2078 | a ^= b ^ d 2079 | d = rotr32(d, 7) 2080 | b = rotr32(b, 1) 2081 | 2082 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2083 | b ^= a ^ c 2084 | c = rotr32(c, 3) 2085 | a = rotr32(a, 13) 2086 | t1 = b ^ c; 2087 | t2 = b | c; 2088 | t3 = a ^ c; 2089 | t7 = a ^ d; 2090 | t4 = t2 ^ t3; 2091 | t5 = d | t4; 2092 | t9 = t2 ^ t7; 2093 | e = t1 ^ t5; 2094 | t8 = t1 | t5; 2095 | t11 = a & t4; 2096 | g = t8 ^ t9; 2097 | t12 = e | t9; 2098 | f = t11 ^ t12; 2099 | t14 = a & g; 2100 | t15 = t2 ^ t14; 2101 | t16 = e & t15; 2102 | h = t4 ^ t16 2103 | e ^= key[4 * 27 + 8] 2104 | f ^= key[4 * 27 + 9] 2105 | g ^= key[4 * 27 + 10] 2106 | h ^= key[4 * 27 + 11] 2107 | g = rotr32(g, 22) 2108 | e = rotr32(e, 5) 2109 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2110 | e ^= f ^ h 2111 | h = rotr32(h, 7) 2112 | f = rotr32(f, 1) 2113 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2114 | f ^= e ^ g 2115 | g = rotr32(g, 3) 2116 | e = rotr32(e, 13) 2117 | t1 = f ^ h; 2118 | t2 = (~t1) % 0x100000000; 2119 | t3 = e ^ g; 2120 | t4 = g ^ t1; 2121 | t7 = e | t2; 2122 | t5 = f & t4; 2123 | t8 = h ^ t7; 2124 | t11 = (~t4) % 0x100000000; 2125 | a = t3 ^ t5; 2126 | t9 = t3 | t8; 2127 | t14 = h & t11; 2128 | d = t1 ^ t9; 2129 | t12 = a | d; 2130 | b = t11 ^ t12; 2131 | t15 = t3 ^ t12; 2132 | c = t14 ^ t15 2133 | a ^= key[4 * 26 + 8] 2134 | b ^= key[4 * 26 + 9] 2135 | c ^= key[4 * 26 + 10] 2136 | d ^= key[4 * 26 + 11] 2137 | c = rotr32(c, 22) 2138 | a = rotr32(a, 5) 2139 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2140 | a ^= b ^ d 2141 | d = rotr32(d, 7) 2142 | b = rotr32(b, 1) 2143 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2144 | b ^= a ^ c 2145 | c = rotr32(c, 3) 2146 | a = rotr32(a, 13) 2147 | t1 = a ^ d; 2148 | t2 = a & b; 2149 | t3 = b ^ c; 2150 | t4 = a ^ t3; 2151 | t5 = b | d; 2152 | t7 = c | t1; 2153 | h = t4 ^ t5; 2154 | t8 = b ^ t7; 2155 | t11 = (~t2) % 0x100000000; 2156 | t9 = t4 & t8; 2157 | f = t1 ^ t9; 2158 | t13 = t9 ^ t11; 2159 | t12 = h & f; 2160 | g = t12 ^ t13; 2161 | t15 = a & d; 2162 | t16 = c ^ t13; 2163 | e = t15 ^ t16 2164 | e ^= key[4 * 25 + 8] 2165 | f ^= key[4 * 25 + 9] 2166 | g ^= key[4 * 25 + 10] 2167 | h ^= key[4 * 25 + 11] 2168 | g = rotr32(g, 22) 2169 | e = rotr32(e, 5) 2170 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2171 | e ^= f ^ h 2172 | h = rotr32(h, 7) 2173 | f = rotr32(f, 1) 2174 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2175 | f ^= e ^ g 2176 | g = rotr32(g, 3) 2177 | e = rotr32(e, 13) 2178 | t1 = (~e) % 0x100000000 2179 | t2 = e ^ f 2180 | t3 = t1 | t2 2181 | t4 = h ^ t3 2182 | t7 = h & t2 2183 | t5 = g ^ t4 2184 | t8 = t1 ^ t7 2185 | c = t2 ^ t5 2186 | t11 = e & t4 2187 | t9 = c & t8 2188 | t14 = t5 ^ t8 2189 | b = t4 ^ t9 2190 | t12 = t5 | b 2191 | d = t11 ^ t12 2192 | a = d ^ t14 2193 | a ^= key[4 * 24 + 8] 2194 | b ^= key[4 * 24 + 9] 2195 | c ^= key[4 * 24 + 10] 2196 | d ^= key[4 * 24 + 11] 2197 | c = rotr32(c, 22) 2198 | a = rotr32(a, 5) 2199 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2200 | a ^= b ^ d 2201 | d = rotr32(d, 7) 2202 | b = rotr32(b, 1) 2203 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2204 | b ^= a ^ c 2205 | c = rotr32(c, 3) 2206 | a = rotr32(a, 13) 2207 | t1 = a & b; 2208 | t2 = a | b; 2209 | t3 = c | t1; 2210 | t4 = d & t2; 2211 | h = t3 ^ t4; 2212 | t6 = (~d) % 0x100000000; 2213 | t7 = b ^ t4; 2214 | t8 = h ^ t6; 2215 | t11 = c ^ t7; 2216 | t9 = t7 | t8; 2217 | f = a ^ t9; 2218 | t12 = d | f; 2219 | e = t11 ^ t12; 2220 | t14 = a & h; 2221 | t15 = t3 ^ f; 2222 | t16 = e ^ t14; 2223 | g = t15 ^ t16 2224 | e ^= key[4 * 23 + 8] 2225 | f ^= key[4 * 23 + 9] 2226 | g ^= key[4 * 23 + 10] 2227 | h ^= key[4 * 23 + 11] 2228 | g = rotr32(g, 22) 2229 | e = rotr32(e, 5) 2230 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2231 | e ^= f ^ h 2232 | h = rotr32(h, 7) 2233 | f = rotr32(f, 1) 2234 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2235 | f ^= e ^ g 2236 | g = rotr32(g, 3) 2237 | e = rotr32(e, 13) 2238 | t1 = (~e) % 0x100000000; 2239 | t2 = e ^ f; 2240 | t3 = g ^ t2; 2241 | t4 = g | t1; 2242 | t5 = h ^ t4; 2243 | t13 = h & t1; 2244 | b = t3 ^ t5; 2245 | t7 = t3 & t5; 2246 | t8 = t2 ^ t7; 2247 | t9 = f | t8; 2248 | d = t5 ^ t9; 2249 | t11 = f | d; 2250 | a = t8 ^ t11; 2251 | t14 = t3 ^ t11; 2252 | c = t13 ^ t14 2253 | a ^= key[4 * 22 + 8] 2254 | b ^= key[4 * 22 + 9] 2255 | c ^= key[4 * 22 + 10] 2256 | d ^= key[4 * 22 + 11] 2257 | c = rotr32(c, 22) 2258 | a = rotr32(a, 5) 2259 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2260 | a ^= b ^ d 2261 | d = rotr32(d, 7) 2262 | b = rotr32(b, 1) 2263 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2264 | b ^= a ^ c 2265 | c = rotr32(c, 3) 2266 | a = rotr32(a, 13) 2267 | t1 = (~c) % 0x100000000; 2268 | t2 = b & t1; 2269 | t3 = d ^ t2; 2270 | t4 = a & t3; 2271 | t5 = b ^ t1; 2272 | h = t4 ^ t5; 2273 | t7 = b | h; 2274 | t8 = a & t7; 2275 | f = t3 ^ t8; 2276 | t10 = a | d; 2277 | t11 = t1 ^ t7; 2278 | e = t10 ^ t11; 2279 | t13 = a ^ c; 2280 | t14 = b & t10; 2281 | t15 = t4 | t13; 2282 | g = t14 ^ t15 2283 | e ^= key[4 * 21 + 8] 2284 | f ^= key[4 * 21 + 9] 2285 | g ^= key[4 * 21 + 10] 2286 | h ^= key[4 * 21 + 11] 2287 | g = rotr32(g, 22) 2288 | e = rotr32(e, 5) 2289 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2290 | e ^= f ^ h 2291 | h = rotr32(h, 7) 2292 | f = rotr32(f, 1) 2293 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2294 | f ^= e ^ g 2295 | g = rotr32(g, 3) 2296 | e = rotr32(e, 13) 2297 | t1 = g ^ h; 2298 | t2 = g | h; 2299 | t3 = f ^ t2; 2300 | t4 = e & t3; 2301 | b = t1 ^ t4; 2302 | t6 = e ^ h; 2303 | t7 = f | h; 2304 | t8 = t6 & t7; 2305 | d = t3 ^ t8; 2306 | t10 = (~e) % 0x100000000; 2307 | t11 = g ^ d; 2308 | t12 = t10 | t11; 2309 | a = t3 ^ t12; 2310 | t14 = g | t4; 2311 | t15 = t7 ^ t14; 2312 | t16 = d | t10; 2313 | c = t15 ^ t16 2314 | a ^= key[4 * 20 + 8] 2315 | b ^= key[4 * 20 + 9] 2316 | c ^= key[4 * 20 + 10] 2317 | d ^= key[4 * 20 + 11] 2318 | c = rotr32(c, 22) 2319 | a = rotr32(a, 5) 2320 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2321 | a ^= b ^ d 2322 | d = rotr32(d, 7) 2323 | b = rotr32(b, 1) 2324 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2325 | b ^= a ^ c 2326 | c = rotr32(c, 3) 2327 | a = rotr32(a, 13) 2328 | t1 = b ^ c; 2329 | t2 = b | c; 2330 | t3 = a ^ c; 2331 | t7 = a ^ d; 2332 | t4 = t2 ^ t3; 2333 | t5 = d | t4; 2334 | t9 = t2 ^ t7; 2335 | e = t1 ^ t5; 2336 | t8 = t1 | t5; 2337 | t11 = a & t4; 2338 | g = t8 ^ t9; 2339 | t12 = e | t9; 2340 | f = t11 ^ t12; 2341 | t14 = a & g; 2342 | t15 = t2 ^ t14; 2343 | t16 = e & t15; 2344 | h = t4 ^ t16 2345 | e ^= key[4 * 19 + 8] 2346 | f ^= key[4 * 19 + 9] 2347 | g ^= key[4 * 19 + 10] 2348 | h ^= key[4 * 19 + 11] 2349 | g = rotr32(g, 22) 2350 | e = rotr32(e, 5) 2351 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2352 | e ^= f ^ h 2353 | h = rotr32(h, 7) 2354 | f = rotr32(f, 1) 2355 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2356 | f ^= e ^ g 2357 | g = rotr32(g, 3) 2358 | e = rotr32(e, 13) 2359 | t1 = f ^ h; 2360 | t2 = (~t1) % 0x100000000; 2361 | t3 = e ^ g; 2362 | t4 = g ^ t1; 2363 | t7 = e | t2; 2364 | t5 = f & t4; 2365 | t8 = h ^ t7; 2366 | t11 = (~t4) % 0x100000000; 2367 | a = t3 ^ t5; 2368 | t9 = t3 | t8; 2369 | t14 = h & t11; 2370 | d = t1 ^ t9; 2371 | t12 = a | d; 2372 | b = t11 ^ t12; 2373 | t15 = t3 ^ t12; 2374 | c = t14 ^ t15 2375 | a ^= key[4 * 18 + 8] 2376 | b ^= key[4 * 18 + 9] 2377 | c ^= key[4 * 18 + 10] 2378 | d ^= key[4 * 18 + 11] 2379 | c = rotr32(c, 22) 2380 | a = rotr32(a, 5) 2381 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2382 | a ^= b ^ d 2383 | d = rotr32(d, 7) 2384 | b = rotr32(b, 1) 2385 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2386 | b ^= a ^ c 2387 | c = rotr32(c, 3) 2388 | a = rotr32(a, 13) 2389 | t1 = a ^ d; 2390 | t2 = a & b; 2391 | t3 = b ^ c; 2392 | t4 = a ^ t3; 2393 | t5 = b | d; 2394 | t7 = c | t1; 2395 | h = t4 ^ t5; 2396 | t8 = b ^ t7; 2397 | t11 = (~t2) % 0x100000000; 2398 | t9 = t4 & t8; 2399 | f = t1 ^ t9; 2400 | t13 = t9 ^ t11; 2401 | t12 = h & f; 2402 | g = t12 ^ t13; 2403 | t15 = a & d; 2404 | t16 = c ^ t13; 2405 | e = t15 ^ t16 2406 | e ^= key[4 * 17 + 8] 2407 | f ^= key[4 * 17 + 9] 2408 | g ^= key[4 * 17 + 10] 2409 | h ^= key[4 * 17 + 11] 2410 | g = rotr32(g, 22) 2411 | e = rotr32(e, 5) 2412 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2413 | e ^= f ^ h 2414 | h = rotr32(h, 7) 2415 | f = rotr32(f, 1) 2416 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2417 | f ^= e ^ g 2418 | g = rotr32(g, 3) 2419 | e = rotr32(e, 13) 2420 | t1 = (~e) % 0x100000000 2421 | t2 = e ^ f 2422 | t3 = t1 | t2 2423 | t4 = h ^ t3 2424 | t7 = h & t2 2425 | t5 = g ^ t4 2426 | t8 = t1 ^ t7 2427 | c = t2 ^ t5 2428 | t11 = e & t4 2429 | t9 = c & t8 2430 | t14 = t5 ^ t8 2431 | b = t4 ^ t9 2432 | t12 = t5 | b 2433 | d = t11 ^ t12 2434 | a = d ^ t14 2435 | a ^= key[4 * 16 + 8] 2436 | b ^= key[4 * 16 + 9] 2437 | c ^= key[4 * 16 + 10] 2438 | d ^= key[4 * 16 + 11] 2439 | c = rotr32(c, 22) 2440 | a = rotr32(a, 5) 2441 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2442 | a ^= b ^ d 2443 | d = rotr32(d, 7) 2444 | b = rotr32(b, 1) 2445 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2446 | b ^= a ^ c 2447 | c = rotr32(c, 3) 2448 | a = rotr32(a, 13) 2449 | t1 = a & b; 2450 | t2 = a | b; 2451 | t3 = c | t1; 2452 | t4 = d & t2; 2453 | h = t3 ^ t4; 2454 | t6 = (~d) % 0x100000000; 2455 | t7 = b ^ t4; 2456 | t8 = h ^ t6; 2457 | t11 = c ^ t7; 2458 | t9 = t7 | t8; 2459 | f = a ^ t9; 2460 | t12 = d | f; 2461 | e = t11 ^ t12; 2462 | t14 = a & h; 2463 | t15 = t3 ^ f; 2464 | t16 = e ^ t14; 2465 | g = t15 ^ t16 2466 | e ^= key[4 * 15 + 8] 2467 | f ^= key[4 * 15 + 9] 2468 | g ^= key[4 * 15 + 10] 2469 | h ^= key[4 * 15 + 11] 2470 | g = rotr32(g, 22) 2471 | e = rotr32(e, 5) 2472 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2473 | e ^= f ^ h 2474 | h = rotr32(h, 7) 2475 | f = rotr32(f, 1) 2476 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2477 | f ^= e ^ g 2478 | g = rotr32(g, 3) 2479 | e = rotr32(e, 13) 2480 | t1 = (~e) % 0x100000000; 2481 | t2 = e ^ f; 2482 | t3 = g ^ t2; 2483 | t4 = g | t1; 2484 | t5 = h ^ t4; 2485 | t13 = h & t1; 2486 | b = t3 ^ t5; 2487 | t7 = t3 & t5; 2488 | t8 = t2 ^ t7; 2489 | t9 = f | t8; 2490 | d = t5 ^ t9; 2491 | t11 = f | d; 2492 | a = t8 ^ t11; 2493 | t14 = t3 ^ t11; 2494 | c = t13 ^ t14 2495 | a ^= key[4 * 14 + 8] 2496 | b ^= key[4 * 14 + 9] 2497 | c ^= key[4 * 14 + 10] 2498 | d ^= key[4 * 14 + 11] 2499 | c = rotr32(c, 22) 2500 | a = rotr32(a, 5) 2501 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2502 | a ^= b ^ d 2503 | d = rotr32(d, 7) 2504 | b = rotr32(b, 1) 2505 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2506 | b ^= a ^ c 2507 | c = rotr32(c, 3) 2508 | a = rotr32(a, 13) 2509 | t1 = (~c) % 0x100000000; 2510 | t2 = b & t1; 2511 | t3 = d ^ t2; 2512 | t4 = a & t3; 2513 | t5 = b ^ t1; 2514 | h = t4 ^ t5; 2515 | t7 = b | h; 2516 | t8 = a & t7; 2517 | f = t3 ^ t8; 2518 | t10 = a | d; 2519 | t11 = t1 ^ t7; 2520 | e = t10 ^ t11; 2521 | t13 = a ^ c; 2522 | t14 = b & t10; 2523 | t15 = t4 | t13; 2524 | g = t14 ^ t15 2525 | e ^= key[4 * 13 + 8] 2526 | f ^= key[4 * 13 + 9] 2527 | g ^= key[4 * 13 + 10] 2528 | h ^= key[4 * 13 + 11] 2529 | g = rotr32(g, 22) 2530 | e = rotr32(e, 5) 2531 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2532 | e ^= f ^ h 2533 | h = rotr32(h, 7) 2534 | f = rotr32(f, 1) 2535 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2536 | f ^= e ^ g 2537 | g = rotr32(g, 3) 2538 | e = rotr32(e, 13) 2539 | t1 = g ^ h; 2540 | t2 = g | h; 2541 | t3 = f ^ t2; 2542 | t4 = e & t3; 2543 | b = t1 ^ t4; 2544 | t6 = e ^ h; 2545 | t7 = f | h; 2546 | t8 = t6 & t7; 2547 | d = t3 ^ t8; 2548 | t10 = (~e) % 0x100000000; 2549 | t11 = g ^ d; 2550 | t12 = t10 | t11; 2551 | a = t3 ^ t12; 2552 | t14 = g | t4; 2553 | t15 = t7 ^ t14; 2554 | t16 = d | t10; 2555 | c = t15 ^ t16 2556 | a ^= key[4 * 12 + 8] 2557 | b ^= key[4 * 12 + 9] 2558 | c ^= key[4 * 12 + 10] 2559 | d ^= key[4 * 12 + 11] 2560 | c = rotr32(c, 22) 2561 | a = rotr32(a, 5) 2562 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2563 | a ^= b ^ d 2564 | d = rotr32(d, 7) 2565 | b = rotr32(b, 1) 2566 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2567 | b ^= a ^ c 2568 | c = rotr32(c, 3) 2569 | a = rotr32(a, 13) 2570 | t1 = b ^ c; 2571 | t2 = b | c; 2572 | t3 = a ^ c; 2573 | t7 = a ^ d; 2574 | t4 = t2 ^ t3; 2575 | t5 = d | t4; 2576 | t9 = t2 ^ t7; 2577 | e = t1 ^ t5; 2578 | t8 = t1 | t5; 2579 | t11 = a & t4; 2580 | g = t8 ^ t9; 2581 | t12 = e | t9; 2582 | f = t11 ^ t12; 2583 | t14 = a & g; 2584 | t15 = t2 ^ t14; 2585 | t16 = e & t15; 2586 | h = t4 ^ t16 2587 | e ^= key[4 * 11 + 8] 2588 | f ^= key[4 * 11 + 9] 2589 | g ^= key[4 * 11 + 10] 2590 | h ^= key[4 * 11 + 11] 2591 | g = rotr32(g, 22) 2592 | e = rotr32(e, 5) 2593 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2594 | e ^= f ^ h 2595 | h = rotr32(h, 7) 2596 | f = rotr32(f, 1) 2597 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2598 | f ^= e ^ g 2599 | g = rotr32(g, 3) 2600 | e = rotr32(e, 13) 2601 | t1 = f ^ h; 2602 | t2 = (~t1) % 0x100000000; 2603 | t3 = e ^ g; 2604 | t4 = g ^ t1; 2605 | t7 = e | t2; 2606 | t5 = f & t4; 2607 | t8 = h ^ t7; 2608 | t11 = (~t4) % 0x100000000; 2609 | a = t3 ^ t5; 2610 | t9 = t3 | t8; 2611 | t14 = h & t11; 2612 | d = t1 ^ t9; 2613 | t12 = a | d; 2614 | b = t11 ^ t12; 2615 | t15 = t3 ^ t12; 2616 | c = t14 ^ t15 2617 | a ^= key[4 * 10 + 8] 2618 | b ^= key[4 * 10 + 9] 2619 | c ^= key[4 * 10 + 10] 2620 | d ^= key[4 * 10 + 11] 2621 | c = rotr32(c, 22) 2622 | a = rotr32(a, 5) 2623 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2624 | a ^= b ^ d 2625 | d = rotr32(d, 7) 2626 | b = rotr32(b, 1) 2627 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2628 | b ^= a ^ c 2629 | c = rotr32(c, 3) 2630 | a = rotr32(a, 13) 2631 | t1 = a ^ d; 2632 | t2 = a & b; 2633 | t3 = b ^ c; 2634 | t4 = a ^ t3; 2635 | t5 = b | d; 2636 | t7 = c | t1; 2637 | h = t4 ^ t5; 2638 | t8 = b ^ t7; 2639 | t11 = (~t2) % 0x100000000; 2640 | t9 = t4 & t8; 2641 | f = t1 ^ t9; 2642 | t13 = t9 ^ t11; 2643 | t12 = h & f; 2644 | g = t12 ^ t13; 2645 | t15 = a & d; 2646 | t16 = c ^ t13; 2647 | e = t15 ^ t16 2648 | e ^= key[4 * 9 + 8] 2649 | f ^= key[4 * 9 + 9] 2650 | g ^= key[4 * 9 + 10] 2651 | h ^= key[4 * 9 + 11] 2652 | g = rotr32(g, 22) 2653 | e = rotr32(e, 5) 2654 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2655 | e ^= f ^ h 2656 | h = rotr32(h, 7) 2657 | f = rotr32(f, 1) 2658 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2659 | f ^= e ^ g 2660 | g = rotr32(g, 3) 2661 | e = rotr32(e, 13) 2662 | t1 = (~e) % 0x100000000 2663 | t2 = e ^ f 2664 | t3 = t1 | t2 2665 | t4 = h ^ t3 2666 | t7 = h & t2 2667 | t5 = g ^ t4 2668 | t8 = t1 ^ t7 2669 | c = t2 ^ t5 2670 | t11 = e & t4 2671 | t9 = c & t8 2672 | t14 = t5 ^ t8 2673 | b = t4 ^ t9 2674 | t12 = t5 | b 2675 | d = t11 ^ t12 2676 | a = d ^ t14 2677 | a ^= key[4 * 8 + 8] 2678 | b ^= key[4 * 8 + 9] 2679 | c ^= key[4 * 8 + 10] 2680 | d ^= key[4 * 8 + 11] 2681 | c = rotr32(c, 22) 2682 | a = rotr32(a, 5) 2683 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2684 | a ^= b ^ d 2685 | d = rotr32(d, 7) 2686 | b = rotr32(b, 1) 2687 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2688 | b ^= a ^ c 2689 | c = rotr32(c, 3) 2690 | a = rotr32(a, 13) 2691 | t1 = a & b; 2692 | t2 = a | b; 2693 | t3 = c | t1; 2694 | t4 = d & t2; 2695 | h = t3 ^ t4; 2696 | t6 = (~d) % 0x100000000; 2697 | t7 = b ^ t4; 2698 | t8 = h ^ t6; 2699 | t11 = c ^ t7; 2700 | t9 = t7 | t8; 2701 | f = a ^ t9; 2702 | t12 = d | f; 2703 | e = t11 ^ t12; 2704 | t14 = a & h; 2705 | t15 = t3 ^ f; 2706 | t16 = e ^ t14; 2707 | g = t15 ^ t16 2708 | e ^= key[4 * 7 + 8] 2709 | f ^= key[4 * 7 + 9] 2710 | g ^= key[4 * 7 + 10] 2711 | h ^= key[4 * 7 + 11] 2712 | g = rotr32(g, 22) 2713 | e = rotr32(e, 5) 2714 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2715 | e ^= f ^ h 2716 | h = rotr32(h, 7) 2717 | f = rotr32(f, 1) 2718 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2719 | f ^= e ^ g 2720 | g = rotr32(g, 3) 2721 | e = rotr32(e, 13) 2722 | t1 = (~e) % 0x100000000; 2723 | t2 = e ^ f; 2724 | t3 = g ^ t2; 2725 | t4 = g | t1; 2726 | t5 = h ^ t4; 2727 | t13 = h & t1; 2728 | b = t3 ^ t5; 2729 | t7 = t3 & t5; 2730 | t8 = t2 ^ t7; 2731 | t9 = f | t8; 2732 | d = t5 ^ t9; 2733 | t11 = f | d; 2734 | a = t8 ^ t11; 2735 | t14 = t3 ^ t11; 2736 | c = t13 ^ t14 2737 | a ^= key[4 * 6 + 8] 2738 | b ^= key[4 * 6 + 9] 2739 | c ^= key[4 * 6 + 10] 2740 | d ^= key[4 * 6 + 11] 2741 | c = rotr32(c, 22) 2742 | a = rotr32(a, 5) 2743 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2744 | a ^= b ^ d 2745 | d = rotr32(d, 7) 2746 | b = rotr32(b, 1) 2747 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2748 | b ^= a ^ c 2749 | c = rotr32(c, 3) 2750 | a = rotr32(a, 13) 2751 | t1 = (~c) % 0x100000000; 2752 | t2 = b & t1; 2753 | t3 = d ^ t2; 2754 | t4 = a & t3; 2755 | t5 = b ^ t1; 2756 | h = t4 ^ t5; 2757 | t7 = b | h; 2758 | t8 = a & t7; 2759 | f = t3 ^ t8; 2760 | t10 = a | d; 2761 | t11 = t1 ^ t7; 2762 | e = t10 ^ t11; 2763 | t13 = a ^ c; 2764 | t14 = b & t10; 2765 | t15 = t4 | t13; 2766 | g = t14 ^ t15 2767 | e ^= key[4 * 5 + 8] 2768 | f ^= key[4 * 5 + 9] 2769 | g ^= key[4 * 5 + 10] 2770 | h ^= key[4 * 5 + 11] 2771 | g = rotr32(g, 22) 2772 | e = rotr32(e, 5) 2773 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2774 | e ^= f ^ h 2775 | h = rotr32(h, 7) 2776 | f = rotr32(f, 1) 2777 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2778 | f ^= e ^ g 2779 | g = rotr32(g, 3) 2780 | e = rotr32(e, 13) 2781 | t1 = g ^ h; 2782 | t2 = g | h; 2783 | t3 = f ^ t2; 2784 | t4 = e & t3; 2785 | b = t1 ^ t4; 2786 | t6 = e ^ h; 2787 | t7 = f | h; 2788 | t8 = t6 & t7; 2789 | d = t3 ^ t8; 2790 | t10 = (~e) % 0x100000000; 2791 | t11 = g ^ d; 2792 | t12 = t10 | t11; 2793 | a = t3 ^ t12; 2794 | t14 = g | t4; 2795 | t15 = t7 ^ t14; 2796 | t16 = d | t10; 2797 | c = t15 ^ t16 2798 | a ^= key[4 * 4 + 8] 2799 | b ^= key[4 * 4 + 9] 2800 | c ^= key[4 * 4 + 10] 2801 | d ^= key[4 * 4 + 11] 2802 | c = rotr32(c, 22) 2803 | a = rotr32(a, 5) 2804 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2805 | a ^= b ^ d 2806 | d = rotr32(d, 7) 2807 | b = rotr32(b, 1) 2808 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2809 | b ^= a ^ c 2810 | c = rotr32(c, 3) 2811 | a = rotr32(a, 13) 2812 | t1 = b ^ c; 2813 | t2 = b | c; 2814 | t3 = a ^ c; 2815 | t7 = a ^ d; 2816 | t4 = t2 ^ t3; 2817 | t5 = d | t4; 2818 | t9 = t2 ^ t7; 2819 | e = t1 ^ t5; 2820 | t8 = t1 | t5; 2821 | t11 = a & t4; 2822 | g = t8 ^ t9; 2823 | t12 = e | t9; 2824 | f = t11 ^ t12; 2825 | t14 = a & g; 2826 | t15 = t2 ^ t14; 2827 | t16 = e & t15; 2828 | h = t4 ^ t16 2829 | e ^= key[4 * 3 + 8] 2830 | f ^= key[4 * 3 + 9] 2831 | g ^= key[4 * 3 + 10] 2832 | h ^= key[4 * 3 + 11] 2833 | g = rotr32(g, 22) 2834 | e = rotr32(e, 5) 2835 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2836 | e ^= f ^ h 2837 | h = rotr32(h, 7) 2838 | f = rotr32(f, 1) 2839 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2840 | f ^= e ^ g 2841 | g = rotr32(g, 3) 2842 | e = rotr32(e, 13) 2843 | t1 = f ^ h; 2844 | t2 = (~t1) % 0x100000000; 2845 | t3 = e ^ g; 2846 | t4 = g ^ t1; 2847 | t7 = e | t2; 2848 | t5 = f & t4; 2849 | t8 = h ^ t7; 2850 | t11 = (~t4) % 0x100000000; 2851 | a = t3 ^ t5; 2852 | t9 = t3 | t8; 2853 | t14 = h & t11; 2854 | d = t1 ^ t9; 2855 | t12 = a | d; 2856 | b = t11 ^ t12; 2857 | t15 = t3 ^ t12; 2858 | c = t14 ^ t15 2859 | a ^= key[4 * 2 + 8] 2860 | b ^= key[4 * 2 + 9] 2861 | c ^= key[4 * 2 + 10] 2862 | d ^= key[4 * 2 + 11] 2863 | c = rotr32(c, 22) 2864 | a = rotr32(a, 5) 2865 | c ^= d ^ ((b << 7) & 0xFFFFFFFF) 2866 | a ^= b ^ d 2867 | d = rotr32(d, 7) 2868 | b = rotr32(b, 1) 2869 | d ^= c ^ ((a << 3) & 0xFFFFFFFF) 2870 | b ^= a ^ c 2871 | c = rotr32(c, 3) 2872 | a = rotr32(a, 13) 2873 | t1 = a ^ d; 2874 | t2 = a & b; 2875 | t3 = b ^ c; 2876 | t4 = a ^ t3; 2877 | t5 = b | d; 2878 | t7 = c | t1; 2879 | h = t4 ^ t5; 2880 | t8 = b ^ t7; 2881 | t11 = (~t2) % 0x100000000; 2882 | t9 = t4 & t8; 2883 | f = t1 ^ t9; 2884 | t13 = t9 ^ t11; 2885 | t12 = h & f; 2886 | g = t12 ^ t13; 2887 | t15 = a & d; 2888 | t16 = c ^ t13; 2889 | e = t15 ^ t16 2890 | e ^= key[4 * 1 + 8] 2891 | f ^= key[4 * 1 + 9] 2892 | g ^= key[4 * 1 + 10] 2893 | h ^= key[4 * 1 + 11] 2894 | g = rotr32(g, 22) 2895 | e = rotr32(e, 5) 2896 | g ^= h ^ ((f << 7) & 0xFFFFFFFF) 2897 | e ^= f ^ h 2898 | h = rotr32(h, 7) 2899 | f = rotr32(f, 1) 2900 | h ^= g ^ ((e << 3) & 0xFFFFFFFF) 2901 | f ^= e ^ g 2902 | g = rotr32(g, 3) 2903 | e = rotr32(e, 13) 2904 | t1 = (~e) % 0x100000000 2905 | t2 = e ^ f 2906 | t3 = t1 | t2 2907 | t4 = h ^ t3 2908 | t7 = h & t2 2909 | t5 = g ^ t4 2910 | t8 = t1 ^ t7 2911 | c = t2 ^ t5 2912 | t11 = e & t4 2913 | t9 = c & t8 2914 | t14 = t5 ^ t8 2915 | b = t4 ^ t9 2916 | t12 = t5 | b 2917 | d = t11 ^ t12 2918 | a = d ^ t14 2919 | a ^= key[4 * 0 + 8] 2920 | b ^= key[4 * 0 + 9] 2921 | c ^= key[4 * 0 + 10] 2922 | d ^= key[4 * 0 + 11] 2923 | if WORD_BIGENDIAN: 2924 | a = byteswap32(a) 2925 | b = byteswap32(b) 2926 | c = byteswap32(c) 2927 | d = byteswap32(d) 2928 | in_blk[0] = a 2929 | in_blk[1] = b 2930 | in_blk[2] = c 2931 | in_blk[3] = d 2932 | 2933 | 2934 | # CBC Encrypt - Jason Reaves 2935 | def serpent_cbc_encrypt(key, data, iv=b'\x00' * 16): 2936 | out = b"" 2937 | last = iv 2938 | for i in range((len(data) // 16)): 2939 | temp = data[i * 16:(i + 1) * 16] 2940 | to_encode = b"" 2941 | for j in range(4): 2942 | temp1 = struct.unpack_from('