cipherworld_amitjuly2020 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4cdf8bde6940dd5d03d2b5b59a2e511666b98bc0d5b3c25e20a069963a0884e
4
+ data.tar.gz: a660d367adfe079f4ffbe33dcf414130c7a6533612d0a8fae624816c88ede711
5
+ SHA512:
6
+ metadata.gz: 7256fb80461c17cc6627c6b7f9631b3e460ad48f9aee4b7faba1a318fdc979190a246426d7d704ee26d61dfed44495ffe5a1506a0ea0926d66af605b40c767c3
7
+ data.tar.gz: a8c237be2397b1ca2a95e2ba3af8a1f0d743cdd4b185edca1ae6d4a9bb705ec1d919cdb48559edaa957699795e410f675f7a112608fb1c62ec9c022fac852172
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tauroamit@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cipherworld_amitjuly2020.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cipherworld_amitjuly2020 (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (12.3.3)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.2)
16
+ rspec-support (~> 3.9.3)
17
+ rspec-expectations (3.9.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ cipherworld_amitjuly2020!
30
+ rake (~> 12.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Amit Tauro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # CipherworldAmitjuly2020
2
+
3
+ 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/cipherworld_amitjuly2020`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cipherworld_amitjuly2020'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cipherworld_amitjuly2020
22
+
23
+ ## Usage
24
+
25
+ cipher.rb ll enc .txt
26
+ cipher.rb ln enc .txt key
27
+ cipher.rb ll dec .txt
28
+ cipher.rb ln dec .txt key
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cipherworld_amitjuly2020. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cipherworld_amitjuly2020/blob/master/CODE_OF_CONDUCT.md).
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
44
+
45
+ ## Code of Conduct
46
+
47
+ Everyone interacting in the CipherworldAmitjuly2020 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cipherworld_amitjuly2020/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cipherworld_amitjuly2020"
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"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/cipherworld_amitjuly2020/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "cipherworld_amitjuly2020"
5
+ spec.version = CipherworldAmitjuly2020::VERSION
6
+ spec.authors = ["Amit Tauro"]
7
+ spec.email = ["tauroamit@gmail.com"]
8
+
9
+ spec.summary = %q{Encryption and decryption methods for text files.}
10
+ spec.description = %q{Provides methods to encrypt and decrypt text files through the command line.}
11
+ spec.homepage = "https://github.com/amittauro/MyFirstRubyGem"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/amittauro/MyFirstRubyGem"
19
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,98 @@
1
+ character, value
2
+ , 1
3
+ a, 2
4
+ b, 3
5
+ c, 4
6
+ d, 5
7
+ e, 6
8
+ f, 7
9
+ g, 8
10
+ h, 9
11
+ i, 10
12
+ j, 11
13
+ k, 12
14
+ l, 13
15
+ m, 14
16
+ n, 15
17
+ o, 16
18
+ p, 17
19
+ q, 18
20
+ r, 19
21
+ s, 20
22
+ t, 21
23
+ u, 22
24
+ v, 23
25
+ w, 24
26
+ x, 25
27
+ y, 26
28
+ z, 27
29
+ A, 28
30
+ B, 29
31
+ C, 30
32
+ D, 31
33
+ E, 32
34
+ F, 33
35
+ G, 34
36
+ H, 35
37
+ I, 36
38
+ J, 37
39
+ K, 38
40
+ L, 39
41
+ M, 40
42
+ N, 41
43
+ O, 42
44
+ P, 43
45
+ Q, 44
46
+ R, 45
47
+ S, 46
48
+ T, 47
49
+ U, 48
50
+ V, 49
51
+ W, 50
52
+ X, 51
53
+ Y, 52
54
+ Z, 53
55
+ !, 54
56
+ @, 55
57
+ £, 56
58
+ $, 57
59
+ %, 58
60
+ ^, 59
61
+ &, 60
62
+ *, 61
63
+ (, 62
64
+ ), 63
65
+ -, 64
66
+ _, 65
67
+ =, 66
68
+ +, 67
69
+ [, 68
70
+ ], 69
71
+ {, 70
72
+ }, 71
73
+ ;, 72
74
+ :, 73
75
+ ', 74
76
+ ", 75
77
+ \, 76
78
+ |, 77
79
+ ,, 78
80
+ ., 79
81
+ <, 80
82
+ >, 81
83
+ /, 82
84
+ ?, 83
85
+ `, 84
86
+ ~, 85
87
+ §, 86
88
+ ±, 87
89
+ 1, 88
90
+ 2, 89
91
+ 3, 90
92
+ 4, 91
93
+ 5, 92
94
+ 6, 93
95
+ 7, 94
96
+ 8, 95
97
+ 9, 96
98
+ 0, 97
@@ -0,0 +1,98 @@
1
+ character, value
2
+ , m
3
+ a, X
4
+ b, p
5
+ c, M
6
+ d, *
7
+ e, D
8
+ f, 3
9
+ g, £
10
+ h, §
11
+ i, t
12
+ j, Y
13
+ k, y
14
+ l, 7
15
+ m, .
16
+ n, w
17
+ o, !
18
+ p, %
19
+ q, g
20
+ r, A
21
+ s, u
22
+ t, 2
23
+ u, J
24
+ v, 9
25
+ w, _
26
+ x, @
27
+ y, [
28
+ z, L
29
+ A, h
30
+ B, q
31
+ C, 0
32
+ D, G
33
+ E, j
34
+ F, ^
35
+ G, Z
36
+ H, ]
37
+ I, I
38
+ J, |
39
+ K, >
40
+ L, B
41
+ M, c
42
+ N, i
43
+ O, e
44
+ P, ;
45
+ Q, ~
46
+ R, :
47
+ S, P
48
+ T, ±
49
+ U, k
50
+ V, S
51
+ W, &
52
+ X, +
53
+ Y, l
54
+ Z, a
55
+ !,
56
+ @, R
57
+ £, ,
58
+ $, }
59
+ %, n
60
+ ^, z
61
+ &, F
62
+ *, 8
63
+ (, C
64
+ ), -
65
+ -, ?
66
+ _, x
67
+ =, 5
68
+ +, U
69
+ [, K
70
+ ], v
71
+ {, =
72
+ }, <
73
+ ;, 1
74
+ :, d
75
+ ', {
76
+ ", N
77
+ \, O
78
+ |, b
79
+ ,, $
80
+ ., Q
81
+ <, H
82
+ >, (
83
+ /, \
84
+ ?, 4
85
+ `, )
86
+ ~, s
87
+ §, 6
88
+ ±, V
89
+ 1, o
90
+ 2, W
91
+ 3, "
92
+ 4, E
93
+ 5, '
94
+ 6, r
95
+ 7, /
96
+ 8, `
97
+ 9, f
98
+ 0, T
@@ -0,0 +1,134 @@
1
+ require "cipherworld_amitjuly2020/version"
2
+
3
+ module CipherworldAmitjuly2020
4
+ class Error < StandardError; end
5
+ module Cipher
6
+
7
+ class LetterNumber
8
+
9
+ def initialize(char_set: ,key: )
10
+ @char_set = char_set
11
+ @key = key
12
+ end
13
+
14
+ def encrypt(string)
15
+ begin
16
+ # fetching letter and encrypting it
17
+ ciphered = string.chars.map{|x| n = dictionary.fetch(x) + @key}
18
+ rescue KeyError => e
19
+ puts "Unsuitable text for cipher: #{e}"
20
+ end
21
+ # counter reset to 99
22
+ ciphered = ciphered.map{|n|
23
+ if n > 99 and n % 99 == 0
24
+ n = 99
25
+ elsif n > 99
26
+ n %= 99
27
+ else
28
+ n
29
+ end}
30
+ # double digit for each letter encryption
31
+ ciphered.map{ |x| x < 10? "0" + x.to_s : x }.join
32
+ end
33
+
34
+ def decrypt(encryptedtext)
35
+ decrypted = encryptedtext.scan(/../).map{|x|
36
+ n = ((x.to_i)-@key)%99
37
+ decryptdict.fetch(n.to_s)}.join
38
+ end
39
+
40
+ private
41
+
42
+ # obtaining character set
43
+ def text_file
44
+ list = []
45
+ File.open(@char_set).each{|x| list.push(x)}
46
+ list.delete_at(0)
47
+ list
48
+ end
49
+
50
+ # creating dictionary from character set
51
+ def dictionary
52
+ character_set = {}
53
+ text_file.each{|x| character_set[x[0]] = (x[3..4].to_i)}
54
+ character_set
55
+ end
56
+
57
+ def decryptdict
58
+ character_set = {}
59
+ text_file.each.with_index{ |x,i| i < 9? character_set[x[3]] = x[0] :
60
+ character_set[x[3..4]] = x[0] }
61
+ character_set
62
+ end
63
+
64
+ end
65
+
66
+ class LetterLetter < LetterNumber
67
+
68
+ def initialize(char_set: )
69
+ @char_set = char_set
70
+ end
71
+
72
+ def encrypt(string)
73
+ # fetching letter and encrypting it
74
+ #string.chars.each{|x| char_errors}
75
+ begin
76
+ ciphered = string.chars.map{|x| dictionary.fetch(x)}.join
77
+ rescue KeyError => e
78
+ puts "Unsuitable text for cipher: #{e}"
79
+ end
80
+ end
81
+
82
+ def decrypt(encryptedtext)
83
+ #string.chars.each{|x| decrypt_errors}
84
+ begin
85
+ ciphered = string.chars.map{|x| dictionary.fetch(x)}.join
86
+ rescue KeyError => e
87
+ puts "Unsuitable text for cipher: #{e}"
88
+ end
89
+ decrypted = encryptedtext.chars.map{|x| dictionary.key(x)}.join
90
+ end
91
+
92
+ private
93
+
94
+ def dictionary
95
+ character_set = {}
96
+ text_file.each{|x| character_set[x[0]] = x[3]}
97
+ character_set
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
104
+ input_array = ARGV
105
+
106
+ begin
107
+ info = File.read(input_array[2])
108
+ info = info.gsub("\n","")
109
+ rescue StandardError
110
+ puts "No suitable text file for encryption/decryption"
111
+ end
112
+
113
+ char_set1 = "char_sets/character_set1.txt"
114
+ char_set2 = "char_sets/character_set2.txt"
115
+
116
+ if input_array[0] == "ll"
117
+ l = Cipher::LetterLetter.new(char_set: char_set2)
118
+ elsif input_array[0] == "ln"
119
+ l = Cipher::LetterNumber.new(char_set: char_set1, key: input_array[3].to_i)
120
+ else
121
+ raise "Incorrect acronym for cipher method. Expect 'll' or 'ln'"
122
+ end
123
+
124
+ if input_array[1] == "enc"
125
+ l = l.encrypt(info)
126
+ File.open("#{input_array[2]}.enc","w") { |f| f.write(l)}
127
+ elsif input_array[1] == "dec"
128
+ l = l.decrypt(info)
129
+ File.open("#{input_array[2][0..-5]}","w") { |f| f.write(l)}
130
+ else
131
+ raise "Incorrect acronym for encrypt or decrypt. Expect 'enc' or 'dec'"
132
+ end
133
+
134
+ end
@@ -0,0 +1,3 @@
1
+ module CipherworldAmitjuly2020
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cipherworld_amitjuly2020
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amit Tauro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides methods to encrypt and decrypt text files through the command
14
+ line.
15
+ email:
16
+ - tauroamit@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - cipherworld_amitjuly2020.gemspec
33
+ - lib/char_sets/character_set1.txt
34
+ - lib/char_sets/character_set2.txt
35
+ - lib/cipherworld_amitjuly2020.rb
36
+ - lib/cipherworld_amitjuly2020/version.rb
37
+ homepage: https://github.com/amittauro/MyFirstRubyGem
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ allowed_push_host: https://rubygems.org
42
+ homepage_uri: https://github.com/amittauro/MyFirstRubyGem
43
+ source_code_uri: https://github.com/amittauro/MyFirstRubyGem
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.1.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Encryption and decryption methods for text files.
63
+ test_files: []