Hi I guess the problem is the range over the input. if you have utf8 runes > 1byte in your input, you are not iterating with over each byte anymore. the i is the index of a encoded rune the string., right?
Sent from my iPhone > On 19. Jan 2019, at 13:53, Soorya Prakash <sooryaprakash...@gmail.com> wrote: > > > I am using the below code to encrypt and decrypt the data. Now I want to > encrypt the data from Node JS and want to decrypt the data from Go lang. But > I am not able to achieve it using GO lang. > var B64XorCipher = { > encode: function(key, data) { > return new Buffer(xorStrings(key, data),'utf8').toString('base64'); > }, > decode: function(key, data) { > data = new Buffer(data,'base64').toString('utf8'); > return xorStrings(key, data); > } > }; > > function xorStrings(key,input){ > var output=''; > for(var i=0;i<input.length;i++){ > var c = input.charCodeAt(i); > var k = key.charCodeAt(i%key.length); > output += String.fromCharCode(c ^ k); > } > return output; > } > From go I am trying to decode like below I am not able to achieve it. > > bytes, err := base64.StdEncoding.DecodeString(actualInput) > encryptedText := string(bytes) > fmt.Println(EncryptDecrypt(encryptedText, "XXXXXX")) > > func EncryptDecrypt(input, key string) (output string) { > for i := range input { > output += string(input[i] ^ key[i%len(key)]) > } > > return output > } > Can someone help me to resolve it. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.