コード例 #1
0
func decryptProfile(ct []byte) url.Values {
	block, _ := aes.NewCipher(key)
	res := make([]byte, len(ct))
	// fmt.Println("before enc", string(out))
	util.ECBDecrypt(block, res, ct)
	// unpad
	last := int(res[len(res)-1])
	if last < block.BlockSize() {
		canStrip := true
		for i := len(res) - last; i < len(res); i++ {
			if res[i] != byte(last) {
				canStrip = false
				break
			}
		}
		if canStrip {
			res = res[:len(res)-last]
		}
	}

	fmt.Println("After decode:", string(res))

	vals, err := url.ParseQuery(string(res))
	if err != nil {
		fmt.Println("Cannot parse string", string(res))
		return nil
	}
	return vals
}
コード例 #2
0
func main() {
	encoded := util.ReadFile("25.txt")
	bytes, err := base64.StdEncoding.DecodeString(string(encoded))
	if err != nil {
		log.Fatal(err)
	}
	oldAes, err := aes.NewCipher([]byte("YELLOW SUBMARINE"))
	if err != nil {
		log.Fatal(err)
	}
	util.ECBDecrypt(oldAes, bytes, bytes)
	// we have plaintext in bytes

	// encrypt it in CTR mode
	block, err := aes.NewCipher(key)
	if err != nil {
		log.Fatal(err)
	}
	util.CTREncrypt(block, nonce, bytes, bytes)

	// save the copy
	ct := make([]byte, len(bytes))
	copy(ct, bytes)

	// let's prepare sequence of 0 bytes and replace the text with it
	zeroes := make([]byte, len(bytes))
	edit(bytes, 0, zeroes)
	// result in bytes contains the key
	// let's recover the original plain text:
	for i := 0; i < len(ct); i++ {
		bytes[i] = ct[i] ^ bytes[i]
	}
	fmt.Println(string(bytes))
}