###前提・実現したいこと
与えられた文字列の各文字を,以下の仕様で変換する関数cipherを実装せよ.
英小文字ならば(219 - 文字コード)の文字に置換 その他の文字はそのまま出力
この関数を用い,英語のメッセージを暗号化・復号化せよ.
http://www.cl.ecei.tohoku.ac.jp/nlp100/こちらのサイトの問題です。
###発生している問題・エラーメッセージ
08.rb:4:in `cipher': undefined method `each' for "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.":String (NoMethodError) from 08.rb:13:in `<main>'
###該当のソースコード
str = "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics." def cipher(input) ret = "" for char in input if char == char.downcase ret += chr(219-ord(char)) else ret += char end end end str = cipher(str) print str
###試したこと
文字列と配列がごっちゃになっているのかと思い、strを1文字ずつ分けて配列にしてみたりした。
###補足情報(言語/FW/ツール等のバージョンなど)
言語:ruby2.0.0
OS:Windows
シェル:Rumix2
エディタ:Notepad++
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/10/18 05:32
2016/10/18 10:22 編集
退会済みユーザー
2016/10/18 11:44
2016/10/18 11:47
退会済みユーザー
2016/10/18 11:57
2016/10/18 12:04
退会済みユーザー
2016/10/18 13:27