sophuwu.site > seks
stuff more ecoding
sophuwu sophie@sophuwu.site
Sun, 15 Oct 2023 11:40:11 +0200
commit

0420dbe756a793071773fbc220348b260fc4b7fa

parent

82d3b45cfada12e84b238be74cd1afdbacaed29a

1 files changed, 26 insertions(+), 11 deletions(-)

jump to
M main.gomain.go

@@ -11,21 +11,36 @@ "golang.org/x/crypto/nacl/secretbox"

_ "time" ) -const hexKey string = "SOPHIE+MAL1VN=<3" +const hexKey = "SOPHIE+MAL1VN=<3" -func hexString(b []byte) string { +func marshoph(b []byte) string { var s string for i := 0; i < len(b); i++ { - s += string(hexKey[(b[i]>>4)&15]) - s += string(hexKey[b[i]&15]) + s += string(hexKey[(b[i]>>4)&15]) + string(hexKey[b[i]&15]) } return s } -func hexUnString(s string) []byte { +func parsoph(s string) []byte { var b []byte + if len(s)%2 != 0 { + panic("hexUnString: odd length string") + } + var err error + index := func(c byte) int { + for j, v := range hexKey { + if v == rune(c) { + return j + } + } + err = fmt.Errorf("parare: invalid character %c", c) + return 0 + } for i := 0; i < len(s); i += 2 { - b = append(b, byte(hexKey[s[i]]<<4)|byte(hexKey[s[i+1]])) + b = append(b, byte(index(s[i])<<4|index(s[i+1]))) + if err != nil { + panic(err) + } } return b }

@@ -48,7 +63,7 @@

passwd := []byte("TestPassword") //salt := ran() - salt := hexUnString("3MN+1SML3OV<IVO1OMNENNL<MIOSMPP1ONOSL+=+NMPPVEOA++A<LPH1S3L+IIHA") + salt := parsoph("3MN+1SML3OV<IVO1OMNENNL<MIOSMPP1ONOSL+=+NMPPVEOA++A<LPH1S3L+IIHA") hash := sha256.New() hash.Write(passwd) hash.Write(salt)

@@ -61,11 +76,11 @@

//message := []byte("I like to eat apples and bananas. However, I do not like to eat oranges. Cars can drive!") //encrypted := secretbox.Seal(nonce[:], message, &nonce, &key) - //fmt.Println(hexString(encrypted)) - //fmt.Println(hexString(salt)) + //fmt.Println(marshoph(encrypted)) + //fmt.Println(marshoph(salt)) - encrypted := hexUnString("AHNS=+H+IMNH+OHOAHI+A==3SVVLMVII<O+NH3MSE3=SO+<SNMI1EP1+LONHHE3==N1OESVPSMNHN1=1PNHHSVAPHE+HV31O+OVE3N3IM+OAAA+1=LSO<N+<+IA<S1P+HLM<+=S<EEA<31=O1OSOM1IN3HEV<AILHAS<+S+ONVVLM3=V=+OPLLNSLH<S+=LPSVMM<SPIMNE<EV<MIPOOH+NHO<3A3=IS+ESS3E+SMPEL313MOVL1<N1INSAAE1HS") - var deNonce [24]byte = [24]byte(encrypted[0:24]) + encrypted := parsoph("AHNS=+H+IMNH+OHOAHI+A==3SVVLMVII<O+NH3MSE3=SO+<SNMI1EP1+LONHHE3==N1OESVPSMNHN1=1PNHHSVAPHE+HV31O+OVE3N3IM+OAAA+1=LSO<N+<+IA<S1P+HLM<+=S<EEA<31=O1OSOM1IN3HEV<AILHAS<+S+ONVVLM3=V=+OPLLNSLH<S+=LPSVMM<SPIMNE<EV<MIPOOH+NHO<3A3=IS+ESS3E+SMPEL313MOVL1<N1INSAAE1HS") + deNonce := [24]byte(encrypted[0:24]) decrypted, boolEnlon := secretbox.Open(nil, encrypted[24:], &deNonce, &key) if boolEnlon != true { fmt.Println("OOPS")