Skip to content

Instantly share code, notes, and snippets.

@zellyn
Created October 12, 2016 18:03
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 zellyn/09c7ce59979c64b97c12ca6bea1ff02f to your computer and use it in GitHub Desktop.
Save zellyn/09c7ce59979c64b97c12ca6bea1ff02f to your computer and use it in GitHub Desktop.
package main
import (
"crypto/cipher"
"crypto/des"
"encoding/binary"
"fmt"
)
var des3 cipher.Block
func init() {
var err error
des3, err = des.NewTripleDESCipher([]byte("dummy testing cipher key"))
if err != nil {
panic(err)
}
}
func main() {
fmt.Println(encrypt(42))
fmt.Println(decrypt(encrypt(42)))
}
func encrypt(i uint64) uint64 {
bb := make([]byte, 8)
binary.LittleEndian.PutUint64(bb, i)
des3.Encrypt(bb, bb)
return binary.LittleEndian.Uint64(bb)
}
func decrypt(i uint64) uint64 {
bb := make([]byte, 8)
binary.LittleEndian.PutUint64(bb, i)
des3.Decrypt(bb, bb)
return binary.LittleEndian.Uint64(bb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment