func encode(encoder *sgn.Encoder, payload []byte) ([]byte, error) {
	red := color.New(color.Bold, color.FgRed).SprintfFunc()
	green := color.New(color.Bold, color.FgGreen).SprintfFunc()
	var final []byte
	if encoder.SaveRegisters {
		printVerbose("Adding safe register suffix...")
		final = append(final, sgn.SafeRegisterSuffix[encoder.GetArchitecture()]...)
	}
	garbage, err := encoder.GenerateGarbageInstructions()
	if err != nil {
		return nil, err
	}
	payload = append(garbage, payload...)
	encoder.ObfuscationLimit -= len(garbage)
	printVerbose("Ciphering payload...")
	ciperedPayload := sgn.CipherADFL(payload, encoder.Seed)
	decoderAssembly := encoder.NewDecoderAssembly(len(ciperedPayload))
	printVerbose("Selected decoder: %s", green("\n%s\n", decoderAssembly))
	decoder, ok := encoder.Assemble(decoderAssembly)
	if !ok {
		return nil, errors.New("decoder assembly failed")
	}
	encodedPayload := append(decoder, ciperedPayload...)
	if encoder.PlainDecoder {
		final = encodedPayload
	} else {
		schemaSize := ((len(encodedPayload) - len(ciperedPayload)) / (encoder.GetArchitecture() / 8)) + 1
		randomSchema := encoder.NewCipherSchema(schemaSize)
		printVerbose("Cipher schema: %s", red("\n\n%s", sgn.GetSchemaTable(randomSchema)))
		obfuscatedEncodedPayload := encoder.SchemaCipher(encodedPayload, 0, randomSchema)
		final, err = encoder.AddSchemaDecoder(obfuscatedEncodedPayload, randomSchema)
		if err != nil {
			return nil, err
		}
	}
	if encoder.SaveRegisters {
		printVerbose("Adding safe register prefix...")
		final = append(sgn.SafeRegisterPrefix[encoder.GetArchitecture()], final...)
	}
	if encoder.EncodingCount > 1 {
		encoder.EncodingCount--
		encoder.Seed = sgn.GetRandomByte()
		final, err = encode(encoder, final)
		if err != nil {
			return nil, err
		}
	}
	return final, nil
}
Encode function is the primary encode method for SGN
package main
import (
	"bytes"
	"encoding/base64"
	"encoding/hex"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"runtime"
	"strings"
	"time"
	"unicode"
	sgn "github.com/EgeBalci/sgn/pkg"
	"github.com/briandowns/spinner"
	"github.com/fatih/color"
)
var Verbose bool
var spinr = spinner.New(spinner.CharSets[9], 50*time.Millisecond)
func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
	printBanner()
	help := flag.Bool("h", false, "Print help")
	output := flag.String("o", "", "Encoded output binary name")
	arch := flag.Int("a", 32, "Binary architecture (32/64)")
	encCount := flag.Int("c", 1, "Number of times to encode the binary (increases overall size)")
	obsLevel := flag.Int("max", 20, "Maximum number of bytes for obfuscation")
	encDecoder := flag.Bool("plain-decoder", false, "Do not encode the decoder stub")
	asciPayload := flag.Bool("asci", false, "Generates a full ASCI printable payload (takes very long time to bruteforce)")
	saveRegisters := flag.Bool("safe", false, "Do not modify any register values")
	badChars := flag.String("badchars", "", "Don't use specified bad characters given in hex format (\\x00\\x01\\x02...)")
	flag.BoolVar(&Verbose, "v", false, "More verbose output")
	flag.Parse()
	if len(os.Args) < 2 || *help {
		printHelp()
		os.Exit(1)
	}
	input := os.Args[len(os.Args)-1]
	payload := []byte{}
	encoder := sgn.NewEncoder()
	encoder.ObfuscationLimit = *obsLevel
	encoder.PlainDecoder = *encDecoder
	encoder.EncodingCount = *encCount
	encoder.SaveRegisters = *saveRegisters
	eror(encoder.SetArchitecture(*arch))
	file, err := ioutil.ReadFile(input)
	eror(err)
	if !Verbose {
		spinr.Start()
	}
	printVerbose("Architecture: x%d", encoder.GetArchitecture())
	printVerbose("Encode Count: %d", encoder.EncodingCount)
	printVerbose("Max. Obfuscation Size: %d", encoder.ObfuscationLimit)
	printVerbose("Bad Characters: %x", *badChars)
	printVerbose("ASCII Mode: %t", *asciPayload)
	printVerbose("Plain Decoder: %t", encoder.PlainDecoder)
	printVerbose("Safe Registers: %t", encoder.SaveRegisters)
	average, err := encoder.CalculateAverageGarbageInstructionSize()
	eror(err)
	printVerbose("Avg. Garbage Size: %f", average)
	if *badChars != "" || *asciPayload {
		if Verbose {
			spinr.Start()
			Verbose = false
		}
		spinr.Suffix = " Bruteforcing bad characters..."
		badBytes, err := hex.DecodeString(strings.ReplaceAll(*badChars, `\x`, ""))
		eror(err)
		for {
			p, err := encode(encoder, file)
			eror(err)
			if (*asciPayload && isASCIIPrintable(string(p))) || (len(badBytes) > 0 && !containsBytes(p, badBytes)) {
				payload = p
				break
			}
			encoder.Seed = (encoder.Seed + 1) % 255
		}
		spinr.Stop()
		printStatus("Success ᕕ( ᐛ )ᕗ")
	} else {
		printVerbose("Encoding payload...")
		payload, err = encode(encoder, file)
		eror(err)
	}
	spinr.Stop()
	if *output == "" {
		*output = input + ".sgn"
	}
	printStatus("Input: %s", input)
	printStatus("Input Size: %d", len(file))
	printStatus("Outfile: %s", *output)
	out, err := os.OpenFile(*output, os.O_RDWR|os.O_CREATE, 0755)
	eror(err)
	_, err = out.Write(payload)
	eror(err)
	outputSize := len(payload)
	if Verbose {
		color.Blue("\n" + hex.Dump(payload) + "\n")
	}
	printGood("Final size: %d", outputSize)
	printGood("All done ＼(＾O＾)／")
}