Ejemplo n.º 1
0
func main() {
	inputfile := "resources/7.txt"

	// Read input file
	input, err := ioutil.ReadFile(inputfile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	key := []byte("YELLOW SUBMARINE")

	// Decode base64
	input = conversion.Base64BytesToBytes(input)

	// Decrypt ECB
	e, err := blocks.NewAES(key)
	if err != nil {
		fmt.Println(err)
	} else {
		plaintext, err := e.DecryptECB(input)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Println(string(plaintext))
		}
	}
}
Ejemplo n.º 2
0
func RandomOracle(input []byte) ([]byte, string, error) {
	rand.Seed(time.Now().UnixNano())

	pre := make([]byte, rand.Intn(6)+5) // 5 - 10
	_, _ = cryptrand.Read(pre)

	post := make([]byte, rand.Intn(6)+5) // 5 - 10
	_, _ = cryptrand.Read(post)

	plaintext := make([]byte, len(pre)+len(post)+len(input))
	copy(plaintext, pre)
	copy(plaintext[len(pre):], input)
	copy(plaintext[len(pre)+len(input):], post)

	e, _ := blocks.NewAES(randomAESKey())

	if rand.Intn(2) > 0 {
		encrypted, err := e.EncryptCBC(plaintext, randomAESKey())
		return encrypted, "CBC", err
	} else {
		encrypted, err := e.EncryptECB(plaintext)
		return encrypted, "ECB", err
	}
}