[utils] Move base62 to utils
This commit is contained in:
parent
e048d87fc9
commit
81bdc8fdf6
2 changed files with 16 additions and 13 deletions
|
@ -18,6 +18,7 @@ from ..compat import (
|
||||||
compat_urllib_parse_urlparse,
|
compat_urllib_parse_urlparse,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
base62,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
ohdave_rsa_encrypt,
|
ohdave_rsa_encrypt,
|
||||||
remove_start,
|
remove_start,
|
||||||
|
@ -126,21 +127,9 @@ class IqiyiSDK(object):
|
||||||
|
|
||||||
|
|
||||||
class IqiyiSDKInterpreter(object):
|
class IqiyiSDKInterpreter(object):
|
||||||
BASE62_TABLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
||||||
|
|
||||||
def __init__(self, sdk_code):
|
def __init__(self, sdk_code):
|
||||||
self.sdk_code = sdk_code
|
self.sdk_code = sdk_code
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def base62(cls, num):
|
|
||||||
if num == 0:
|
|
||||||
return '0'
|
|
||||||
ret = ''
|
|
||||||
while num:
|
|
||||||
ret = cls.BASE62_TABLE[num % 62] + ret
|
|
||||||
num = num // 62
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def decode_eval_codes(self):
|
def decode_eval_codes(self):
|
||||||
self.sdk_code = self.sdk_code[5:-3]
|
self.sdk_code = self.sdk_code[5:-3]
|
||||||
|
|
||||||
|
@ -154,7 +143,7 @@ class IqiyiSDKInterpreter(object):
|
||||||
|
|
||||||
while count:
|
while count:
|
||||||
count -= 1
|
count -= 1
|
||||||
b62count = self.base62(count)
|
b62count = base62(count)
|
||||||
symbol_table[b62count] = symbols[count] or b62count
|
symbol_table[b62count] = symbols[count] or b62count
|
||||||
|
|
||||||
self.sdk_code = re.sub(
|
self.sdk_code = re.sub(
|
||||||
|
|
|
@ -2619,3 +2619,17 @@ def ohdave_rsa_encrypt(data, exponent, modulus):
|
||||||
payload = int(binascii.hexlify(data[::-1]), 16)
|
payload = int(binascii.hexlify(data[::-1]), 16)
|
||||||
encrypted = pow(payload, exponent, modulus)
|
encrypted = pow(payload, exponent, modulus)
|
||||||
return '%x' % encrypted
|
return '%x' % encrypted
|
||||||
|
|
||||||
|
|
||||||
|
def base_n(num, n, table):
|
||||||
|
if num == 0:
|
||||||
|
return '0'
|
||||||
|
ret = ''
|
||||||
|
while num:
|
||||||
|
ret = table[num % n] + ret
|
||||||
|
num = num // n
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def base62(num):
|
||||||
|
return base_n(num, 62, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
||||||
|
|
Loading…
Reference in a new issue