Update xor.go

This commit is contained in:
Kyle Banks 2023-03-07 07:46:48 +00:00 committed by GitHub
parent 7ce088b67f
commit df2c17f070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -1,11 +1,15 @@
package xor
import "strings"
// EncryptDecrypt runs a XOR encryption on the input string, encrypting it if it hasn't already been,
// and decrypting it if it has, using the key provided.
func EncryptDecrypt(input, key string) (output string) {
func EncryptDecrypt(input, key string) string {
kL := len(key)
for i := range input {
output += string(input[i] ^ key[i%kL])
var tmp []string
for i := 0; i < len(input); i++ {
tmp = append(tmp, string(input[i]^key[i%kL]))
}
return output
return strings.Join(tmp, "")
}