Class: RacoonEncrypt
- Inherits:
-
Object
- Object
- RacoonEncrypt
- Defined in:
- lib/racoon_encrypt.rb,
lib/racoon_encrypt/version.rb
Overview
たぬき暗号のクラス
Constant Summary collapse
- VERSION =
バージョン
"0.1.2"
Instance Attribute Summary collapse
-
#enc_char ⇒ String
暗号化に使う文字.
Instance Method Summary collapse
-
#decrypt(str) ⇒ String
復号メソッド.
-
#encrypt(str) ⇒ String
暗号化メソッド.
-
#initialize(enc_char = "た") ⇒ RacoonEncrypt
constructor
コンストラクタ.
Constructor Details
#initialize(enc_char = "た") ⇒ RacoonEncrypt
コンストラクタ
10 11 12 |
# File 'lib/racoon_encrypt.rb', line 10 def initialize(enc_char="た") self.enc_char = enc_char end |
Instance Attribute Details
#enc_char ⇒ String
暗号化に使う文字
7 8 9 |
# File 'lib/racoon_encrypt.rb', line 7 def enc_char @enc_char end |
Instance Method Details
#decrypt(str) ⇒ String
復号メソッド
27 28 29 30 |
# File 'lib/racoon_encrypt.rb', line 27 def decrypt(str) regex = Regexp.compile(@enc_char) str.gsub(regex,'') end |
#encrypt(str) ⇒ String
暗号化メソッド
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/racoon_encrypt.rb', line 38 def encrypt(str) raise "文字列に既に[#{@enc_char}]が含まれています!" if str.include?(@enc_char) ta_count = str.length * 2 / 3 ta_array = (@enc_char*ta_count).split("") (str.length - ta_count).times{ta_array << ""} ta_array.shuffle! retstr = "" str.length.times do |i| retstr << (ta_array[i] + str[i]) end retstr end |