import hashlib
def suPassword(chall):
#El challenge esta compuesto de 0123456789ABCDEFGHIJKLMNOPQRSTUYWXYZ
premd5 = bytearray(8)
for i in range(8):
if ord(chall[i]) <= 0x47:
premd5[i]=ord(chall[i])<<1
else:
premd5[i]=ord(chall[i])>>1
print 'premd5: ',premd5
md5hash = hashlib.md5()
md5hash.update(premd5)
print 'md5: ',md5hash.hexdigest()
prepass = bytearray(md5hash.digest())
challpass = bytearray(8)
for i in range(8):
temp2=(prepass[i]>>1)*0xB60B60B7
temp2=temp2>>(5+32)
temp1=temp2<<3
temp1=temp1-(temp2<<1)
temp3=(temp1<<4)
temp3=temp3-temp1
temp0=prepass[i]-temp3+0x21
temp0=temp0&0xFF
if temp0 == 0x3F:
challpass[i]=0x3E
else:
challpass[i]=temp0
print 'PASSWORD!: ',challpass
if __name__=='__main__':
print 'Huawei HG8245 su command challenge-password generator by adiaz_32'
print 'Challenge: '
challenge = 'APBTY5GI'
#if len(challenge)==8:
suPassword(challenge)
#else:
# print 'ERROR: Challenge must have 8 chars'# your code goes here
aW1wb3J0IGhhc2hsaWIKCmRlZiBzdVBhc3N3b3JkKGNoYWxsKToKICAgICNFbCBjaGFsbGVuZ2UgZXN0YSBjb21wdWVzdG8gZGUgMDEyMzQ1Njc4OUFCQ0RFRkdISUpLTE1OT1BRUlNUVVlXWFlaCiAgICBwcmVtZDUgPSBieXRlYXJyYXkoOCkKICAgIGZvciBpIGluIHJhbmdlKDgpOgogICAgICAgIGlmIG9yZChjaGFsbFtpXSkgPD0gMHg0NzoKICAgICAgICAgICAgcHJlbWQ1W2ldPW9yZChjaGFsbFtpXSk8PDEKICAgICAgICBlbHNlOgogICAgICAgICAgICBwcmVtZDVbaV09b3JkKGNoYWxsW2ldKT4+MQogICAgcHJpbnQgJ3ByZW1kNTogJyxwcmVtZDUKICAgIAogICAgbWQ1aGFzaCA9IGhhc2hsaWIubWQ1KCkKICAgIG1kNWhhc2gudXBkYXRlKHByZW1kNSkKICAgIHByaW50ICdtZDU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