doza 0.3
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 +7 -0
- data/lib/doza.rb +96 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 102c6d8646dd44ce2193783fed87f1330308047fafbf80e05c6cf98cc05a7716
|
|
4
|
+
data.tar.gz: 9436435e1f49b6a0b106c4ff67d0350922aa43887258ef0e2e74794cd804c720
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 844ddae1ecfde8b1c2594cbf0f4e3126eff5136f28320e91a44647c463d4b52580c52c0d7b3751ac0acb66610e1d1bd14b5495e306c450578ef489452df7052a
|
|
7
|
+
data.tar.gz: 3443b8261d66abb017a02a1b8683919f004c9737845e9336e050d74703d0ebff4abcf20b22231aa4a4c4708874a97559009cb6edc3fe0620fa80b5577a67b454
|
data/lib/doza.rb
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
class Doza
|
|
2
|
+
attr_reader :intermediate_text, :key
|
|
3
|
+
|
|
4
|
+
def encrypt(input_text, key = nil)
|
|
5
|
+
check_text(input_text)
|
|
6
|
+
@intermediate_text = input_text
|
|
7
|
+
|
|
8
|
+
(key.nil?) ? generate_random_key : @key = key
|
|
9
|
+
check_key(@key)
|
|
10
|
+
|
|
11
|
+
@intermediate_text.reverse!
|
|
12
|
+
compile_codepoints_and_split
|
|
13
|
+
compile_character_assignment
|
|
14
|
+
|
|
15
|
+
{ :key => @key, :text => @intermediate_text }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def decrypt(input_text, key)
|
|
19
|
+
check_text(input_text)
|
|
20
|
+
check_key(key)
|
|
21
|
+
@intermediate_text = input_text
|
|
22
|
+
@key = key
|
|
23
|
+
|
|
24
|
+
decompile_character_assignment
|
|
25
|
+
decompile_codepoints_and_split
|
|
26
|
+
@intermediate_text.reverse!
|
|
27
|
+
|
|
28
|
+
{ :text => @intermediate_text }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def compile_codepoints_and_split
|
|
32
|
+
output_text = "|"
|
|
33
|
+
@intermediate_text.codepoints.each do |dec|
|
|
34
|
+
output_text += dec.to_s + "|"
|
|
35
|
+
end
|
|
36
|
+
@intermediate_text = output_text
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def compile_character_assignment
|
|
40
|
+
split_key = [@key[0..3], @key[4..7], @key[8..11], @key[12..15], @key[16..19], @key[20..23], @key[24..27], @key[28..31], @key[32..35], @key[36..39], @key[40..45]]
|
|
41
|
+
output_text = ""
|
|
42
|
+
@intermediate_text.each_char do |n|
|
|
43
|
+
if is_number?(n)
|
|
44
|
+
output_text += split_key[n.to_i].chars.sample
|
|
45
|
+
else
|
|
46
|
+
output_text += split_key.last.chars.sample
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
@intermediate_text = output_text
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def decompile_codepoints_and_split
|
|
53
|
+
output_text = ""
|
|
54
|
+
intermediate_text = @intermediate_text.split("|").reject(&:empty?)
|
|
55
|
+
intermediate_text.each do |char|
|
|
56
|
+
num = char.to_i
|
|
57
|
+
output_text += [num].pack('U')
|
|
58
|
+
end
|
|
59
|
+
@intermediate_text = output_text
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def decompile_character_assignment
|
|
63
|
+
output_text = ""
|
|
64
|
+
@intermediate_text.chars.each do |char|
|
|
65
|
+
index = @key.chars.find_index(char) / 4
|
|
66
|
+
(index < 10) ? output_text += index.to_s : output_text += "|" # split char
|
|
67
|
+
end
|
|
68
|
+
@intermediate_text = output_text
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def generate_random_key
|
|
74
|
+
key = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST".chars
|
|
75
|
+
@key = key.shuffle.join
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def is_number?(input)
|
|
79
|
+
input.to_f.to_s == input.to_s || input.to_i.to_s == input.to_s
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def check_text(text)
|
|
83
|
+
raise NoValidText.new("Not valid text length") if text.length < 1
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def check_key(key)
|
|
87
|
+
raise NoValidKey.new("Not valid key length") if key.length != 46
|
|
88
|
+
raise NoValidKey.new("Not valid characters in key") if not !!(key =~ /\A[a-zA-Z]+\z/)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class NoValidKey < StandardError
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class NoValidText < StandardError
|
|
96
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: doza
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '0.3'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Domenico Caiazza
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Encrypts and decrypts text and files with the Doza algorithm
|
|
14
|
+
email: caiazza.domenico@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/doza.rb
|
|
20
|
+
homepage: https://rubygems.org/gems/doza
|
|
21
|
+
licenses:
|
|
22
|
+
- CC-BY-NC-ND-4.0
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.2.33
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: doza-0.3
|
|
43
|
+
test_files: []
|