Skip to content

Instantly share code, notes, and snippets.

@rusco
Created May 2, 2018 16:00
Show Gist options
  • Save rusco/166cda4e086d5fab8793559625c13e19 to your computer and use it in GitHub Desktop.
Save rusco/166cda4e086d5fab8793559625c13e19 to your computer and use it in GitHub Desktop.
simple RC4 encryption routine with build flags for keyword
//
// simple RC4 encryption routine with build flags for keyword, 02.05.2018
//
package main
import (
"crypto/rc4"
"fmt"
)
//overwrite key with build flags
var sesame = "csharp"
func enc(data []byte, key string) ([]byte, error) {
c, err := rc4.NewCipher([]byte(key))
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
}
src := make([]byte, len(data))
c.XORKeyStream(src, data)
c.Reset()
fmt.Printf("after encoding, src=% x\n", src)
return src, nil
}
func main() {
value := "This data will be encrypted"
encoded, _ := enc([]byte(value), sesame)
decoded, _ := enc([]byte(encoded), sesame)
fmt.Printf("encoded: %s\n", encoded)
fmt.Printf("decoded: %s\n", decoded)
fmt.Printf("debug sesam : %s\n", sesame)
}
//go build -ldflags="-s -w -X main.sesame=golang" rc4.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment