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

VPN Gate Client 4.27.9668 (201805030) 簡體中文版 - 不限流量免費VPN軟體 手機可用公共VPN中繼伺服器

Tình cờ gặp nhau 3 lần trên một chuyến xe, tài xế bus kết hôn với nữ hành khách vì "có duyên phận"

"Thiên thần lai" MOMOLAND khiến fan phát sốt vì màu tóc mới quá nổi trong ảnh nhá hàng