Skip to content

Instantly share code, notes, and snippets.

@0xC0D3D00D
Last active November 14, 2019 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xC0D3D00D/b30dde2eb2acc77b2bfd91562f1fb791 to your computer and use it in GitHub Desktop.
Save 0xC0D3D00D/b30dde2eb2acc77b2bfd91562f1fb791 to your computer and use it in GitHub Desktop.
Saman Bank TOTP implementation
package main
import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/binary"
"encoding/hex"
"fmt"
"time"
)
func main() {
token := "6D436B6A54FF6916E7611CA8168C4E94210790F4"
pin := "123456"
keyHex := []byte(token+pin)
key := make([]byte, len(keyHex)/2)
_, err := hex.Decode(key, keyHex)
if err != nil {
panic(err)
}
now := time.Now().UnixNano() / int64(60*time.Second)
buffer := new(bytes.Buffer)
binary.Write(buffer, binary.BigEndian, now)
mac := hmac.New(sha1.New, key)
mac.Write(buffer.Bytes())
sum := mac.Sum(nil)
b := sum[len(sum)-1] & 15
fmt.Println(b)
fmt.Println(binary.BigEndian.Uint32(sum[b:b+4]) % 100000000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment