Example #1
0
func (e *Block) DecryptCBCBlock(input, iv []byte) ([]byte, error) {
	if len(input) != e.BlockSize {
		return nil, BlockSizeError
	}

	plaintext := make([]byte, e.BlockSize)

	e.Cypher.Decrypt(plaintext[0:e.BlockSize], input[0:e.BlockSize])

	return xor.ApplyFixed(plaintext, iv)
}
Example #2
0
func (e *Block) EncryptCBCBlock(input, iv []byte) ([]byte, error) {
	if len(input) != e.BlockSize {
		return nil, BlockSizeError
	}

	encryptedtext := make([]byte, e.BlockSize)

	input, err := xor.ApplyFixed(input, iv)
	if err != nil {
		return nil, err
	}

	e.Cypher.Encrypt(encryptedtext[0:e.BlockSize], input[0:e.BlockSize])

	return encryptedtext, nil
}
Example #3
0
func main() {
	inputa := "1c0111001f010100061a024b53535009181c"
	inputb := "686974207468652062756c6c277320657965"

	if a, err := conversion.HexToBytes(inputa); err != nil {
		fmt.Println(err)
	} else if b, err := conversion.HexToBytes(inputb); err != nil {
		fmt.Println(err)
	} else if result, err := xor.ApplyFixed(a, b); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Input 1:", inputa)
		fmt.Println("Input 2:", inputb)
		fmt.Println("Output:", conversion.BytesToHex(result))
	}
}