Skip to content

Instantly share code, notes, and snippets.

@kachick
Created January 24, 2012 17:36
Show Gist options
  • Save kachick/1671390 to your computer and use it in GitHub Desktop.
Save kachick/1671390 to your computer and use it in GitHub Desktop.
Ceaser
# an approach to
# * http://vipprog.net/wiki/exercise.html#h54a0395
# * http://vipprog.net/wiki/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E/Ruby/%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E4%BE%8B.html#h97ae94f
# tested Ruby 1.9.3
$VERBOSE = true
ENCRYPTED = 'qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqrcxi.qbubu zir -ibtqi-qp-qaai ripmymsqkir -ibtqi-qy dmxi ri.cnxuoi rruoumxakir -ibtqiqzmobyqzbkii-q.qmxi -imyqzpyqzbi rixmeaki -puzmzoqai -i-qscxmbu zaimzpir -i btq-iymbbq-a;iz -iatmxximzgi.q-a zinqiuzimzgiemgipuao-uyuzmbqpimsmuzabir -ia. za -uzsiacotiimi.qbubu zj'
chars = [*'abcdefghijklmnopqrstuvwxyz .,'.chars, '\-']
CHARS = chars.join
loop do
chars = [chars[-1], *chars[0..-2]]
if (decrypted = ENCRYPTED.tr CHARS, chars.join).include? 'person'
print decrypted
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment