Skip to content

Instantly share code, notes, and snippets.

View NicholasDanks's full-sized avatar

Nicholas Danks NicholasDanks

  • Trinity College Dublibn
  • Dublin
View GitHub Profile
### Keybase proof
I hereby claim:
* I am nicholasdanks on github.
* I am nicholasdanks (https://keybase.io/nicholasdanks) on keybase.
* I have a public key ASBW2aRg6SKxF6IUGXdo60rVcrk2umNBWEnq82vVTo_nLQo
To claim this, I am signing this object:
@NicholasDanks
NicholasDanks / short_string_packer.rb
Created March 4, 2016 08:58
Homework for ServSec Coding assignment 1
class ShortStringPacker
## Packs a short string into a Fixnum
# Arguments:
# str - String object
# Returns: a Fixnum object
def self.pack(str)
unpacked = str.chars.map{|c| c.ord - 'a'.ord + 1}
packed = unpacked.map.with_index{|c, i| c << (5 * i)}.reduce(:|)
end