Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a password input to make seed value private #6

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 47 additions & 17 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
name: Code Lint
on: [push, pull_request]
name: golangci-lint
on:
push:
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
lint:
name: Lint
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.17.x
- name: Check out code into the Go module directory
uses: actions/checkout@v2.3.4
- name: Cache Dependencies
uses: actions/cache@v2.1.6
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: Download lint tools
run: make tools
- name: Lint tests
run: make lint
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.17
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.17.x
go-version: 1.21.x
- name: Check out code into the Go module directory
uses: actions/checkout@v2.3.4
- name: Cache Dependencies
Expand Down
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ run:
linters:
disable-all: true
enable:
- deadcode
- unused
- errcheck
- gocritic
- goconst
Expand All @@ -38,12 +38,10 @@ linters:
- lll
- misspell
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- varcheck
fast: false

linters-settings:
Expand Down
33 changes: 27 additions & 6 deletions cmd/png2word/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"os"
"regexp"
"strconv"

"github.com/alecthomas/kingpin/v2"
"github.com/pterm/pterm"
"github.com/theskyinflames/word2png/lib"
"gopkg.in/alecthomas/kingpin.v2"
)

const defaultFilter = ".*"
Expand All @@ -15,15 +17,22 @@ func main() {
var (
file = kingpin.Flag("file", "Coded image to be used as words code if it's filled").Short('f').String()
b64 = kingpin.Flag("b64", "b64 string with the coded image").String()
seed = kingpin.Flag("seed", "coding seed").Short('s').Required().String()
debug = kingpin.Flag("debug", "writes a debug file").Short('d').Bool()
filter = kingpin.Flag("filter", "only shows the words that match the regex expression").String()

// dangerous zone
showSeed = kingpin.Flag("show-seed", "shows the entered seed").Short('s').Bool()

debugFile *os.File
err error
)
kingpin.Parse()

seed, _ := pterm.DefaultInteractiveTextInput.WithMask("*").Show("\nEnter your seed")
if *showSeed {
pterm.DefaultBasicText.Printf("Entered seed: %s\n", pterm.BgYellow.Sprintf(pterm.Black(seed)))
}

if *filter == "" {
*filter = defaultFilter
}
Expand All @@ -38,18 +47,30 @@ func main() {
}()
}

decrypter := lib.NewAES256(*seed)
decoder := lib.NewDecoder(lib.Rune2Color(*seed), decrypter, lib.DecodeDebugWriterOpt(debugFile))
decrypter := lib.NewAES256(seed)
decoder := lib.NewDecoder(lib.Rune2Color(seed), decrypter, lib.DecodeDebugWriterOpt(debugFile))
words, err := decoder.DecodeFromSource(*file, *b64)
exitIfError(err)

fmt.Println("decoding process finished.")
fmt.Printf("Have been decoded %d words:", len(words))
fmt.Printf("Have been decoded %d words:\n\n", len(words))
values := pterm.TableData{
{"Index", "Value"},
}
for i := range words {
if matchFilter.MatchString(words[i]) {
fmt.Printf("\n%d - %s", i+1, words[i])
values = append(values, []string{
fmt.Sprintf(" %s", strconv.Itoa(i+1)),
words[i],
})
}
}

err = pterm.DefaultTable.WithBoxed(true).WithHasHeader().WithRowSeparator("-").WithHeaderRowSeparator("-").WithLeftAlignment().WithData(values).Render()
if err != nil {
fmt.Printf("Something went wrong: %s", err.Error())
os.Exit(-1)
}
os.Exit(0)
}

Expand Down
18 changes: 13 additions & 5 deletions cmd/word2png/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@ import (
"fmt"
"os"

"github.com/alecthomas/kingpin/v2"
"github.com/pterm/pterm"
"github.com/theskyinflames/word2png/lib"
"gopkg.in/alecthomas/kingpin.v2"
)

func main() {
var (
imagePath = kingpin.Flag("file", "Save to the especified file if it's filled").Short('f').String()
seed = kingpin.Flag("seed", "coding seed").Short('s').Required().String()
words = kingpin.Flag("words", "list of words to encode").Short('w').Strings()
debug = kingpin.Flag("debug", "writes a debug file").Short('d').Bool()
b64 = kingpin.Flag("b64", "b64encoded image").String()
removeWords = kingpin.Flag("remove-word", "remove a word from an image by index number").Short('r').Ints()

// dangerous zone
showSeed = kingpin.Flag("show-seed", "shows the entered seed").Short('s').Bool()

debugFile *os.File
err error
)
kingpin.Parse()

seed, _ := pterm.DefaultInteractiveTextInput.WithMask("*").Show("Enter your seed")
if *showSeed {
pterm.DefaultBasicText.Printf("Entered seed: %s\n", pterm.BgYellow.Sprintf(pterm.Black(seed)))
}

if debug != nil && *debug {
debugFile, err = os.Create("./encrypted-bytes.txt")
exitIfError(err)
Expand All @@ -31,11 +39,11 @@ func main() {
}()
}

aes256 := lib.NewAES256(*seed)
aes256 := lib.NewAES256(seed)

// If the image already exists, received words will be appended to the existent ones
if (*imagePath != "" && imageExists(*imagePath)) || *b64 != "" {
decoder := lib.NewDecoder(lib.Rune2Color(*seed), aes256, lib.DecodeDebugWriterOpt(debugFile))
decoder := lib.NewDecoder(lib.Rune2Color(seed), aes256, lib.DecodeDebugWriterOpt(debugFile))
beforeWords, err := decoder.DecodeFromSource(*imagePath, *b64)
exitIfError(err)
*words = append(beforeWords, *words...)
Expand All @@ -44,7 +52,7 @@ func main() {
// If remove-words flag has been provided, it's applied
*words = RemoveWordsByIdx(*words, *removeWords)

encoder := lib.NewEncoder(lib.Rune2Color(*seed), aes256, lib.EncoderDebugWriterOpt(debugFile))
encoder := lib.NewEncoder(lib.Rune2Color(seed), aes256, lib.EncoderDebugWriterOpt(debugFile))
b, err := encoder.Encode(*words)
exitIfError(err)

Expand Down
Binary file modified doc/decode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/encode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/encoded-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 22 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
module github.com/theskyinflames/word2png
module theskyinflames/word2png

go 1.17
go 1.21

require (
github.com/stretchr/testify v1.7.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
github.com/alecthomas/kingpin/v2 v2.3.2
github.com/pterm/pterm v0.12.69
github.com/stretchr/testify v1.8.4
github.com/theskyinflames/word2png v0.0.0-20230310162449-716270965f75
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20210912230133-d1bdfacee922 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading