accutronic 0.2.0 → 0.2.1

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,113 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ #--
5
+ # Copyright 2014 Luke Spangler
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #++
19
+
20
+ require "abc"
21
+
22
+ # This library contains a module for access
23
+ # to simple substitution cipher "encryption"
24
+ #
25
+ #
26
+ # Author:: Luke Spangler
27
+ # Email:: m27frogy.roblox@gmail.com
28
+
29
+ # Module containing the classes and methods
30
+ # of the library.
31
+ module SubstitutionCipher
32
+ ALPHA_RANGE = 97..122
33
+ # Remove non-alphabetical letters
34
+ # from plaintext (bar spaces and newlines)
35
+ def self.purge_nonalpha(text)
36
+ text = text.dup.downcase
37
+ table = []
38
+ text.split("").each_with_index do |source,index|
39
+ if not SubstitutionCipher::ALPHA_RANGE.include? source.ord and (not source.ord == 10 and not source.ord == 32) then
40
+ table << index
41
+ end
42
+ end
43
+ table.reverse.each do |index|
44
+ text[index] = ""
45
+ end
46
+ return text
47
+ end
48
+
49
+ # "Encrypt" a string via a
50
+ # substitution cipher.
51
+ def self.encrypt(string,offset=3)
52
+ string = self.purge_nonalpha string
53
+ final = ""
54
+ string.split("").each_with_index do |source,index|
55
+ if (not source.ord == 10 and not source.ord == 32) then
56
+ result = source.ord + offset
57
+ if not SubstitutionCipher::ALPHA_RANGE.include? source.ord then
58
+ result -= 25
59
+ end
60
+ else
61
+ result = source.ord
62
+ end
63
+ final << result.chr
64
+ end
65
+ return final
66
+ end
67
+
68
+ # "Decrypt" a string via a
69
+ # substitution cipher.
70
+ def self.decrypt(string,offset=3)
71
+ string = self.purge_nonalpha string
72
+ final = ""
73
+ string.split("").each_with_index do |source,index|
74
+ if (not source.ord == 10 and not source.ord == 32) then
75
+ result = source.ord - offset
76
+ if not SubstitutionCipher::ALPHA_RANGE.include? source.ord then
77
+ result += 25
78
+ end
79
+ else
80
+ result = source.ord
81
+ end
82
+ final << result.chr
83
+ end
84
+ return final
85
+ end
86
+
87
+ # A method to crack (with the users help)
88
+ # a string that has been "encrypted"
89
+ # with SubstitutionCipher#encrypt.
90
+ def self.crack_offset(string)
91
+ first = Time.now
92
+ range = 1..25
93
+ complete = false
94
+ range.to_a.each do |value|
95
+ puts "\n-------------\n\n"
96
+ puts self.decrypt(string,value)
97
+ puts "\n-------------\n\n"
98
+ puts "Valid? |Y N|"
99
+ result = gets.chomp.downcase
100
+ if result == "y" then
101
+ complete = value
102
+ break
103
+ end
104
+ end
105
+ puts "\n-------------\n\n"
106
+ if not complete then
107
+ puts "Crack failed."
108
+ else
109
+ puts "Offset: #{complete}\nTime taken: #{Time.now-first}"
110
+ end
111
+ return complete
112
+ end
113
+ end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
4
  #--
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
4
  #--
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accutronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-24 00:00:00.000000000 Z
12
+ date: 2014-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abc
@@ -63,6 +63,7 @@ files:
63
63
  - lib/accu-window.rb
64
64
  - lib/accu-encrypt.rb
65
65
  - lib/accu-file.rb
66
+ - lib/accu-cipher.rb
66
67
  - LICENSE.txt
67
68
  - bin/accu-encrypt
68
69
  homepage: