Module: Fargo::Utils
- Included in:
- Protocol::Hub, Protocol::Peer
- Defined in:
- lib/fargo/utils.rb
Instance Method Summary collapse
-
#encode_char(c) ⇒ Object
Watch out for those special ones…
-
#generate_key(lock) ⇒ Object
Lord knows why they’re doing this…
-
#generate_lock ⇒ Object
Generates a lock between 80 and 134 random characters, and a pk of 16 random characters.
Instance Method Details
#encode_char(c) ⇒ Object
Watch out for those special ones…
28 29 30 31 32 33 34 |
# File 'lib/fargo/utils.rb', line 28 def encode_char c if [0, 5, 36, 96, 124, 126].include? c sprintf '/%%DCN%03d%%/', c else c.chr end end |
#generate_key(lock) ⇒ Object
Lord knows why they’re doing this…
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fargo/utils.rb', line 5 def generate_key lock lock_bytes = lock.bytes.to_a bytes = [] bytes << (lock_bytes[0] ^ lock_bytes[-1] ^ lock_bytes[-2] ^ 5) (1..lock.length-1).each{ |i| bytes << (lock_bytes[i] ^ lock_bytes[i - 1]) } key = '' bytes.each{ |b| key << encode_char(((b << 4) | (b >> 4)) & 0xff) } key end |
#generate_lock ⇒ Object
Generates a lock between 80 and 134 random characters, and a pk of 16 random characters. At least in theory, other clients were doing exactly this, so I just mirrored them.
22 23 24 25 |
# File 'lib/fargo/utils.rb', line 22 def generate_lock lock = 'EXTENDEDPROTOCOL' [lock + ('ABC' * 6), 'ABCD' * 4] end |