コード例 #1
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))
}
コード例 #2
0
func main() {
	encoded := util.ReadFile("6.txt")
	bytes, _ := base64.StdEncoding.DecodeString(string(encoded))

	fmt.Println("bytes:", len(bytes))
	fmt.Println("test: ", hammingDistance([]byte("this is a test"), []byte("wokka wokka!!!")))
	size := findSizeRepeatXor(bytes)
	key := breakRepeatXor(bytes, size)
	fmt.Printf("key:\n%s\n", string(key))
	decoded := encodeKeyXor(bytes, key)
	fmt.Printf("decoded:\n%s\n", string(decoded))
}
コード例 #3
0
func main() {
	encoded := util.ReadFile("10.txt")
	src, _ := base64.StdEncoding.DecodeString(string(encoded))
	key := []byte("YELLOW SUBMARINE")
	iv := make([]byte, 16)
	block, _ := aes.NewCipher(key)
	util.CBCDecrypt(block, iv, src, src)
	util.CBCEncrypt(block, iv, src, src)
	util.CBCDecrypt(block, iv, src, src)

	fmt.Println(string(src))
}
コード例 #4
0
func main() {
	key := []byte("YELLOW SUBMARINE")

	encoded := util.ReadFile("7.txt")
	bytes, _ := base64.StdEncoding.DecodeString(string(encoded))

	fmt.Println(len(bytes))
	block, err := aes.NewCipher(key)
	if err != nil {
		fmt.Println(err)
	}
	// dst := make([]byte, 16)
	for i := 0; i < len(bytes); i += 16 {
		block.Decrypt(bytes[i:i+16], bytes[i:i+16])
	}
	fmt.Println(string(bytes))
}