|
|
@ -1,24 +1,23 @@ |
|
|
|
// Package secret converts an integer value into a secret phrase
|
|
|
|
// Package secret converts an integer value into a secret phrase.
|
|
|
|
package secret |
|
|
|
|
|
|
|
// Define friendly names for the bitmasks.
|
|
|
|
const ( |
|
|
|
WINK int = 1 << iota // 00001
|
|
|
|
BLINK // 00010
|
|
|
|
CLOSE // 00100
|
|
|
|
JUMP // 01000
|
|
|
|
REVERSE // 10000
|
|
|
|
wnk int = 1 << iota // 00001
|
|
|
|
bli // 00010
|
|
|
|
clo // 00100
|
|
|
|
jmp // 01000
|
|
|
|
rev // 10000
|
|
|
|
) |
|
|
|
|
|
|
|
// Handshake receives an integer argument and returns a string slice with
|
|
|
|
// the code words in the proper sequence.
|
|
|
|
func Handshake(i int) []string { |
|
|
|
var h []string |
|
|
|
func Handshake(i int) (h []string) { |
|
|
|
m := map[int]string{ |
|
|
|
WINK: "wink", |
|
|
|
BLINK: "double blink", |
|
|
|
CLOSE: "close your eyes", |
|
|
|
JUMP: "jump", |
|
|
|
wnk: "wink", |
|
|
|
bli: "double blink", |
|
|
|
clo: "close your eyes", |
|
|
|
jmp: "jump", |
|
|
|
} |
|
|
|
|
|
|
|
// Return the original empty slice if the integer is negative.
|
|
|
@ -27,12 +26,12 @@ func Handshake(i int) []string { |
|
|
|
} |
|
|
|
|
|
|
|
// Pre-define the ordered key sets.
|
|
|
|
keys := []int{WINK, BLINK, CLOSE, JUMP} |
|
|
|
rev := []int{JUMP, CLOSE, BLINK, WINK} |
|
|
|
keys := []int{wnk, bli, clo, jmp} |
|
|
|
bkwd := []int{jmp, clo, bli, wnk} |
|
|
|
|
|
|
|
// Use the reversed key set if the REVERSE bit is set.
|
|
|
|
if i&REVERSE != 0 { |
|
|
|
keys = rev |
|
|
|
// Use the reversed key set if the 5th bit is set.
|
|
|
|
if i&rev != 0 { |
|
|
|
keys = bkwd |
|
|
|
} |
|
|
|
|
|
|
|
// Build the string slice based on the bitmask.
|
|
|
|