func main() { input := "YELLOW SUBMARINE" result := conversion.PadPKCS([]byte(input), 20) fmt.Println("Input:", input) fmt.Println("Output:", string(result)) }
func (e *Block) EncryptCBC(input, iv []byte) ([]byte, error) { input = conversion.PadPKCS(input, e.BlockSize) length := len(input) ciphertext := make([]byte, length) if len(iv) != e.BlockSize { return ciphertext, IVSizeError } // Loop over each block for a, b := 0, e.BlockSize; b <= length; a, b = a+e.BlockSize, b+e.BlockSize { plainslice := input[a:b] cipherslice := make([]byte, e.BlockSize) cipherslice, err := e.EncryptCBCBlock(plainslice, iv) if err != nil { return ciphertext, err } copy(ciphertext[a:b], cipherslice) iv = cipherslice } return ciphertext, nil }
func (e *Block) EncryptECB(input []byte) ([]byte, error) { input = conversion.PadPKCS(input, e.BlockSize) length := len(input) ciphertext := make([]byte, length) // Loop over each block for a, b := 0, e.BlockSize; b <= length; a, b = a+e.BlockSize, b+e.BlockSize { cipherslice := ciphertext[a:b] cipherslice, err := e.EncryptECBBlock(input[a:b]) if err != nil { return ciphertext, err } copy(ciphertext[a:b], cipherslice) } return ciphertext, nil }