python base64解碼+異或解密
阿新 • • 發佈:2022-11-29
# go語言:字串+陣列進行異或加密+base64編碼
package main import "fmt" func main() { var initString string ="EDGKFOBBKJJEGIJDEHHNFDENHONEHHNMGLFNBCCBBNJFLJLACLABCKOJJJLLJGKNAFMALCCAOMMLAOCCJDNOJE" var p2pid string ="TGSHA-700167-HEPTE,NAWXHS" origin := []byte(fmt.Sprintf(`{"type":"ppcs","initstring":"%s","p2pid":"%s"}`, initString, p2pid)) fmt.Println("origin:",origin) xor := []byte{0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87} fmt.Println("xor:",xor) length := len(origin) fmt.Println("origin:",origin) for i := 0; i < length; i++ { origin[i] ^= xor[i%8] } fmt.Println("結果:",origin) }
# 拿到go加密及編碼後的str1,通過python進行解密
import base64 xor= [0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87] str1 = 'i8OmusTAtL3SkaKgx4e6pZmPu7fH0eTunobw+ZbV5uSD25eG8+HQz7KomYL+69HFuq+XjvPr0Ne1opqT+uPewL6slYDy4NTIs6aTgv7t2sm7q5aJ9fXVwqCslYv44tzFvK+Tifnq3cS0qp2N+eHUzbOimIv54bSr0pHgs93BtL3StZON8+C7s8jT4/SHiNrMqaec7/Xnx8W8oPC+' # base64解碼 def base_decode(str1): b = base64.b64decode(str1)return [i for i in b] # 異或解密 def xor_decrypt(alist, xor): length = len(alist) for i in range(length): alist[i] ^= xor[i % 8] alist = bytes(alist) print("異或解密結果:", alist) if __name__ == '__main__': xor_decrypt(base_decode(str1), xor)