Created
October 12, 2016 18:03
-
-
Save zellyn/09c7ce59979c64b97c12ca6bea1ff02f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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