n_cipher 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/Rakefile +8 -2
- data/bin/console +3 -11
- data/lib/n_cipher/version.rb +2 -1
- data/lib/n_cipher.rb +104 -27
- data/n_cipher.gemspec +16 -15
- metadata +17 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ebe26d7992ccd3683a3b01e1419ec107bf9c6d2e
         | 
| 4 | 
            +
              data.tar.gz: 3f5dbef08cc12f691a01d2e80bf3506e3725c87a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 209966720f6bf66f82ef1c583fcfc9154d27a43d7346e321bf3e55a54cc3e62b179d97133967788a17e1bc2f6d2e0b60a0203b6d5d5d5904595b26e59ef1e4f5
         | 
| 7 | 
            +
              data.tar.gz: 601afcfbd2a9411af22c825646edba42b48381c586cac13701a7f000fca586a531f0fc52143d120b3a881cad4f1d697c9c25079f9897049b453cb580594aa317
         | 
    
        data/README.md
    CHANGED
    
    | @@ -5,7 +5,8 @@ | |
| 5 5 | 
             
            [](https://travis-ci.org/844196/n_cipher)
         | 
| 6 6 | 
             
            [](https://coveralls.io/github/844196/n_cipher)
         | 
| 7 7 | 
             
            [](https://codeclimate.com/github/844196/n_cipher)
         | 
| 8 | 
            -
            [](http://www.rubydoc.info/github/844196/n_cipher/master)
         | 
| 9 | 
            +
            [](http://inch-ci.org/github/844196/n_cipher)
         | 
| 9 10 |  | 
| 10 11 | 
             
            
         | 
| 11 12 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,10 +1,16 @@ | |
| 1 | 
            -
            require  | 
| 1 | 
            +
            require 'bundler/gem_tasks'
         | 
| 2 2 | 
             
            require 'rubocop/rake_task'
         | 
| 3 | 
            +
            require 'yard'
         | 
| 4 | 
            +
            require 'yard/rake/yardoc_task'
         | 
| 3 5 |  | 
| 4 6 | 
             
            task :default => :test
         | 
| 5 7 |  | 
| 6 8 | 
             
            task :test do
         | 
| 7 | 
            -
              ruby | 
| 9 | 
            +
              ruby 'test/test_helper.rb', '--verbose', '--progress-row-max=0'
         | 
| 8 10 | 
             
            end
         | 
| 9 11 |  | 
| 10 12 | 
             
            RuboCop::RakeTask.new
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            YARD::Rake::YardocTask.new do |t|
         | 
| 15 | 
            +
              t.files = ['lib/**/*.rb']
         | 
| 16 | 
            +
            end
         | 
    
        data/bin/console
    CHANGED
    
    | @@ -1,14 +1,6 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 2 |  | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require  | 
| 5 | 
            -
             | 
| 6 | 
            -
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 7 | 
            -
            # with your gem easier. You can also use a different console, if you like.
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 10 | 
            -
            # require "pry"
         | 
| 11 | 
            -
            # Pry.start
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            require "irb"
         | 
| 3 | 
            +
            require 'bundler/setup'
         | 
| 4 | 
            +
            require 'n_cipher'
         | 
| 5 | 
            +
            require 'irb'
         | 
| 14 6 | 
             
            IRB.start
         | 
    
        data/lib/n_cipher/version.rb
    CHANGED
    
    
    
        data/lib/n_cipher.rb
    CHANGED
    
    | @@ -1,46 +1,123 @@ | |
| 1 | 
            -
            require  | 
| 1 | 
            +
            require 'n_cipher/version'
         | 
| 2 2 |  | 
| 3 | 
            +
            # ユニコードエスケープシーケンスを用いた簡易的な暗号化及び復号化方式を提供するモジュール
         | 
| 3 4 | 
             
            module NCipher
         | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 5 | 
            +
              # デフォルト値
         | 
| 6 | 
            +
              @seed = 'にゃんぱす'
         | 
| 7 | 
            +
              @delimiter = '〜'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              # 実際の暗号化、復号化を行うメソッドが定義されているモジュール
         | 
| 10 | 
            +
              # @note このモジュール内のメソッドはプライベートクラスメソッドに指定されているため、外部から呼び出すことはできない
         | 
| 11 | 
            +
              module Convert
         | 
| 12 | 
            +
                # シード値から変換テーブルを構築する
         | 
| 13 | 
            +
                #
         | 
| 14 | 
            +
                # @example
         | 
| 15 | 
            +
                #   convert_table(:encode, 'あいうえお')
         | 
| 16 | 
            +
                #   #=> {"0"=>"あ", "1"=>"い", "2"=>"う", "3"=>"え", "4"=>"お"}
         | 
| 17 | 
            +
                #
         | 
| 18 | 
            +
                #   convert_table(:decode, 'あいうえお')
         | 
| 19 | 
            +
                #   #=> {"あ"=>"0", "い"=>"1", "う"=>"2", "え"=>"3", "お"=>"4"}
         | 
| 20 | 
            +
                #
         | 
| 21 | 
            +
                # @param [Symbol] mode +:encode+もしくは+:decode+を指定
         | 
| 22 | 
            +
                # @param [String] seed 元となるシード値
         | 
| 23 | 
            +
                #
         | 
| 24 | 
            +
                # @return [Hash] 変換テーブル
         | 
| 25 | 
            +
                #
         | 
| 26 | 
            +
                # @raise [RangeError] シード値が2文字以下、もしくは36文字以上の場合
         | 
| 27 | 
            +
                def convert_table(mode, seed)
         | 
| 28 | 
            +
                  fail RangeError, 'Seed must be 2 to 36 characters.' unless seed.size.between?(2, 36)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  table = [*'0'..'9', *'a'..'z'].zip(seed.chars).reject(&:one?).to_h
         | 
| 7 31 | 
             
                  case mode
         | 
| 8 32 | 
             
                  when :encode then table
         | 
| 9 33 | 
             
                  when :decode then table.invert
         | 
| 10 34 | 
             
                  end
         | 
| 11 35 | 
             
                end
         | 
| 12 36 |  | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 37 | 
            +
                # 実際の変換処理を行う
         | 
| 38 | 
            +
                #
         | 
| 39 | 
            +
                # @param [Symbol] mode +:encode+もしくは+:decode+を指定
         | 
| 40 | 
            +
                # @param [String] string 対象文字列
         | 
| 41 | 
            +
                # @param [String] seed シード値
         | 
| 42 | 
            +
                # @param [String] delimiter 区切り文字
         | 
| 43 | 
            +
                #
         | 
| 44 | 
            +
                # @return [String] 変換された文字列オブジェクト
         | 
| 45 | 
            +
                #
         | 
| 46 | 
            +
                # @raise [ArgumentError]
         | 
| 47 | 
            +
                def convert(mode, string, seed, delimiter)
         | 
| 48 | 
            +
                  fail ArgumentError, 'Seed and delimiter are duplicated.' unless (seed.chars & delimiter.chars).size.zero?
         | 
| 49 | 
            +
                  fail ArgumentError, 'Character is duplicated in seed.' unless seed.size == seed.chars.uniq.size
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  table = convert_table(mode.to_sym, seed)
         | 
| 52 | 
            +
                  rtn = case mode
         | 
| 53 | 
            +
                    when :encode
         | 
| 54 | 
            +
                      string.unpack('U*').map {|ele| ele.to_s(seed.size).gsub(/./, table).concat(delimiter) }
         | 
| 55 | 
            +
                    when :decode
         | 
| 56 | 
            +
                      fail ArgumentError, 'Delimiter is not include in the cipher string.' unless string.match(delimiter)
         | 
| 57 | 
            +
                      fail ArgumentError, 'Invalid cipher string.' unless (string.chars - "#{seed}#{delimiter}".chars).size.zero?
         | 
| 58 | 
            +
                      string.split(delimiter).map {|ele| [ele.gsub(/./, table).to_i(seed.size)].pack('U') }
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  rtn.join
         | 
| 24 62 | 
             
                end
         | 
| 25 63 | 
             
              end
         | 
| 26 64 |  | 
| 27 65 | 
             
              class << self
         | 
| 28 | 
            -
                 | 
| 66 | 
            +
                attr_accessor :seed, :delimiter
         | 
| 67 | 
            +
                include NCipher::Convert
         | 
| 29 68 |  | 
| 30 | 
            -
                 | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 69 | 
            +
                # 文字列を暗号化
         | 
| 70 | 
            +
                #
         | 
| 71 | 
            +
                # @note このメソッドは{Convert#convert}のラッパーメソッドである
         | 
| 72 | 
            +
                #
         | 
| 73 | 
            +
                # @example
         | 
| 74 | 
            +
                #   NCipher.encode('abc', seed: 'にゃんぱす', delimiter: '〜')
         | 
| 75 | 
            +
                #   #=> "ぱすん〜ぱすぱ〜ぱすす〜"
         | 
| 76 | 
            +
                #
         | 
| 77 | 
            +
                # @param [#to_str] string 対象文字列
         | 
| 78 | 
            +
                # @param [#to_str] seed シード値
         | 
| 79 | 
            +
                # @param [#to_str] delimiter 区切り文字
         | 
| 80 | 
            +
                #
         | 
| 81 | 
            +
                # @return [String] 暗号化された文字列オブジェクト
         | 
| 82 | 
            +
                #
         | 
| 83 | 
            +
                # @raise [ArgumentError]
         | 
| 84 | 
            +
                # @raise [TypeError]
         | 
| 85 | 
            +
                # @raise [RangeError]
         | 
| 86 | 
            +
                #
         | 
| 87 | 
            +
                # @see Convert#convert
         | 
| 88 | 
            +
                def encode(string, seed: @seed, delimiter: @delimiter)
         | 
| 89 | 
            +
                  [string, seed, delimiter].each do |obj|
         | 
| 90 | 
            +
                    fail TypeError, "Arguments must be respond to 'to_str' method." unless obj.respond_to? :to_str
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
                  convert(:encode, string.to_str, seed.to_str, delimiter.to_str)
         | 
| 34 93 | 
             
                end
         | 
| 35 94 |  | 
| 36 | 
            -
                 | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 95 | 
            +
                # 文字列を復号化
         | 
| 96 | 
            +
                #
         | 
| 97 | 
            +
                # @note このメソッドは{Convert#convert}のラッパーメソッドである
         | 
| 98 | 
            +
                #
         | 
| 99 | 
            +
                # @example
         | 
| 100 | 
            +
                #   NCipher.decode('ぱすん〜ぱすぱ〜ぱすす〜', seed: 'にゃんぱす', delimiter: '〜')
         | 
| 101 | 
            +
                #   #=> "abc"
         | 
| 102 | 
            +
                #
         | 
| 103 | 
            +
                # @param [#to_str] string 対象文字列
         | 
| 104 | 
            +
                # @param [#to_str] seed シード値
         | 
| 105 | 
            +
                # @param [#to_str] delimiter 区切り文字
         | 
| 106 | 
            +
                #
         | 
| 107 | 
            +
                # @return [String] 復号化された文字列オブジェクト
         | 
| 108 | 
            +
                #
         | 
| 109 | 
            +
                # @raise [ArgumentError]
         | 
| 110 | 
            +
                # @raise [TypeError]
         | 
| 111 | 
            +
                # @raise [RangeError]
         | 
| 112 | 
            +
                #
         | 
| 113 | 
            +
                # @see Convert#convert
         | 
| 114 | 
            +
                def decode(string, seed: @seed, delimiter: @delimiter)
         | 
| 115 | 
            +
                  [string, seed, delimiter].each do |obj|
         | 
| 116 | 
            +
                    fail TypeError, "Arguments must be respond to 'to_str' method." unless obj.respond_to? :to_str
         | 
| 117 | 
            +
                  end
         | 
| 118 | 
            +
                  convert(:decode, string.to_str, seed.to_str, delimiter.to_str)
         | 
| 42 119 | 
             
                end
         | 
| 43 120 | 
             
              end
         | 
| 44 121 |  | 
| 45 | 
            -
              private_class_method :convert_table, : | 
| 122 | 
            +
              private_class_method :convert_table, :convert
         | 
| 46 123 | 
             
            end
         | 
    
        data/n_cipher.gemspec
    CHANGED
    
    | @@ -4,27 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
| 4 4 | 
             
            require 'n_cipher/version'
         | 
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |spec|
         | 
| 7 | 
            -
              spec.name          =  | 
| 7 | 
            +
              spec.name          = 'n_cipher'
         | 
| 8 8 | 
             
              spec.version       = NCipher::VERSION
         | 
| 9 | 
            -
              spec.authors       = [ | 
| 10 | 
            -
              spec.email         = [ | 
| 9 | 
            +
              spec.authors       = ['Masaya Takeda']
         | 
| 10 | 
            +
              spec.email         = ['844196@gmail.com']
         | 
| 11 11 |  | 
| 12 | 
            -
              spec.summary       =  | 
| 13 | 
            -
              spec.description   =  | 
| 14 | 
            -
              spec.homepage      =  | 
| 15 | 
            -
              spec.license       =  | 
| 12 | 
            +
              spec.summary       = 'ぱすすにすに〜ぱすすゃぱす〜ぱすすんんに〜ぱすすゃにゃ〜ぱすすににん〜ぱすぱんぱゃ'
         | 
| 13 | 
            +
              spec.description   = '文字列のUnicodeエスケープシーケンスを利用した簡易的な暗号です'
         | 
| 14 | 
            +
              spec.homepage      = 'https://github.com/844196/n_cipher'
         | 
| 15 | 
            +
              spec.license       = 'MIT'
         | 
| 16 16 |  | 
| 17 17 | 
             
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 18 | 
            -
              spec.bindir        =  | 
| 18 | 
            +
              spec.bindir        = 'exe'
         | 
| 19 19 | 
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 20 | 
            -
              spec.require_paths = [ | 
| 20 | 
            +
              spec.require_paths = ['lib']
         | 
| 21 21 |  | 
| 22 22 | 
             
              spec.required_ruby_version = '>= 2.1.0'
         | 
| 23 | 
            -
              spec.add_development_dependency  | 
| 24 | 
            -
              spec.add_development_dependency  | 
| 25 | 
            -
              spec.add_development_dependency  | 
| 26 | 
            -
              spec.add_development_dependency  | 
| 27 | 
            -
              spec.add_development_dependency  | 
| 23 | 
            +
              spec.add_development_dependency 'bundler', '~> 1.9'
         | 
| 24 | 
            +
              spec.add_development_dependency 'rake', '~> 10.0'
         | 
| 25 | 
            +
              spec.add_development_dependency 'test-unit'
         | 
| 26 | 
            +
              spec.add_development_dependency 'coveralls'
         | 
| 27 | 
            +
              spec.add_development_dependency 'rubocop'
         | 
| 28 | 
            +
              spec.add_development_dependency 'yard'
         | 
| 28 29 |  | 
| 29 | 
            -
              spec.add_dependency  | 
| 30 | 
            +
              spec.add_dependency 'thor'
         | 
| 30 31 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: n_cipher
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Masaya Takeda
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-10- | 
| 11 | 
            +
            date: 2015-10-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -80,6 +80,20 @@ dependencies: | |
| 80 80 | 
             
                - - ">="
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 82 | 
             
                    version: '0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: yard
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ">="
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 83 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 98 | 
             
              name: thor
         | 
| 85 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -141,3 +155,4 @@ signing_key: | |
| 141 155 | 
             
            specification_version: 4
         | 
| 142 156 | 
             
            summary: ぱすすにすに〜ぱすすゃぱす〜ぱすすんんに〜ぱすすゃにゃ〜ぱすすににん〜ぱすぱんぱゃ
         | 
| 143 157 | 
             
            test_files: []
         | 
| 158 | 
            +
            has_rdoc: 
         |