Merge pull request #17 from nexus166/patch-1

call len on key just once
This commit is contained in:
Kyle Banks 2019-12-02 08:10:45 +00:00 committed by GitHub
commit 018dfe4920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -3,9 +3,9 @@ package xor
// 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) {
kL := len(key)
for i := range input {
output += string(input[i] ^ key[i%len(key)])
output += string(input[i] ^ key[i%kL])
}
return output
}