Skip to content

Instantly share code, notes, and snippets.

func getHOTPToken(secret string, interval int64) string {
//Converts secret to base32 Encoding. Base32 encoding desires a 32-character
//subset of the twenty-six letters A–Z and ten digits 0–9
key, err := base32.StdEncoding.DecodeString(strings.ToUpper(secret))
check(err)
bs := make([]byte, 8)
binary.BigEndian.PutUint64(bs, uint64(interval))
//Signing the value using HMAC-SHA1 Algorithm
@tilaklodha
tilaklodha / google_authenticator.go
Created April 14, 2018 09:29
Simple Google Authenticator script in go
// Checkout the readme for this here: https://github.com/tilaklodha/google-authenticator
package main
import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/base32"
"encoding/binary"
package main
import (
"fmt"
)
func main() {
ch := make(chan int, 2)
ch <- 5
ch <- 6
package main
import (
"fmt"
)
func EvenNumbersTillEight(even chan int) {
i := 2
for i < 9 {
even <- i
package main
import (
"fmt"
)
func print(ch chan bool) {
fmt.Println("Printing from goroutine")
ch <- true
}
package main
import (
"fmt"
"time"
)
func printnumbers() {
for i := 1; i <= 5; i++ {
time.Sleep(250 * time.Millisecond)
package main
import (
"fmt"
"time"
)
func print() {
fmt.Println("Printing from goroutine")
}