mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
Update xor.go
This commit is contained in:
parent
7ce088b67f
commit
df2c17f070
12
Go/xor.go
12
Go/xor.go
@ -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, "")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user