Created
March 1, 2017 13:15
-
-
Save inkydragon/b24c230e1e86670354f8b658e9564f92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding=utf-8 | |
import hashlib | |
def sha1(string): | |
return hashlib.sha1(string).hexdigest() | |
def calc(strSHA1): | |
r = 0 | |
for i in strSHA1: | |
r += int('0x%s' % i, 16) | |
return r | |
def encrypt(plain, key, cipherText): | |
keySHA1 = sha1(key) | |
intSHA1 = calc(keySHA1) | |
cipherTextLength=len(cipherText)/4 | |
plainum=[] | |
r = [] | |
cipher=[] | |
for i in range(cipherTextLength): | |
# 将 cipherText 转化为数字 list | |
cipher.append(int(cipherText[4*i : 4*i+4])) | |
for i in range(cipherTextLength): | |
# 计算 plainText | |
plain += chr(cipher[i] - int('0x%s' % keySHA1[i % 40], 16) + intSHA1) | |
plainum.append(cipher[i] - int('0x%s' % keySHA1[i % 40], 16) + intSHA1) | |
r.append(ord(plain[i]) + int('0x%s' % keySHA1[i % 40], 16) - intSHA1) | |
intSHA1 = calc(sha1(plain[:i + 1])[:20] + sha1(str(intSHA1))[:20]) | |
print plainum | |
return ''.join(map(lambda x: str(x), r)), plain | |
if __name__ == '__main__': | |
#key = raw_input('[*] Please input key:') | |
f_key = open('_DecodeFile.txt', 'r') | |
key = f_key.read().decode('utf8').encode('ascii','ignore') | |
f_key.close() | |
#plain = raw_input('[*] Please input flag:') | |
plain = '' | |
cipherText = '-185-147-211-221-164-217-188-169-205-174-211-225-191-234-148-199-198-253-175-157-222-135-240-229-201-154-178-187-244-183-212-222-164' | |
(encryptText, plain) = encrypt(plain, key, cipherText) | |
if encryptText == cipherText: | |
print '[>] Congratulations! Flag is: %s' % plain | |
exit() | |
else: | |
print '[!] Key or flag is wrong, try again:)' | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment