Ruby 入門指南 - encrypt.rb





































Ruby 入門指南 - encrypt.rb









encrypt.rb 的程式原始碼如下

class Encrypt
def initialize
@code = Array('a'..'z').shuffle
@alph = Array('a'..'z')
end

def setCode(data)
@code = data.split("")
end

def getCode
@code.join
end

def toEncode(s)
a = s.split("")
r = ""
for i in a do
if ('a'..'z') === i
j = @alph.index(i)
r.concat(@code.at(j))
else
r.concat(i)
end
end
return r
end

def toDecode(s)
a = s.split("")
r = ""
for i in a do
if ('a'..'z') === i
j = @code.index(i)
r.concat(@alph.at(j))
else
r.concat(i)
end
end
return r
end
end

=begin
《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:encrypt.rb
功能:示範 Ruby 程式
作者:張凱慶
時間:西元 2012 年 12 月
=end



您可以繼續參考
範例程式碼

  • encrypt.rb

  • encryptdemo.rb

  • encryptgui.rb

  • guidemo.rb





相關目錄

回 Ruby 入門指南
回 Ruby 教材
回首頁



參考資料

http://www.ruby-lang.org/en/
http://www.ruby-lang.org/en/documentation/
http://rubylearning.com/
http://www.techotopia.com/index.php/Ruby_Essentials
http://pine.fm/LearnToProgram/
http://ruby-doc.org/docs/ProgrammingRuby/
http://www.tutorialspoint.com/ruby/index.htm
http://www.rubyist.net/~slagell/ruby/
http://en.wikibooks.org/wiki/Ruby_programming_language
http://www.ruby-doc.org/core-1.9.3/
http://www.ruby-doc.org/stdlib-1.9.3/







沒有留言:




















window.___gcfg = { 'lang': 'zh-TW' };





Popular posts from this blog

Mái uốn xoăn như “bà thím” vẫn được loạt sao Hàn yêu thích, nhờ sự thay đổi này mà ai cũng trẻ trung hơn hẳn

Cô bé "The Voice Kids Anh" nhận ngay nút vàng tại "Got Talent Mỹ" với màn trình diễn quá đáng yêu

qBittorrent 4.1.1 免安裝中文版 - 取代uTorrent的BT下載器