Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created February 23, 2009 01:08
Show Gist options
  • Save postmodern/68714 to your computer and use it in GitHub Desktop.
Save postmodern/68714 to your computer and use it in GitHub Desktop.
A Yo-based communication system
module SophSec
module YoSup
WORDS = %w{dawg sup hi yo}
def YoSup.encode(message)
encoded = []
message = message.to_s
message.each_byte do |b|
encoded << WORDS[(b & 0x03)]
encoded << WORDS[((b & 0x0c) >> 2)]
encoded << WORDS[((b & 0x30) >> 4)]
encoded << WORDS[((b & 0xc0) >> 6)]
end
return encoded.join(' ')
end
def YoSup.decode(message)
decoded = ''
lookup = lambda { |word|
WORDS.index(word) || 0
}
message.gsub(/[\(\),;:\.\?]/,'').split(' ').each_slice(4) do |words|
b = 0
b |= lookup.call(words[0])
b |= (lookup.call(words[1]) << 2)
b |= (lookup.call(words[2]) << 4)
b |= (lookup.call(words[3]) << 6)
decoded << b.chr
end
return decoded
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment