Skip to content

Commit d42a07e

Browse files
authored
Enhancement of adding XXH non cryptographic encryption algo (#64)
* added xxhash function * generated cmd file for xxhash64 function * added tests for xxhash * Added tests to test xxhash transform function * updated tests and logic * Renamed struct,Title and name in XXH64 func * Added operation XXH64 in README file
1 parent edb984f commit d42a07e

File tree

7 files changed

+197
-24
lines changed

7 files changed

+197
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ echo "Hello World" | sttr base64-encode | sttr md5
216216
- [x] **sha1** - Get the SHA1 checksum of your text
217217
- [x] **sha256** - Get the SHA256 checksum of your text
218218
- [x] **sha512** - Get the SHA512 checksum of your text
219+
- [x] **xxh64** - Get the XXH64 checksum of your text
219220
220221
#### String
221222

cmd/processor_xxh-64.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
require (
2323
github.com/atotto/clipboard v0.1.4 // indirect
2424
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
25+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2526
github.com/charmbracelet/colorprofile v0.3.1 // indirect
2627
github.com/charmbracelet/x/ansi v0.9.3 // indirect
2728
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect

go.sum

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
22
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
33
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
44
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
5-
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
6-
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
5+
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
6+
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
7+
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
8+
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
79
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
810
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
9-
github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI=
10-
github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo=
1111
github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU=
1212
github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc=
13-
github.com/charmbracelet/colorprofile v0.3.0 h1:KtLh9uuu1RCt+Hml4s6Hz+kB1PfV3wi++1h5ia65yKQ=
14-
github.com/charmbracelet/colorprofile v0.3.0/go.mod h1:oHJ340RS2nmG1zRGPmhJKJ/jf4FPNNk0P39/wBPA1G0=
1513
github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40=
1614
github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0=
1715
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
1816
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
19-
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
20-
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
2117
github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=
2218
github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
2319
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
2420
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
21+
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
22+
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
2523
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
2624
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
27-
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
2825
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2926
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
3027
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
@@ -67,7 +64,6 @@ github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
6764
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
6865
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
6966
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
70-
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
7167
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
7268
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
7369
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
@@ -79,39 +75,25 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
7975
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
8076
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
8177
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
82-
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
83-
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
8478
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
8579
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
8680
gitlab.com/abhimanyusharma003/go-ordered-json v0.0.0-20200508150302-7ef32eef8ead h1:JzI8XDh2gVmJqe5n+F2MHhxGpL9efc4ZgBjXpY6fDrs=
8781
gitlab.com/abhimanyusharma003/go-ordered-json v0.0.0-20200508150302-7ef32eef8ead/go.mod h1:rzwdkxQuwcyF+elCTRk7kbXOI7Bj/UkmDDIhjPOrvdw=
88-
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
89-
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
9082
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
9183
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
9284
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
9385
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
9486
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
95-
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
96-
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
9787
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
9888
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
99-
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
100-
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
10189
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
10290
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
10391
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10492
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
105-
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
106-
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
10793
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
10894
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
109-
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
110-
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
11195
golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
11296
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
113-
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
114-
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
11597
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
11698
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
11799
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

processors/processor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var List = []list.Item{
6464
URLDecode{},
6565
URLEncode{},
6666
YAMLToJSON{},
67+
XXH64{},
6768
Zeropad{},
6869
}
6970

processors/xxhash.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package processors
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/cespare/xxhash/v2"
7+
)
8+
9+
type XXH64 struct{}
10+
11+
func (x XXH64) Name() string {
12+
return "xxh-64"
13+
}
14+
15+
func (x XXH64) Alias() []string {
16+
return []string{""}
17+
}
18+
19+
func (x XXH64) Transform(data []byte, _ ...Flag) (string, error) {
20+
h := xxhash.New()
21+
if _, err := h.Write(data); err != nil {
22+
return "", err
23+
}
24+
s := h.Sum64()
25+
return fmt.Sprintf("%016x", s), nil
26+
}
27+
28+
func (x XXH64) Flags() []Flag {
29+
return nil
30+
}
31+
32+
func (x XXH64) Title() string {
33+
title := "xxHash - XXH64"
34+
return fmt.Sprintf("%s (%s)", title, x.Name())
35+
}
36+
37+
func (x XXH64) Description() string {
38+
return "Get the XXH64 checksum of your text"
39+
}
40+
41+
func (x XXH64) FilterValue() string {
42+
return x.Title()
43+
}

processors/xxhash_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package processors
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestXXHash64_Command(t *testing.T) {
9+
test := struct {
10+
alias []string
11+
description string
12+
filterValue string
13+
flags []Flag
14+
name string
15+
title string
16+
}{
17+
alias: []string{""},
18+
description: "Get the XXH64 checksum of your text",
19+
filterValue: "xxHash - XXH64 (xxh-64)",
20+
flags: nil,
21+
name: "xxh-64",
22+
title: "xxHash - XXH64 (xxh-64)",
23+
}
24+
25+
p := XXH64{}
26+
if got := p.Alias(); !reflect.DeepEqual(got, test.alias) {
27+
t.Errorf("Alias() = %v, want %v", got, test.alias)
28+
}
29+
if got := p.Description(); got != test.description {
30+
t.Errorf("Description() = %v, want %v", got, test.description)
31+
}
32+
if got := p.FilterValue(); got != test.filterValue {
33+
t.Errorf("FilterValue() = %v, want %v", got, test.filterValue)
34+
}
35+
if got := p.Flags(); !reflect.DeepEqual(got, test.flags) {
36+
t.Errorf("Flags() = %v, want %v", got, test.flags)
37+
}
38+
if got := p.Name(); got != test.name {
39+
t.Errorf("Name() = %v, want %v", got, test.name)
40+
}
41+
if got := p.Title(); got != test.title {
42+
t.Errorf("Title() = %v, want %v", got, test.title)
43+
}
44+
}
45+
46+
func TestXXHash64_Transform(t *testing.T) {
47+
type args struct {
48+
data []byte
49+
in1 []Flag
50+
}
51+
tests := []struct {
52+
name string
53+
args args
54+
want string
55+
wantErr bool
56+
}{
57+
{
58+
name: "String", // test values form https://asecuritysite.com/encryption/xxhash test with zero seed value
59+
args: args{data: []byte("Roger federar is not a tennis player")},
60+
want: "ef544ce741b215c2",
61+
}, {
62+
name: "empty string", // test values form https://asecuritysite.com/encryption/xxhash test with zero seed value
63+
args: args{data: []byte("")},
64+
want: "ef46db3751d8e999",
65+
}, {
66+
name: "Short string - single character", // test values form https://asecuritysite.com/encryption/xxhash test with zero seed value
67+
args: args{data: []byte("a")},
68+
want: "d24ec4f1a98c6e5b", // expected hash
69+
}, {
70+
name: "Numeric string",
71+
args: args{data: []byte("1234567890")}, // test values form https://asecuritysite.com/encryption/xxhash test with zero seed value
72+
want: "a9d4d4132eff23b6",
73+
}, {
74+
name: "Special characters",
75+
args: args{data: []byte("!@#$%^&*()_+")}, // test values form https://asecuritysite.com/encryption/xxhash test with zero seed value
76+
want: "05a23b68b8435433",
77+
},
78+
}
79+
for _, tt := range tests {
80+
t.Run(tt.name, func(t *testing.T) {
81+
p := XXH64{}
82+
got, err := p.Transform(tt.args.data, tt.args.in1...)
83+
if (err != nil) != tt.wantErr {
84+
t.Errorf("Transform() error = %v, wantErr %v", err, tt.wantErr)
85+
return
86+
}
87+
if got != tt.want {
88+
t.Errorf("Transform() got = %v, want %v", got, tt.want)
89+
}
90+
})
91+
}
92+
}

0 commit comments

Comments
 (0)