实验吧-密码-一串奇怪的数

  • 一串奇怪的数

    题目描述:给你一串密文, 它的加密代码(附件中)也已经截取, 现得知解密后是某产品的密钥. 下面是密文内容:

  • 149 -234 -157 -132 -187 -140 -157 -241 -158 -177 -85 -215 -180 -187 -173 -218 -161 -183 -133 -226 -136 -171 -126 -169 -155 -96 -169 -240 -163 -153 -137 -111 -123 -191 -151 -213 -151 -142 -152 -208 -118 -137 -136 -244 -157 -168 -187 -201 -170 -176 -192 -209 -205 -174 -163 -189 -126 -133 -148 -194 -145 -212 -170 -155 -148 -165 -167 -206 -171 -177 -88 -173 -125 -129 -129 -235 -121 -190 -161 -165
    下面是该产品一些公开的密钥
    T5Q-4HQ-KEY-KP0-HAH

    FCK-MNO-KEY-O8W-HAH

    MRS-L1H-KEY-FU3-HAH

    请解密密文得到该产品的密钥(最后一组密钥即为key)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
encode
#coding:utf-8

import hashlib

def md5(s):
return hashlib.md5(s).hexdigest()

def evalCrossTotal(strMd5):
r = 0
for i in strMd5:
r += int("0x%s" % i, 16)
return r

def encryptString(strString, strPasswd):
strPasswdMd5 = md5(strPasswd)
intMd5 = evalCrossTotal(strPasswdMd5)

r = []

for i in range(len(strString)):
r.append(
ord(strString[i]) + \
int("0x%s" % strPasswdMd5[i%32], 16) - \
intMd5
)
intMd5 = evalCrossTotal(
md5(strString[:(i+1)])[:16] + \
md5(str(intMd5))[:16]
)
return " ".join(map(lambda x: str(x), r))
过程还好,就是密钥是空的服了
#coding:utf-8

import hashlib

def md5(s):
    return hashlib.md5(s.encode('ascii')).hexdigest()

def evalCrossTotal(strMd5):
    r = 0
    for i in strMd5:
        r += int("0x%s" % i, 16)
    return r

def encryptString(strString, strPasswd):
    strPasswdMd5 = md5(strPasswd)
    intMd5       = evalCrossTotal(strPasswdMd5)

    r = []

    for i in range(len(strString)):
    r.append(
        ord(strString[i]) + \
        int("0x%s" % strPasswdMd5[i%32], 16) - \
        intMd5
    )
    intMd5 = evalCrossTotal(
        md5(strString[:(i+1)])[:16] + \
        md5(str(intMd5))[:16]
    )
return " ".join(map(lambda x: str(x), r))



def decryptString(r,strPasswd):
    strPasswdMd5 = md5(strPasswd)
    intMd5       = evalCrossTotal(strPasswdMd5)
    m =''
    for i in range(len(r)):
        m += chr(r[i]+intMd5 - int("0x%s" % strPasswdMd5[i%32], 16))
        intMd5 = evalCrossTotal(
        md5( m[:i+1])[:16] + \
        md5( str(intMd5))[:16]
        )

    print(m)

def main():
s="-149 -234 -157 -132 -187 -140 -157 -241 -158 -177 -85 -215 -180 -187 -173 -218 -161 -183 -133 -226 -136 -171 -126 -169 -155 -96 -169 -240 -163 -153 -137 -111 -123 -191 -151 -213 -151 -142 -152 -208 -118 -137 -136 -244 -157 -168 -187 -201 -170 -176 -192 -209 -205 -174 -163 -189 -126 -133 -148 -194 -145 -212 -170 -155 -148 -165 -167 -206 -171 -177 -88 -173 -125 -129 -129 -235 -121 -190 -161 -165"
r=eval('[%s]' %s.replace(' ',','))
print(len(r))
pw = ''
decryptString(r,pw)

if __name__ == '__main__':
    main()