cobreaktws 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,438 @@
1
+ #include<cobreak_openssl.h>
2
+ #define BLOCK_SIZE 64
3
+ #define HASH_SIZE_512 64
4
+ #define HASH_SIZE 32
5
+ #define NUM_ROUNDS 12
6
+
7
+ VALUE mCoBreakOpenSSL;
8
+ VALUE cCoBreakOpenSSLmd4;
9
+ VALUE cCoBreakOpenSSLmd5;
10
+ VALUE cCoBreakOpenSSLhalf_md5;
11
+ VALUE cCoBreakOpenSSLsha1;
12
+ VALUE cCoBreakOpenSSLsha2_224;
13
+ VALUE cCoBreakOpenSSLsha2_256;
14
+ VALUE cCoBreakOpenSSLsha2_384;
15
+ VALUE cCoBreakOpenSSLsha2_512;
16
+ VALUE cCoBreakOpenSSLsha3_224;
17
+ VALUE cCoBreakOpenSSLsha3_256;
18
+ VALUE cCoBreakOpenSSLsha3_384;
19
+ VALUE cCoBreakOpenSSLsha3_512;
20
+ VALUE cCoBreakOpenSSLripemd160;
21
+
22
+
23
+ VALUE ripemd160_hexdigest(VALUE self, VALUE full){
24
+ char *str = RSTRING_PTR(full);
25
+ int n;
26
+ RIPEMD160_CTX c;
27
+ unsigned char digest[65];
28
+ char *out = (char*)malloc(33);
29
+ int length = strlen(str);
30
+
31
+ RIPEMD160_Init(&c);
32
+
33
+ while (length > 0) {
34
+ if (length > 512) {
35
+ RIPEMD160_Update(&c, str, 512);
36
+ } else {
37
+ RIPEMD160_Update(&c, str, length);
38
+ }
39
+ length -= 512;
40
+ str += 512;
41
+ }
42
+
43
+ RIPEMD160_Final(digest, &c);
44
+
45
+ for (n = 0; n < RIPEMD160_DIGEST_LENGTH; ++n) {
46
+ snprintf(&(out[n*2]), RIPEMD160_DIGEST_LENGTH*2, "%02x", (unsigned int)digest[n]);
47
+ }
48
+
49
+ return rb_str_new2(out);
50
+ free(out);
51
+ }
52
+
53
+ VALUE md4_hexdigest(VALUE self, VALUE input) {
54
+ // Convertir el valor Ruby a una cadena C
55
+ char *str = RSTRING_PTR(input);
56
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
57
+ unsigned char digest[MD4_DIGEST_LENGTH]; // MD4 produce un hash de 16 bytes
58
+ char out[33]; // 16 bytes * 2 para hexadecimal + 1 para el terminador
59
+
60
+ // Calcular el hash MD4
61
+ MD4((unsigned char*)str, length, digest);
62
+
63
+ // Convertir el hash a una cadena hexadecimal
64
+ for (int n = 0; n < MD4_DIGEST_LENGTH; ++n) {
65
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
66
+ }
67
+ out[32] = '\0'; // Terminar la cadena
68
+
69
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
70
+ return result;
71
+ }
72
+
73
+ VALUE md5_hexdigest(VALUE self, VALUE input) {
74
+ // Convertir el valor Ruby a una cadena C
75
+ char *str = RSTRING_PTR(input);
76
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
77
+ unsigned char digest[MD5_DIGEST_LENGTH]; // MD5 produce un hash de 16 bytes
78
+ char out[33]; // 16 bytes * 2 para hexadecimal + 1 para el terminador
79
+
80
+ // Calcular el hash MD5
81
+ MD5((unsigned char*)str, length, digest);
82
+
83
+ // Convertir el hash a una cadena hexadecimal
84
+ for (int n = 0; n < MD5_DIGEST_LENGTH; ++n) {
85
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
86
+ }
87
+ out[32] = '\0'; // Terminar la cadena
88
+
89
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
90
+ return result;
91
+ }
92
+
93
+ VALUE half_md5_hexdigest(VALUE self, VALUE input) {
94
+ // Convertir el valor Ruby a una cadena C
95
+ char *str = RSTRING_PTR(input);
96
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
97
+ unsigned char digest[MD5_DIGEST_LENGTH]; // MD5 produce un hash de 16 bytes
98
+ char out[17]; // 8 bytes * 2 para hexadecimal + 1 para el terminador
99
+
100
+ // Calcular el hash MD5
101
+ MD5((unsigned char*)str, length, digest);
102
+
103
+ // Convertir solo los primeros 8 bytes del hash a una cadena hexadecimal
104
+ for (int n = 0; n < 8; ++n) {
105
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
106
+ }
107
+ out[16] = '\0'; // Terminar la cadena
108
+
109
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
110
+ return result;
111
+ }
112
+
113
+ VALUE sha1_hexdigest(VALUE self, VALUE input) {
114
+ // Convertir el valor Ruby a una cadena C
115
+ char *str = RSTRING_PTR(input);
116
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
117
+ unsigned char digest[SHA_DIGEST_LENGTH]; // SHA-1 produce un hash de 20 bytes
118
+ char out[41]; // 20 bytes * 2 para hexadecimal + 1 para el terminador
119
+
120
+ // Calcular el hash SHA-1
121
+ SHA1((unsigned char*)str, length, digest);
122
+
123
+ // Convertir el hash a una cadena hexadecimal
124
+ for (int n = 0; n < SHA_DIGEST_LENGTH; ++n) {
125
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
126
+ }
127
+ out[40] = '\0'; // Terminar la cadena
128
+
129
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
130
+ return result;
131
+ }
132
+
133
+ VALUE sha2_224_hexdigest(VALUE self, VALUE input) {
134
+ // Convertir el valor Ruby a una cadena C
135
+ char *str = RSTRING_PTR(input);
136
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
137
+ unsigned char digest[SHA224_DIGEST_LENGTH]; // SHA-224 produce un hash de 28 bytes
138
+ char out[57]; // 28 bytes * 2 para hexadecimal + 1 para el terminador
139
+
140
+ // Calcular el hash SHA-224
141
+ SHA224((unsigned char*)str, length, digest);
142
+
143
+ // Convertir el hash a una cadena hexadecimal
144
+ for (int n = 0; n < SHA224_DIGEST_LENGTH; ++n) {
145
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
146
+ }
147
+ out[56] = '\0'; // Terminar la cadena
148
+
149
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
150
+ return result;
151
+ }
152
+
153
+ VALUE sha2_256_hexdigest(VALUE self, VALUE input) {
154
+ // Convertir el valor Ruby a una cadena C
155
+ char *str = RSTRING_PTR(input);
156
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
157
+ unsigned char digest[SHA256_DIGEST_LENGTH]; // SHA-256 produce un hash de 32 bytes
158
+ char out[65]; // 32 bytes * 2 para hexadecimal + 1 para el terminador
159
+
160
+ // Calcular el hash SHA-256
161
+ SHA256((unsigned char*)str, length, digest);
162
+
163
+ // Convertir el hash a una cadena hexadecimal
164
+ for (int n = 0; n < SHA256_DIGEST_LENGTH; ++n) {
165
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
166
+ }
167
+ out[64] = '\0'; // Terminar la cadena
168
+
169
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
170
+ return result;
171
+ }
172
+
173
+ VALUE sha2_384_hexdigest(VALUE self, VALUE input) {
174
+ // Convertir el valor Ruby a una cadena C
175
+ char *str = RSTRING_PTR(input);
176
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
177
+ unsigned char digest[SHA384_DIGEST_LENGTH]; // SHA-384 produce un hash de 48 bytes
178
+ char out[97]; // 48 bytes * 2 para hexadecimal + 1 para el terminador
179
+
180
+ // Calcular el hash SHA-384
181
+ SHA384((unsigned char*)str, length, digest);
182
+
183
+ // Convertir el hash a una cadena hexadecimal
184
+ for (int n = 0; n < SHA384_DIGEST_LENGTH; ++n) {
185
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
186
+ }
187
+ out[96] = '\0'; // Terminar la cadena
188
+
189
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
190
+ return result;
191
+ }
192
+
193
+ VALUE sha2_512_hexdigest(VALUE self, VALUE input) {
194
+ // Convertir el valor Ruby a una cadena C
195
+ char *str = RSTRING_PTR(input);
196
+ int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
197
+ unsigned char digest[SHA512_DIGEST_LENGTH]; // SHA-512 produce un hash de 64 bytes
198
+ char out[129]; // 64 bytes * 2 para hexadecimal + 1 para el terminador
199
+
200
+ // Calcular el hash SHA-512
201
+ SHA512((unsigned char*)str, length, digest);
202
+
203
+ // Convertir el hash a una cadena hexadecimal
204
+ for (int n = 0; n < SHA512_DIGEST_LENGTH; ++n) {
205
+ sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
206
+ }
207
+ out[128] = '\0'; // Terminar la cadena
208
+
209
+ VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
210
+ return result;
211
+ }
212
+
213
+ VALUE sha3_224_hexdigest(VALUE self, VALUE input) {
214
+
215
+ // Asegúrate de que el input es una cadena
216
+
217
+ Check_Type(input, T_STRING);
218
+
219
+
220
+ // Crear un contexto para el hash
221
+
222
+ EVP_MD_CTX *ctx = EVP_MD_CTX_new();
223
+
224
+ const EVP_MD *md = EVP_sha3_224();
225
+
226
+
227
+
228
+ // Inicializar el contexto y calcular el hash
229
+
230
+ EVP_DigestInit_ex(ctx, md, NULL);
231
+
232
+ EVP_DigestUpdate(ctx, (unsigned char *)StringValueCStr(input), RSTRING_LEN(input));
233
+
234
+
235
+
236
+ unsigned char output[EVP_MAX_MD_SIZE];
237
+
238
+ unsigned int output_len;
239
+
240
+
241
+ EVP_DigestFinal_ex(ctx, output, &output_len);
242
+
243
+ EVP_MD_CTX_free(ctx);
244
+
245
+
246
+ // Convertir el hash a una cadena hexadecimal
247
+
248
+ VALUE hex_string = rb_str_new("", 0);
249
+
250
+ for (unsigned int i = 0; i < output_len; i++) {
251
+
252
+ rb_str_catf(hex_string, "%02x", output[i]);
253
+
254
+ }
255
+
256
+
257
+ return hex_string;
258
+ }
259
+
260
+ VALUE sha3_256_hexdigest(VALUE self, VALUE input) {
261
+
262
+ // Asegúrate de que el input es una cadena
263
+
264
+ Check_Type(input, T_STRING);
265
+
266
+
267
+ // Crear un contexto para el hash
268
+
269
+ EVP_MD_CTX *ctx = EVP_MD_CTX_new();
270
+
271
+ const EVP_MD *md = EVP_sha3_256();
272
+
273
+
274
+
275
+ // Inicializar el contexto y calcular el hash
276
+
277
+ EVP_DigestInit_ex(ctx, md, NULL);
278
+
279
+ EVP_DigestUpdate(ctx, (unsigned char *)StringValueCStr(input), RSTRING_LEN(input));
280
+
281
+
282
+
283
+ unsigned char output[EVP_MAX_MD_SIZE];
284
+
285
+ unsigned int output_len;
286
+
287
+
288
+ EVP_DigestFinal_ex(ctx, output, &output_len);
289
+
290
+ EVP_MD_CTX_free(ctx);
291
+ // Convertir el hash a una cadena hexadecimal
292
+
293
+ VALUE hex_string = rb_str_new("", 0);
294
+
295
+ for (unsigned int i = 0; i < output_len; i++) {
296
+
297
+ rb_str_catf(hex_string, "%02x", output[i]);
298
+
299
+ }
300
+ return hex_string;
301
+ }
302
+
303
+ VALUE sha3_384_hexdigest(VALUE self, VALUE input) {
304
+
305
+ // Asegúrate de que el input es una cadena
306
+
307
+ Check_Type(input, T_STRING);
308
+
309
+
310
+ // Crear un contexto para el hash
311
+
312
+ EVP_MD_CTX *ctx = EVP_MD_CTX_new();
313
+
314
+ const EVP_MD *md = EVP_sha3_384();
315
+
316
+
317
+
318
+ // Inicializar el contexto y calcular el hash
319
+
320
+ EVP_DigestInit_ex(ctx, md, NULL);
321
+
322
+ EVP_DigestUpdate(ctx, (unsigned char *)StringValueCStr(input), RSTRING_LEN(input));
323
+
324
+
325
+
326
+ unsigned char output[EVP_MAX_MD_SIZE];
327
+
328
+ unsigned int output_len;
329
+
330
+
331
+ EVP_DigestFinal_ex(ctx, output, &output_len);
332
+
333
+ EVP_MD_CTX_free(ctx);
334
+
335
+
336
+ // Convertir el hash a una cadena hexadecimal
337
+
338
+ VALUE hex_string = rb_str_new("", 0);
339
+
340
+ for (unsigned int i = 0; i < output_len; i++) {
341
+
342
+ rb_str_catf(hex_string, "%02x", output[i]);
343
+
344
+ }
345
+ return hex_string;
346
+ }
347
+
348
+ VALUE sha3_512_hexdigest(VALUE self, VALUE input) {
349
+
350
+ // Asegúrate de que el input es una cadena
351
+
352
+ Check_Type(input, T_STRING);
353
+
354
+
355
+ // Crear un contexto para el hash
356
+
357
+ EVP_MD_CTX *ctx = EVP_MD_CTX_new();
358
+
359
+ const EVP_MD *md = EVP_sha3_512();
360
+
361
+
362
+
363
+ // Inicializar el contexto y calcular el hash
364
+
365
+ EVP_DigestInit_ex(ctx, md, NULL);
366
+
367
+ EVP_DigestUpdate(ctx, (unsigned char *)StringValueCStr(input), RSTRING_LEN(input));
368
+
369
+
370
+
371
+ unsigned char output[EVP_MAX_MD_SIZE];
372
+
373
+ unsigned int output_len;
374
+
375
+
376
+ EVP_DigestFinal_ex(ctx, output, &output_len);
377
+
378
+ EVP_MD_CTX_free(ctx);
379
+
380
+
381
+ // Convertir el hash a una cadena hexadecimal
382
+
383
+ VALUE hex_string = rb_str_new("", 0);
384
+
385
+ for (unsigned int i = 0; i < output_len; i++) {
386
+
387
+ rb_str_catf(hex_string, "%02x", output[i]);
388
+
389
+ }
390
+
391
+
392
+ return hex_string;
393
+
394
+ }
395
+
396
+ void init_cobreak_openssl(){
397
+ //Define module OpenSSL in mCoBreak
398
+ mCoBreakOpenSSL = rb_define_module_under(mCoBreak, "OpenSSL");
399
+ //Define Class MD4 encrypt mode
400
+ cCoBreakOpenSSLmd4 = rb_define_class_under(mCoBreakOpenSSL, "MD4", rb_cObject);
401
+ rb_define_singleton_method(cCoBreakOpenSSLmd4, "hexdigest", md4_hexdigest, 1);
402
+ //Define Class MD5 encrypt mode
403
+ cCoBreakOpenSSLmd5 = rb_define_class_under(mCoBreakOpenSSL, "MD5", rb_cObject);
404
+ rb_define_singleton_method(cCoBreakOpenSSLmd5, "hexdigest", md5_hexdigest, 1);
405
+ //Define Class MD5 encrypt mode
406
+ cCoBreakOpenSSLhalf_md5 = rb_define_class_under(mCoBreakOpenSSL, "HALF_MD5", rb_cObject);
407
+ rb_define_singleton_method(cCoBreakOpenSSLhalf_md5, "hexdigest", half_md5_hexdigest, 1);
408
+ //Define Class SHA-1 encrypt mode
409
+ cCoBreakOpenSSLsha1 = rb_define_class_under(mCoBreakOpenSSL, "SHA1", rb_cObject);
410
+ rb_define_singleton_method(cCoBreakOpenSSLsha1, "hexdigest", sha1_hexdigest, 1);
411
+ //Define Class SHA2-224 encrypt mode
412
+ cCoBreakOpenSSLsha2_224 = rb_define_class_under(mCoBreakOpenSSL, "SHA2_224", rb_cObject);
413
+ rb_define_singleton_method(cCoBreakOpenSSLsha2_224, "hexdigest", sha2_224_hexdigest, 1);
414
+ //Define Class SHA2-256 encrypt mode
415
+ cCoBreakOpenSSLsha2_256 = rb_define_class_under(mCoBreakOpenSSL, "SHA2_256", rb_cObject);
416
+ rb_define_singleton_method(cCoBreakOpenSSLsha2_256, "hexdigest", sha2_256_hexdigest, 1);
417
+ //Define Class SHA2-384 encrypt mode
418
+ cCoBreakOpenSSLsha2_384 = rb_define_class_under(mCoBreakOpenSSL, "SHA2_384", rb_cObject);
419
+ rb_define_singleton_method(cCoBreakOpenSSLsha2_384, "hexdigest", sha2_384_hexdigest, 1);
420
+ //Define Class SHA2-512 encrypt mode
421
+ cCoBreakOpenSSLsha2_512 = rb_define_class_under(mCoBreakOpenSSL, "SHA2_512", rb_cObject);
422
+ rb_define_singleton_method(cCoBreakOpenSSLsha2_512, "hexdigest", sha2_512_hexdigest, 1);
423
+ //Define Class SHA3-224 encrypt mode
424
+ cCoBreakOpenSSLsha3_224 = rb_define_class_under(mCoBreakOpenSSL, "SHA3_224", rb_cObject);
425
+ rb_define_singleton_method(cCoBreakOpenSSLsha3_224, "hexdigest", sha3_224_hexdigest, 1);
426
+ //Define Class SHA3-224 encrypt mode
427
+ cCoBreakOpenSSLsha3_256 = rb_define_class_under(mCoBreakOpenSSL, "SHA3_256", rb_cObject);
428
+ rb_define_singleton_method(cCoBreakOpenSSLsha3_256, "hexdigest", sha3_256_hexdigest, 1);
429
+ //Define Class SHA3-224 encrypt mode
430
+ cCoBreakOpenSSLsha3_384 = rb_define_class_under(mCoBreakOpenSSL, "SHA3_384", rb_cObject);
431
+ rb_define_singleton_method(cCoBreakOpenSSLsha3_384, "hexdigest", sha3_384_hexdigest, 1);
432
+ //Define Class SHA3-224 encrypt mode
433
+ cCoBreakOpenSSLsha3_512 = rb_define_class_under(mCoBreakOpenSSL, "SHA3_512", rb_cObject);
434
+ rb_define_singleton_method(cCoBreakOpenSSLsha3_512, "hexdigest", sha3_512_hexdigest, 1);
435
+ //Define Class RIPEMD-160 encrypt mode
436
+ cCoBreakOpenSSLripemd160 = rb_define_class_under(mCoBreakOpenSSL, "RIPEMD_160", rb_cObject);
437
+ rb_define_singleton_method(cCoBreakOpenSSLripemd160, "hexdigest", ripemd160_hexdigest, 1);
438
+ }
@@ -0,0 +1,21 @@
1
+ #ifndef COBREAK_OPENSSL_RUBY
2
+ #define COBREAK_OPENSS_RUBY
3
+
4
+ //include library <cobreak_ruby.h> for project
5
+ #include<cobreak_ruby.h>
6
+
7
+ //definition body for file <header>
8
+ #include<openssl/sha.h>
9
+ //#include<openssl/sha3.h>
10
+ #include<openssl/md4.h>
11
+ #include<openssl/md5.h>
12
+ #include<openssl/ripemd.h>
13
+ #include <openssl/evp.h>
14
+ #include <openssl/err.h>
15
+ //#include<crypto.h>
16
+ //#include<ssl.h>
17
+
18
+ //initialize function
19
+ void init_cobreak_openssl();
20
+
21
+ #endif
@@ -0,0 +1,24 @@
1
+ #ifndef COBREAK_RUBY
2
+ #define COBREAK_RUBY
3
+
4
+ #include<ruby.h>
5
+ #include<string.h>
6
+ #include<stdbool.h>
7
+ #include<stdlib.h>
8
+ #include<stdio.h>
9
+ #include<stdint.h>
10
+
11
+ extern VALUE mCoBreak;
12
+ #if 0
13
+ VALUE mCoBreak = rb_define_module("CoBreak");
14
+ #endif
15
+
16
+
17
+
18
+
19
+ #include<cobreak_openssl.h>
20
+ #include<cobreak_gcrypt.h>
21
+ #include<cobreak_cipher.h>
22
+ //#include<cobreak_exception.h>
23
+ //continue...
24
+ #endif
@@ -0,0 +1,27 @@
1
+ require "mkmf"
2
+
3
+ #Welcome to CoBreak ExtConf
4
+
5
+ abort "Missing library crypto" unless have_library("crypto")
6
+ #if not have_header("openssl/ssl.h") and have_header("nettle/nettle-types.h") and have_library("crypto")
7
+ # abort("missing libreries of openssl / nettle / crypto")
8
+ #end
9
+ if (`gem search sqlite3 --installed` == "true\n")
10
+ #dir of configuration
11
+ dir_config("cobreak")
12
+ # if have_header("cobreak_ruby.h")
13
+ # have_header("string.h")
14
+ # if RUBY_PLATFORM =~ /mswin|darwin/
15
+ # have_header("window.h")
16
+ # end
17
+ create_header
18
+ have_library( 'stdc++' );
19
+ have_library('gcrypt');
20
+ $CFLAGS << " -Wall"
21
+ create_makefile("cobreak/cobreak")
22
+ # else
23
+ # abort("missing header's of CoBreak")
24
+ # end
25
+ else
26
+ abort("missing libreries, use (gem install sqlite3)")
27
+ end
@@ -0,0 +1,10 @@
1
+ module CoBreak
2
+ class Binary
3
+ def self.binary(dato)
4
+ return dato.unpack("B*").join('')
5
+ end
6
+ def self.hexbinary(dato)
7
+ return [dato].pack("B*")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ class CesarCifrado
2
+ def cesar(dato, rotasiones, orientacion = 1)
3
+ cesar = OpenStruct.new
4
+ cesar.cad_rot = []
5
+ alfa_mayus = ('A'..'Z').to_a
6
+ alfa_minus = ('a'..'z').to_a
7
+ alf = 26
8
+ lit_mayus = 65
9
+ lit_minus = 97
10
+ cad_rot = ""
11
+ for letra in dato.chars
12
+ if !letra.match(/^[[:alpha:]]$/)
13
+ cad_rot += letra
14
+ next
15
+ end
16
+ alfabeto = alfa_mayus
17
+ limit = lit_mayus
18
+ if letra == letra.downcase
19
+ alfabeto = alfa_minus
20
+ limit = lit_minus
21
+ end
22
+ var_ascii = letra.ord
23
+ rot_ver = rotasiones * orientacion
24
+ new_pos = (var_ascii - limit + rot_ver) % alf
25
+ cesar.cad_rot << alfabeto[new_pos]
26
+ end
27
+ return cesar.cad_rot.join('')
28
+ end
29
+ end
30
+ Cesar = CesarCifrado.new
@@ -0,0 +1,30 @@
1
+ require 'ascii85'
2
+
3
+ module CoBreak
4
+ class Cifrado
5
+ def self.cipher(mode, dato)
6
+ cipher = OpenStruct.new
7
+ cipher.mode = mode
8
+ cipher.dato = dato
9
+ if (cipher.mode.eql?('base16'))
10
+ cipher.result = CoBreak::Cipher::Base16.encode(dato)
11
+ elsif (cipher.mode.eql?('base32'))
12
+ cipher.result = CoBreak::Cipher::Base32.encode(dato)
13
+ elsif (cipher.mode.eql?('base64'))
14
+ cipher.result = CoBreak::Cipher::Base64.encode(dato)
15
+ elsif (cipher.mode.eql?('ascii85'))
16
+ cipher.result = Ascii85.encode(dato)
17
+ elsif (cipher.mode.eql?('cesar'))
18
+ cipher.result = CoBreak::Cipher::Cesar.encode(dato, ARGV[0].to_i)
19
+ elsif (cipher.mode.eql?('binary'))
20
+ cipher.result = CoBreak::Cipher::Binary.encode(dato)
21
+ end
22
+ unless (cipher.result.nil?) or (cipher.result.eql?(cipher.dato))
23
+ puts "\n\e[1;32m[\e[37m+\e[1;32m]\e[37m Ciphertext: #{cipher.result}"
24
+ puts "\e[1;32m[\e[37m+\e[1;32m]\e[37m Number Rotations: #{ARGV[0]}" if (cipher.mode.eql?('cesar'))
25
+ else
26
+ puts "\e[1;31m[\e[37m+\e[1;31m]\e[37m Not Cipher Text..."
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,77 @@
1
+ #!/bin/env ruby
2
+ module CoBreak
3
+ class Box
4
+ def self.var(options)
5
+ @options = options
6
+ $options = options
7
+ end
8
+ begin
9
+ require 'cobreak/cifrado'
10
+ require 'cobreak/decifrado'
11
+ require 'cobreak/encrypt'
12
+ require 'cobreak/decrypt'
13
+ rescue LoadError => e
14
+ puts e.message
15
+ puts "A file is missing from the repository"
16
+ puts ""
17
+ exit(1)
18
+ end
19
+ #encoding and decoding algoritmhs
20
+ class Cipher
21
+ def self.coding()
22
+ @options = $options
23
+ @options.enc = "" if @options.enc.nil? == true
24
+ @options.dec = "" if @options.dec.nil? == true
25
+ @options.cipher = %w[Base16 Base32 Base64 Ascii85 Binary Cesar]
26
+ if (@options.cipher.include?(@options.enc.capitalize)) or (@options.cipher.include?(@options.dec.capitalize));
27
+ if (File.exists?(@options.algo));
28
+ IO.foreach(@options.algo){|line|
29
+ line.chomp!
30
+ if (@options.cipher?(@options.enc.capitalize))
31
+ CoBreak::Cifrado.cipher(line.to_s)
32
+ end
33
+ if (@options.cipher.include?(@options.dec.capitalize))
34
+ CoBreak::Decifrado.cipher(line.to_s)
35
+ end
36
+ }
37
+ else
38
+ if (@options.cipher.include?(@options.enc.capitalize))
39
+ CoBreak::Cifrado::cipher(@options.enc, @options.algo.to_s)
40
+ end
41
+ if (@options.cipher.include?(@options.dec.capitalize))
42
+ CoBreak::Decifrado::cipher(@options.dec,@options.algo.to_s)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ class Cryptgraphy
49
+ def self.crypt()
50
+ @options = $options
51
+ @options.encrypt = "" if @options.encrypt.nil? == true
52
+ @options.decrypt = "" if @options.decrypt.nil? == true
53
+ show = OpenStruct.new
54
+ show.crypt = %w[MD4 MD5 HALF-MD5 SHA1 SHA2-224 SHA2-256 SHA2-384 SHA2-512 SHA3-224 SHA3-256 SHA3-384 SHA3-512 RIPEMD-160 TIGER-160 DOUBLE-SHA1 BLAKE2S-128 BLAKE2S-160 BLAKE2B-160 BLAKE2S-224 BLAKE2S-256 BLAKE2B-256 BLAKE2B-384 BLAKE2B-512 WHIRLPOOL GOST-STREEBOG-256 GOST-STREEBOG-512 SHAKE-128]
55
+ if (show.crypt.include?(@options.encrypt.upcase)) or (show.crypt.include?(@options.decrypt.upcase));
56
+ if (File.exists?(@options.algo));
57
+ IO.foreach(@options.algo){|line|
58
+ line.chomp!
59
+ EnCrypt::show(@options.encrypt, line) if (show.crypt.include?(@options.encrypt.upcase))
60
+ DeCrypt::show(@options.decrypt, line) if (show.crypt.include?(@options.decrypt.upcase))
61
+ }
62
+ else
63
+ if (show.crypt.include?(@options.encrypt.upcase))
64
+ EnCrypt::show(@options.encrypt, @options.algo)
65
+ end
66
+ if (show.crypt.include?(@options.decrypt.upcase))
67
+ DeCrypt::show(@options.decrypt.upcase, @options.algo)
68
+ #DeCrypt::show(@options.decrypt, @options.algo)
69
+ end
70
+ end
71
+ else
72
+ abort "\e[31m[\e[37m✘\e[31m]\e[37m Invalid Hash Format"
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
File without changes
@@ -0,0 +1,30 @@
1
+ require 'ascii85'
2
+
3
+ module CoBreak
4
+ class Decifrado
5
+ def self.cipher(mode, dato)
6
+ decipher = OpenStruct.new
7
+ decipher.mode = mode
8
+ decipher.dato = dato
9
+ if (decipher.mode.eql?('base16'))
10
+ decipher.result = CoBreak::Cipher::Base16.decode(decipher.dato)
11
+ elsif (decipher.mode.eql?('base32'))
12
+ decipher.result = CoBreak::Cipher::Base32.decode(decipher.dato)
13
+ elsif (decipher.mode.eql?('base64'))
14
+ decipher.result = CoBreak::Cipher::Base64.decode(decipher.dato)
15
+ elsif (decipher.mode.eql?('ascii85'))
16
+ decipher.result = Ascii85.decode(decipher.dato)
17
+ elsif (decipher.mode.eql?('cesar'))
18
+ decipher.result = CoBreak::Cipher::Cesar.decode(decipher.dato, ARGV[0].to_i)
19
+ elsif (decipher.mode.eql?('binary'))
20
+ decipher.result = CoBreak::Cipher::Binary.decode(decipher.dato)
21
+ end
22
+ unless (decipher.result.nil?) or (decipher.result.eql?(decipher.dato))
23
+ puts "\n\e[1;32m[\e[37m+\e[1;32m]\e[37m DecipherText: #{decipher.result}"
24
+ puts "\e[1;32m[\e[37m+\e[1;32m]\e[37m Number Rotations: #{ARGV[0]}" if (decipher.mode.eql?('cesar'))
25
+ else
26
+ puts "\e[1;31m[\e[37m+\e[1;31m]\e[37m Not Cipher Text..."
27
+ end
28
+ end
29
+ end
30
+ end