encrypt-vigen 0.0.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.
- checksums.yaml +7 -0
- data/lib/encryptv.rb +98 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49b238552a1bcfee825df47d5a00d271c6c60e2138f47ced07bf5067b16a9b9e
|
4
|
+
data.tar.gz: 80c3971423468ea4fd7a4d52bfd21f8239d642b4bf67fa49d714c2ff3ff0742a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27f217bc15ffea6cebb4b0c950a64a7f68fb8fca9d87596dbd73bc0847a71ef931f5faf87febe77da14b95ebea9631ea17a8b611526b13638ded0a5c27437b2c
|
7
|
+
data.tar.gz: efc005f4bbccb19640e069af79c76d8c529bfa1d600befc012b7760019fcf8ab2822e4e69217181507b14b1139ed6b00658f30653950e193efcfa07b696a449b
|
data/lib/encryptv.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Archivo encrypt_v/lib/encryptv.rb
|
2
|
+
class EncryptV
|
3
|
+
# Variables privadas de la clase
|
4
|
+
# @available_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".split("")
|
5
|
+
|
6
|
+
# Acceso publico
|
7
|
+
|
8
|
+
# Metodos publicos
|
9
|
+
def encrypt(msg, key)
|
10
|
+
# Metodo para encriptar un mensaje
|
11
|
+
self.algorithm_encrypt_v(msg,key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def decrypt(encrypted_msg, key)
|
15
|
+
# Metodo para desencriptar un mensaje
|
16
|
+
new_key = extend_key(encrypted_msg, key)
|
17
|
+
algorithm_decrypt_v(encrypted_msg,new_key)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Acceso privado
|
21
|
+
protected
|
22
|
+
# Metodos privados
|
23
|
+
|
24
|
+
def index(ch)
|
25
|
+
# Devuelve la ppsicion del caracter en el hash
|
26
|
+
available_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".split("")
|
27
|
+
available_chars.each_with_index { |c,i|
|
28
|
+
if c.eql? ch
|
29
|
+
return i
|
30
|
+
end
|
31
|
+
}
|
32
|
+
return -1
|
33
|
+
end
|
34
|
+
|
35
|
+
def gen_ch_array(len)
|
36
|
+
# Devuelve un array de tamaño 'len' de caracteres 'x'
|
37
|
+
('x'*len).split("")
|
38
|
+
end
|
39
|
+
|
40
|
+
def extend_key(msg, key)
|
41
|
+
# Generar une nueva clave a base del mensage y la clave original
|
42
|
+
msg_len = msg.length
|
43
|
+
new_key = gen_ch_array(msg_len)
|
44
|
+
key_len = key.length
|
45
|
+
j = 0
|
46
|
+
msg.split("").each_with_index{ |c,i|
|
47
|
+
if j.eql? key_len
|
48
|
+
j = 0
|
49
|
+
end
|
50
|
+
new_key[i] = key.split("")[j]
|
51
|
+
j = j + 1
|
52
|
+
}
|
53
|
+
return new_key.join("")
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate(str)
|
57
|
+
# Devuelve verdadero si el str es alfa-numerico
|
58
|
+
chars = ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a
|
59
|
+
str.chars.detect {|ch| !chars.include?(ch)}.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
def algorithm_encrypt_v(msg, key)
|
63
|
+
# Encrypta un mensaje utilizando el algoritmo vigenere
|
64
|
+
msg_len = msg.length
|
65
|
+
key_len = key.length
|
66
|
+
encrypted_msg = gen_ch_array(msg_len)
|
67
|
+
|
68
|
+
new_key = extend_key(msg, key)
|
69
|
+
|
70
|
+
# Encriptacion
|
71
|
+
available_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".split("")
|
72
|
+
msg.split("").each_with_index{ |c,i|
|
73
|
+
if validate(c) || (c.eql? ' ')
|
74
|
+
encrypted_msg[i] = available_chars[((index(msg.split("")[i]) + index(new_key.split("")[i])) % available_chars.length())]
|
75
|
+
else
|
76
|
+
encrypted_msg[i] = msg.split("")[i]
|
77
|
+
end
|
78
|
+
}
|
79
|
+
|
80
|
+
return encrypted_msg.join("")
|
81
|
+
end
|
82
|
+
|
83
|
+
def algorithm_decrypt_v(encrypted_msg, new_key)
|
84
|
+
msg_len = encrypted_msg.length
|
85
|
+
decrypted_msg = gen_ch_array(msg_len)
|
86
|
+
|
87
|
+
#Desencriptacion
|
88
|
+
available_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".split("")
|
89
|
+
encrypted_msg.split("").each_with_index{ |c,i|
|
90
|
+
if validate(c) || (c.eql? ' ')
|
91
|
+
decrypted_msg[i] = available_chars[(((index(encrypted_msg.split("")[i]) - index(new_key.split("")[i])) + available_chars.length()) % available_chars.length())]
|
92
|
+
else
|
93
|
+
decrypted_msg[i] = decrypted_msg.split("")[i]
|
94
|
+
end
|
95
|
+
}
|
96
|
+
return decrypted_msg.join("");
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: encrypt-vigen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Rodriguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Encriptacion de mensajes mediante algoritmo vigenere
|
14
|
+
email:
|
15
|
+
- engineer.jrg@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/encryptv.rb
|
21
|
+
homepage: https://github.com/engineer-jrg/EncryptV.git
|
22
|
+
licenses:
|
23
|
+
- GPL-1.0-only
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Encrypt Vigenere
|
44
|
+
test_files: []
|