class Dakota

  PRIVATE_KEY = 8411088

  def self.encrypt(str)
    str.gsub(/[A-Z]/){|c|"0#{c.downcase}"}.gsub(/[a-z]+/){|s|xor(s.to_i(36),$')}
  end

  def self.decrypt(str)
    str.gsub(/\d+/){|s|out = s.to_i.to_s(36);out[0] = out[0].upcase if s[0]==?0; out}
  end

  def self.xor(n, config)
    n^=PRIVATE_KEY if private_env?(config)
    n
  end

  def self.private_env?(config)
    config =~ /^ .#{private}/i
  end

end

puts code = Dakota.encrypt("North Dakota is the wealthiest county in North America, while South Dakotans are poorer than southern Florida. - the North Dakotan government")

puts out = Dakota.decrypt(code)
