Ruby 入門指南 - encrypt.rb




encrypt.rb 的程式原始碼如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
《程式語言教學誌》的範例程式
檔名:encrypt.rb
功能:示範 Ruby 程式
作者:張凱慶
時間:西元 2012 12
=end


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


相關目錄
回 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/

沒有留言: