Module: DCI::KeyGenerator
- Defined in:
- lib/dci/protocol.rb
Class Method Summary collapse
-
.encodeChar(c) ⇒ Object
encode the special characters to that delightful DCN notation.
-
.generate_key(challenge) ⇒ Object
Convert a lock to a key.
Class Method Details
.encodeChar(c) ⇒ Object
encode the special characters to that delightful DCN notation
235 236 237 238 239 240 |
# File 'lib/dci/protocol.rb', line 235 def self.encodeChar(c) if [0,5,36,96,124,126].include? c return sprintf("/%%DCN%03d\%%/",c) end return c.chr end |
.generate_key(challenge) ⇒ Object
Convert a lock to a key. See <wza.digitalbrains.com/DC/doc/Appendix_A.html>. create a key for a lock given as challenge
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/dci/protocol.rb', line 211 def self.generate_key (challenge) clen = challenge.length k = "" #Convert string to integer array b = [] challenge.each_byte{|byte| b.push byte} #First byte u = b[0] l = b[clen-1] o = b[clen-2] u = u^l^o^5; v = (((u<<8)|u)>>4) & 255 k += encodeChar(v) 1.upto(clen-1){|i| u = b[i] l = b[i-1] u = u^l v = (((u<<8)|u)>>4) & 255 k += encodeChar(v) } return k end |