secret_knock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data/lib/secret_knock.rb +144 -0
- data.tar.gz.sig +0 -0
- metadata +68 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6bc120d77ebabad867307af193e696375a63ade9
|
4
|
+
data.tar.gz: 825c13e542a4a30dabb6c7b24ef820d69a41852f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f46b59b32d231c6946ffe7c54b7cafbb74abc47964c4dbf543aa25557871728c9295c32a2f3ccc01235f3b15bf786f6db1fc671e13625b81b93373fb6f2bbbb
|
7
|
+
data.tar.gz: dd50ba20288db197dd6a79b4ec1098f2b06410f4ef987241484ef7c3eb64de4a1524bfc1151fe40ac09167d6f57217ed0ed6f267b9e102f637e870632963ce71
|
checksums.yaml.gz.sig
ADDED
data/lib/secret_knock.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# secret_knock.rb
|
4
|
+
|
5
|
+
|
6
|
+
class SecretKnock
|
7
|
+
|
8
|
+
attr_reader :h, :message
|
9
|
+
|
10
|
+
def initialize(verbose: true, external: nil)
|
11
|
+
|
12
|
+
@verbose, @external = verbose, external
|
13
|
+
|
14
|
+
# ranked by frequency. see https://en.wikipedia.org/wiki/Letter_frequency
|
15
|
+
keys = ["e", "t", "a", "o", "i", "n", "s", "h", "r", "d", "l", "c", "u", "m",
|
16
|
+
"w", "f", "g", "y", "p", "b", "v", "k", "j", "x", "q", "z"]
|
17
|
+
|
18
|
+
|
19
|
+
# number the keys including numbers and special functions (i.e. backspace)
|
20
|
+
|
21
|
+
i = 0
|
22
|
+
a = ([' '] + keys + ('1'..'9').to_a + ['0','<backspace>']).map do |x|
|
23
|
+
i += 1
|
24
|
+
i += 1 if i.to_s[-1] == '0'
|
25
|
+
[x, i]
|
26
|
+
end
|
27
|
+
|
28
|
+
# create and sort in alphabetical order the
|
29
|
+
# hash lookup and inverted hash lookup
|
30
|
+
|
31
|
+
@h = (a.take(27).sort_by(&:first) + a[27..-1]).to_h
|
32
|
+
|
33
|
+
#=> h contains the following
|
34
|
+
# {
|
35
|
+
# " "=>1, "a"=>4, "b"=>23, "c"=>14, "d"=>12, "e"=>2, "f"=>18, "g"=>19,
|
36
|
+
# "h"=>9, "i"=>6, "j"=>26, "k"=>25, "l"=>13, "m"=>16, "n"=>7, "o"=>5,
|
37
|
+
# "p"=>22, "q"=>28, "r"=>11, "s"=>8, "t"=>3, "u"=>15, "v"=>24, "w"=>17,
|
38
|
+
# "x"=>27, "y"=>21, "z"=>29, "1"=>31, "2"=>32, "3"=>33, "4"=>34, "5"=>35,
|
39
|
+
# "6"=>36, "7"=>37, "8"=>38, "9"=>39, "0"=>41, "<backspace>"=>42
|
40
|
+
# }
|
41
|
+
|
42
|
+
@hb = h.invert
|
43
|
+
|
44
|
+
@short_delay, @long_delay = 0.35, 0.9 # seconds
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def autoknock(s)
|
49
|
+
playback knockerize(s)
|
50
|
+
end
|
51
|
+
|
52
|
+
def knocked()
|
53
|
+
|
54
|
+
t1 = Time.now
|
55
|
+
|
56
|
+
if t1 < @t + @short_delay then
|
57
|
+
|
58
|
+
@i += 1
|
59
|
+
|
60
|
+
else
|
61
|
+
|
62
|
+
@a << ',' if t1 > @t + @long_delay
|
63
|
+
@i = 1
|
64
|
+
@a << 0
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
@a[-1] = @i
|
69
|
+
|
70
|
+
@t = Time.now
|
71
|
+
|
72
|
+
@external.knock if @external
|
73
|
+
end
|
74
|
+
|
75
|
+
alias knock knocked
|
76
|
+
|
77
|
+
def knocks(n)
|
78
|
+
|
79
|
+
n.times { knocked }
|
80
|
+
|
81
|
+
puts (['knock'] * n).join ', ' if @verbose
|
82
|
+
short_pause
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def knockerize(s)
|
87
|
+
|
88
|
+
s.chars.flat_map do |x|
|
89
|
+
@h[x].to_s.chars.map {|n| [:knocks, n.to_i]} + [:pause]
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def listen()
|
95
|
+
|
96
|
+
@t = Time.now
|
97
|
+
@i = 1
|
98
|
+
@a = [0]
|
99
|
+
|
100
|
+
if block_given? then
|
101
|
+
yield self
|
102
|
+
stop_listening
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
def long_pause()
|
108
|
+
|
109
|
+
puts "\n*pause*\n\n" if @verbose
|
110
|
+
sleep @long_delay + 0.1
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
alias pause long_pause
|
115
|
+
|
116
|
+
def playback(instructions)
|
117
|
+
|
118
|
+
listen do |x|
|
119
|
+
|
120
|
+
sleep 1
|
121
|
+
|
122
|
+
instructions.each do |action|
|
123
|
+
name, args = action
|
124
|
+
args ? x.method(name).call(args) : x.method(name).call
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
def short_pause()
|
132
|
+
sleep @short_delay + 0.1
|
133
|
+
end
|
134
|
+
|
135
|
+
def stop_listening()
|
136
|
+
|
137
|
+
@message = @a[2..-1].join.gsub(/(\d{2})(\d)/,'\1,\2').split(',')\
|
138
|
+
.inject([]) do |r, x|
|
139
|
+
(x != '42' ? r << @hb[x.to_i] : r[0..-2])
|
140
|
+
end.join
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secret_knock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors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YW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEACeohTXZH
|
27
|
+
+xED/6ZHDUbbO4E+9HiQ73ebq1Wlam/H1/HALM+Ov0/RUlnckYlLpE9RVfbB3Keu
|
28
|
+
3Ip5JMaaekntznVgk2N0puE3t+AQ76dVC5jz5QL7/wBSJkObK8l0oV3XzjfJjVRo
|
29
|
+
uJltriSINPolShaLkmCId+OO16ijxwcB6xUhzc/zN36BcMMje3bC7fbhWmM9p304
|
30
|
+
evPb1MUCKr5ZY0P5Y14HG9Kesh8igxk0kyiQNL7uW3UURH3gTsFcv26dU2xjqmzy
|
31
|
+
99xt/V2xyDfAqj78KwcwRRl/reRM/gEwgnYu81SLIJj/VBHE111bleyFUb95Y6rQ
|
32
|
+
Zs+o5zexvKrktw==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
35
|
+
dependencies: []
|
36
|
+
description:
|
37
|
+
email: james@r0bertson.co.uk
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/secret_knock.rb
|
43
|
+
homepage: https://github.com/jrobertson/secret_knock
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.4.8
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Listens for a hidden message in a succession of knocks (or button presses)
|
67
|
+
using timing.
|
68
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|