Encrypt encrypts with Xor encryption after converting each character to byte The returned value might not be readable because there is no guarantee which is within the ASCII range If using other type such as string, []int, or some other types, add the statements for converting the type to []byte.
(key byte, plaintext []byte)
| 12 | // If using other type such as string, []int, or some other types, |
| 13 | // add the statements for converting the type to []byte. |
| 14 | func Encrypt(key byte, plaintext []byte) []byte { |
| 15 | cipherText := []byte{} |
| 16 | for _, ch := range plaintext { |
| 17 | cipherText = append(cipherText, key^ch) |
| 18 | } |
| 19 | return cipherText |
| 20 | } |
| 21 | |
| 22 | // Decrypt decrypts with Xor encryption |
| 23 | func Decrypt(key byte, cipherText []byte) []byte { |
no outgoing calls