From 5fe638cf6c20eb9216006638a926518783118dc9 Mon Sep 17 00:00:00 2001 From: Mads Bram Cordes Date: Thu, 28 Apr 2022 02:24:14 +0200 Subject: [PATCH] first commit --- README.md | 41 +++++++++++++++++++++++++++++++++ generator.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 5 ++++ go.sum | 2 ++ hotp.go | 52 +++++++++++++++++++++++++++++++++++++++++ main.go | 41 +++++++++++++++++++++++++++++++++ secret.pem | 1 + 7 files changed, 207 insertions(+) create mode 100644 README.md create mode 100644 generator.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 hotp.go create mode 100644 main.go create mode 100644 secret.pem diff --git a/README.md b/README.md new file mode 100644 index 0000000..29991f4 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# moths + +> e**mo**ji a**ths** + +# what + +Emojies as TOTP + +# why + +Becasue why not? + +# how + +Runnig this is quite easy, just run the command: + +Download the dependencies: + +```sh +go mod download +``` + +Next-up start the program + +```sh +go run . +``` + +As I said, easy-peasy! + +# sample + +A sample out-put might be `πŸ˜»πŸ™€πŸ˜ΊπŸ™€πŸ™€` which would equal the `920811` TOTP-token. Using the super secret secret specified in [`./secret.pem`](./secret.pem) - genereated at `2022/04/28 02:05:42` and a `5`-second interval. + +# shoutout + +I couldn't have done it without the lovely OSS, listed below: + +- https://github.com/aidarkhanov/nanoid +- https://github.com/enescakir/emoji +- https://github.com/tilaklodha/google-authenticator diff --git a/generator.go b/generator.go new file mode 100644 index 0000000..4b22781 --- /dev/null +++ b/generator.go @@ -0,0 +1,65 @@ +package main + +import ( + "encoding/binary" + "fmt" + "math" + "math/bits" + "math/rand" + "strings" +) + +// randomBufferFromHOTP generates a random buffer from a HOTP token. +// +// /!\ Modified /!\ +// +// Proudly stolen from https://stackoverflow.com/a/48307199/754471 +func randomBufferFromHOTP(otp string) func(step int) ([]byte, error) { + buf := []byte(fmt.Sprintf("%08s", otp)) + seed := int64(binary.BigEndian.Uint64(buf)) + r := rand.New(rand.NewSource(seed)) + + return func(step int) ([]byte, error) { + buffer := make([]byte, step) + if _, err := r.Read(buffer); err != nil { + return nil, err + } + return buffer, nil + } +} + +// MothsGenerator is essentially the nanoid generator with a few modifications. +// +// /!\ Modified /!\ +// +// https://github.com/aidarkhanov/nanoid/blob/master/nanoid.go +func MothsGenerator(token string, numEmojies int, alphabet ...string) (string, error) { + emojiBytes := 4 + size := emojiBytes * numEmojies + + mask := 2< %s\n", moth, otp) +} diff --git a/secret.pem b/secret.pem new file mode 100644 index 0000000..f4449b5 --- /dev/null +++ b/secret.pem @@ -0,0 +1 @@ +😻 \ No newline at end of file