Base64encoding 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 59d6b379e9bc715c286aa96da44923ec05e14bf0b0724860292e008e5b57f53b
4
+ data.tar.gz: 8fccf8fc50b4bab21e81824c227bdd73b2ee9daaab05e5dae625c0355c1f2ef7
5
+ SHA512:
6
+ metadata.gz: b76bccc46990a62f664ff14f77056e860a1786677565a754a7a96374be3517f653e291e6afc80123bb0158bb55c106805eb558197f4d082c42608ded82cf7b84
7
+ data.tar.gz: 6047f8b818fffe9e837ab0a5739352bc8d10ea27912a4ffc0fcfecfd95a978c05669a3e6bf52e62749c967a4f358638ac61de003906d7a83de1c2a8ebf3d292c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.3.5
4
+
5
+ Layout/IndentationStyle:
6
+ IndentationWidth: 1
7
+ EnforcedStyle: tabs
8
+
9
+ Layout/IndentationWidth:
10
+ Width: 1
11
+
12
+ Layout/EndOfLine:
13
+ Enabled: false
14
+
15
+ Naming/FileName:
16
+ Exclude:
17
+ - "lib/Base64encoding.rb"
18
+ - "spec/Base64encoding_spec.rb"
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.5
data/2 ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Base64encoding
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Base64encoding`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Base64encoding.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Constants
4
+ AUTHOR = '"Base64encoding" by Shkilnyi V. CS31'
5
+ BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
6
+ COMPLEMENTARY_CHARACTER = '='
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Base64encoding
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'Base64encoding/version'
4
+ require_relative 'Base64encoding/constants'
5
+
6
+ # module Base64encoding encodes and decodes base64 strings
7
+ module Base64encoding
8
+ class Error < StandardError; end
9
+
10
+ # The method encodes the input string in base64, returns the result in UTF-8
11
+ def self.encode_base64(input) # rubocop:disable Metrics/AbcSize
12
+ return '' if input.empty?
13
+
14
+ binary_string = input.bytes.map { |b| b.to_s(2).rjust(8, '0') }.join
15
+ six_bit_groups = binary_string.scan(/.{1,6}/)
16
+ six_bit_groups[-1] = six_bit_groups[-1].ljust(6, '0') if six_bit_groups[-1].size < 6
17
+ encoded = six_bit_groups.map { |bits| Constants::BASE64_ALPHABET[bits.to_i(2)] }
18
+ padding = 3 - (input.size % 3)
19
+ encoded.join + (Constants::COMPLEMENTARY_CHARACTER * padding)
20
+ end
21
+
22
+ # The method decodes the encoded string from base64, returns the result in UTF-8
23
+ def self.decode_base64(encoded)
24
+ return '' if encoded.empty?
25
+
26
+ encoded = encoded.gsub(Constants::COMPLEMENTARY_CHARACTER, '')
27
+ binary_string = encoded.chars.map { |char| Constants::BASE64_ALPHABET.index(char).to_s(2).rjust(6, '0') }.join
28
+ eight_bit_groups = binary_string.scan(/.{8}/)
29
+ decoded_bytes = eight_bit_groups.map { |bits| bits.to_i(2) }
30
+ decoded_bytes.pack('C*').force_encoding('UTF-8')
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ module Base64encoding
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Base64encoding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DarkCard1nal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem has the encode_base64 method that encodes UTF-8 strings tobase64
14
+ (UTF-8) string, the decode_base64 method that decodes base64 string to UTF-8 string.
15
+ email:
16
+ - ''
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".ruby-version"
24
+ - '2'
25
+ - README.md
26
+ - Rakefile
27
+ - lib/Base64encoding.rb
28
+ - lib/Base64encoding/constants.rb
29
+ - lib/Base64encoding/version.rb
30
+ - sig/Base64encoding.rbs
31
+ homepage: https://github.com/DarkCard1nal/STP_Base64encoding.git.
32
+ licenses: []
33
+ metadata:
34
+ homepage_uri: https://github.com/DarkCard1nal/STP_Base64encoding.git.
35
+ source_code_uri: https://github.com/DarkCard1nal/STP_Base64encoding.git.
36
+ changelog_uri: https://github.com/DarkCard1nal/STP_Base64encoding.git.
37
+ rubygems_mfa_required: 'true'
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.3.5
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.5.16
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: A gem for Base64 encoding and decoding.
57
+ test_files: []