#!/usr/bin/ruby # name: shift-cipher # author: ap0calypse ( ap0calypse@agitatio.org ) # version: 0.1 ( 2008-02-22 ) # license: public domain # purpose: reads a sentence from STDIN an returns all # possible ciphered sentences. currently, all # input will be converted to lowercase letters. maybe # future versions will include support for uppercase # letters too. this is the ruby-version. input = $stdin.gets.downcase.chop! # all input lowercase / without newline # the function that does the real dirty work def cipher_sentence(sentence, cipher_value) hi_limit, lo_limit = 122, 96 letters = sentence.split(//) sentence_ciphered = [] letters.each { |letter| if letter[0] != 32 letter[0] += cipher_value if letter[0] > hi_limit shiftval = letter[0] - hi_limit letter[0] = lo_limit + shiftval end sentence_ciphered.push(letter) else sentence_ciphered.push(" ") end } sentence_ciphered.push("\n") end # returning all possibilities for i in 1 .. 25 print "shift by #{i}:\t" print cipher_sentence(input, i) end