cobreaktws 1.0.4
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/.vscode/settings.json +10 -0
- data/Gemfile +18 -0
- data/README.md +72 -0
- data/bin/cbrdb +95 -0
- data/bin/cobreak +11 -0
- data/cobreak.gemspec +28 -0
- data/ext/cobreak/cobreak.c +17 -0
- data/ext/cobreak/cobreak_cipher.c +341 -0
- data/ext/cobreak/cobreak_cipher.h +10 -0
- data/ext/cobreak/cobreak_gcrypt.c +556 -0
- data/ext/cobreak/cobreak_gcrypt.h +14 -0
- data/ext/cobreak/cobreak_openmp.c +9 -0
- data/ext/cobreak/cobreak_openmp.h +14 -0
- data/ext/cobreak/cobreak_openssl.c +438 -0
- data/ext/cobreak/cobreak_openssl.h +21 -0
- data/ext/cobreak/cobreak_ruby.h +24 -0
- data/ext/cobreak/extconf.rb +27 -0
- data/lib/cobreak/binary.rb +10 -0
- data/lib/cobreak/cesar.rb +30 -0
- data/lib/cobreak/cifrado.rb +30 -0
- data/lib/cobreak/cobreak_opt.rb +77 -0
- data/lib/cobreak/config/database.db +0 -0
- data/lib/cobreak/decifrado.rb +30 -0
- data/lib/cobreak/decrypt.rb +98 -0
- data/lib/cobreak/details.rb +19 -0
- data/lib/cobreak/encrypt.rb +114 -0
- data/lib/cobreak/force.rb +226 -0
- data/lib/cobreak/force_brute.rb +62 -0
- data/lib/cobreak/force_chars.rb +54 -0
- data/lib/cobreak/function_db.rb +26 -0
- data/lib/cobreak/function_hash.rb +28 -0
- data/lib/cobreak/hash/hash.db +1 -0
- data/lib/cobreak/info_author.rb +20 -0
- data/lib/cobreak/list_all.rb +41 -0
- data/lib/cobreak/optionpr.rb +148 -0
- data/lib/cobreak/run.rb +9 -0
- data/lib/cobreak/version.rb +5 -0
- data/lib/cobreak.rb +4 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a1000df1c655580f07fc0b8d0e552472d1bf8ed61237f1586f61db496dd1e39
|
4
|
+
data.tar.gz: 6a39de6bfbcac26983322fa42ec2bc5ec6fbe1b9f7c9d9be0fed48dcf287158c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df08b6a634312072473b69ee522a3af98bc9a4623370ef7d79ad766984eca1e33bf77a2a170f0d1c8edc90dbce94b4d454a2c70638130dbe5201cb2ea6619000
|
7
|
+
data.tar.gz: 2dbcbd15ca642b8309a5a07a5a1c42fd5c5767c3184c3e9df48d8ddd9c8b47e093c40ea974246472cce221fff4c121b358d13bc5c98fee5d54227b555b4e75ae
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#source 'https://rubygems.org'
|
2
|
+
source 'http://127.0.0.1:9292'
|
3
|
+
gem "cobreak"
|
4
|
+
=begin
|
5
|
+
group :code do
|
6
|
+
gem 'base16'
|
7
|
+
gem 'base32'
|
8
|
+
gem 'base64'
|
9
|
+
gem 'Ascii85'
|
10
|
+
end
|
11
|
+
group :crypt do
|
12
|
+
gem 'openssl'
|
13
|
+
end
|
14
|
+
group :database do
|
15
|
+
gem 'sqlite3'
|
16
|
+
gem 'sequel'
|
17
|
+
end
|
18
|
+
=end
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# CoBreak
|
2
|
+
|
3
|
+
[`CoBreak.com`](https://github.com/BreakingTWS/CoBreak.git)
|
4
|
+
|
5
|
+
This script was made by [`Breaker`](https://github.com/BreakingTWS/CoBreak.git)
|
6
|
+
|
7
|
+
CoBreak is a password security audit and recovery tool available for many operating systems. CoBreak supports various types of cipher and hashing for the purpose of facilitating data encryption or other
|
8
|
+
|
9
|
+
# GitHub Stats
|
10
|
+
|
11
|
+

|
12
|
+
|
13
|
+
<h1> Installation</h2>
|
14
|
+
|
15
|
+
<h3> Cipher</h3>
|
16
|
+
|
17
|
+
- Base64
|
18
|
+
- Base32
|
19
|
+
- Base16
|
20
|
+
- Ascii85
|
21
|
+
- Cesar
|
22
|
+
- Binaries
|
23
|
+
|
24
|
+
<h3> Raw-Hash</h3>
|
25
|
+
|
26
|
+
- MD4
|
27
|
+
- MD5
|
28
|
+
- Half-MD5
|
29
|
+
- SHA-1
|
30
|
+
- Double-SHA1
|
31
|
+
- SHA2-224
|
32
|
+
- SHA2-256
|
33
|
+
- SHA2-384
|
34
|
+
- SHA2-512
|
35
|
+
- SHA3-224
|
36
|
+
- SHA3-256
|
37
|
+
- SHA3-384
|
38
|
+
- SHA3-512
|
39
|
+
- Ripemd-160
|
40
|
+
- Tiger-160
|
41
|
+
- Blake2s-128
|
42
|
+
- Blake2s-160
|
43
|
+
- Blake2s-256
|
44
|
+
- Blake2b-160
|
45
|
+
- Blake2b-256
|
46
|
+
- Blake2b-384
|
47
|
+
- Blake2b-512
|
48
|
+
- GOST R 34.11-2012 (Streebog) 256-bit, big-endian
|
49
|
+
- GOST R 34.11-2012 (Streebog) 512-bit, big-endian
|
50
|
+
|
51
|
+
<h1> Setup</h3>
|
52
|
+
---
|
53
|
+
<h2>Execute in your terminal for build ruby gem and installation:</h2>
|
54
|
+
|
55
|
+
<h3>Build ruby gem:</h3>
|
56
|
+
|
57
|
+
> $ **gem build cobreak.gemspec**
|
58
|
+
|
59
|
+
<h3>And after install ruby gem:</h3>
|
60
|
+
|
61
|
+
> $ **sudo gem install ./cobreak-1.0.4.gem**
|
62
|
+
|
63
|
+
---
|
64
|
+
# Version
|
65
|
+
## CoBreak
|
66
|
+
|
67
|
+

|
68
|
+
|
69
|
+
# License
|
70
|
+
|
71
|
+
This project is licensed under the (GNU GENERAL PUBLIC LICENSE) - see the [LICENSE](LICENSE) file for details
|
72
|
+
# CoBreak
|
data/bin/cbrdb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
require 'ostruct'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'cobreak/version'
|
5
|
+
options = OpenStruct.new
|
6
|
+
ARGV.each {|opt|
|
7
|
+
path_hash = File.join(Gem.path[1], "gems","cobreak-#{CoBreak.version}" , "lib", "cobreak", "hash", "hash.db")
|
8
|
+
path_chr = File.join(Gem.path[1], "gems","cobreak-#{CoBreak.version}" , "lib", "cobreak", "show")
|
9
|
+
path_bool = File.join(Gem.path[1], "gems","cobreak-#{CoBreak.version}" , "lib", "cobreak", "config", "database.db")
|
10
|
+
#dat = ['md4', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'ripemd160']
|
11
|
+
dat = %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]
|
12
|
+
case opt
|
13
|
+
when 'start'
|
14
|
+
begin
|
15
|
+
File.open(path_bool, mode: 'w'){|line|
|
16
|
+
line.write 'true'
|
17
|
+
}
|
18
|
+
puts "\e[1;32m[\e[1;37m+\e[1;32m]\e[1;37m The Database was activated"
|
19
|
+
rescue Errno::EACCES
|
20
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m Access Denied"
|
21
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m root privileges needed"
|
22
|
+
end
|
23
|
+
when 'stop'
|
24
|
+
begin
|
25
|
+
File.open(path_bool, mode: 'w'){|line|
|
26
|
+
line.puts false
|
27
|
+
}
|
28
|
+
puts "\e[1;33m[i]\e[37m Database already stopped"
|
29
|
+
rescue Errno::EACCES
|
30
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m Access Denied"
|
31
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m root privileges needed"
|
32
|
+
end
|
33
|
+
when 'reinit'
|
34
|
+
begin
|
35
|
+
File.foreach(path_bool){|line|
|
36
|
+
line.chomp!
|
37
|
+
if (line == 'false')
|
38
|
+
abort "\e[1;32m[\e[1;37m+\e[1;32m]\e[1;37m Database Not Started"
|
39
|
+
end
|
40
|
+
}
|
41
|
+
File.open(path_hash, mode: 'w'){|line|
|
42
|
+
line.puts nil
|
43
|
+
}
|
44
|
+
for dbreinit in dat
|
45
|
+
File.open(path_chr + "/#{dbreinit}.db", mode: 'w'){|line|
|
46
|
+
line.puts nil
|
47
|
+
}
|
48
|
+
end
|
49
|
+
puts "\e[1;32m[\e[1;37m+\e[1;32m]\e[1;37m Reinitializing The Database"
|
50
|
+
rescue Errno::EACCES
|
51
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m Access Denied"
|
52
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m root privileges needed"
|
53
|
+
end
|
54
|
+
when 'delete'
|
55
|
+
begin
|
56
|
+
for dbdelete in dat
|
57
|
+
FileUtils.rm(path_chr + "/#{dbdelete}.db")
|
58
|
+
end
|
59
|
+
FileUtils.rm(path_hash)
|
60
|
+
File.open(path_bool, mode: 'w'){|line|
|
61
|
+
line.puts false
|
62
|
+
}
|
63
|
+
puts "\e[1;32m[\e[1;37m+\e[1;32m]\e[1;37m Database Deleted Successfully"
|
64
|
+
rescue Errno::ENOENT
|
65
|
+
puts "\e[1;32m[\e[1;37m+\e[1;32m]\e[1;37m Database Deleted Successfully"
|
66
|
+
rescue Errno::EACCES
|
67
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m Access Denied"
|
68
|
+
puts "\e[1;31m[\e[1;37m✘\e[1;31m]\e[1;37m root privileges needed"
|
69
|
+
end
|
70
|
+
when 'status'
|
71
|
+
puts "\e[37mCoBreak Database Status"
|
72
|
+
File.foreach(path_bool){|line|
|
73
|
+
line.chomp!
|
74
|
+
if (line.eql?('true'))
|
75
|
+
puts "\e[1;32m[\e[1;37m+\e[1;32m]\e[1;37m The Database Is Activated"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
}
|
79
|
+
if true
|
80
|
+
puts "\e[1;33m[i]\e[1;37m The Database Is Deactivated"
|
81
|
+
end
|
82
|
+
when 'help'
|
83
|
+
puts "Manage the CoBreak database"
|
84
|
+
puts
|
85
|
+
puts "Examples: cbrdb start"
|
86
|
+
puts
|
87
|
+
puts "cbrdb start # start the database"
|
88
|
+
puts "cbrdb stop # stop the database"
|
89
|
+
puts "cbrdb reinit # delete and reinitialize the database"
|
90
|
+
puts "cbrdb delete # delete database and stop using it"
|
91
|
+
puts "cbrdb status # check database status"
|
92
|
+
else
|
93
|
+
puts "parameter not found, run cbrdb help"
|
94
|
+
end
|
95
|
+
}
|
data/bin/cobreak
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
require 'ostruct'
|
3
|
+
require 'optparse'
|
4
|
+
require 'cobreak/run'
|
5
|
+
options = OpenStruct.new
|
6
|
+
begin
|
7
|
+
CoBreakOPT::Runner.runner(options)
|
8
|
+
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => error
|
9
|
+
puts error.message
|
10
|
+
exit(1)
|
11
|
+
end
|
data/cobreak.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |info|
|
2
|
+
info.name = 'cobreaktws'
|
3
|
+
info.version = '1.0.4'
|
4
|
+
info.executables << "cobreak"
|
5
|
+
info.executables << "cbrdb"
|
6
|
+
info.description = "The CoBreak script is an cipher and cryptography tool"
|
7
|
+
info.add_development_dependency "bundler", "~> 1.5"
|
8
|
+
info.add_development_dependency "openssl", "~> 2.2.0"
|
9
|
+
info.add_development_dependency "sequel", "~> 5.44.0"
|
10
|
+
info.add_development_dependency "sqlite3", '~> 1.4', '>= 1.4.0'
|
11
|
+
# info.add_runtime_dependency "sequel", '~> 2.0', '>= 2.0.0'
|
12
|
+
info.add_runtime_dependency "sqlite3", '~> 1.4', '>= 1.4.0'
|
13
|
+
info.add_runtime_dependency "Ascii85", '~> 1.0', '>= 1.0.0'
|
14
|
+
# info.add_runtime_dependency "ruby_figlet", "=> 0"
|
15
|
+
info.authors = ["BreakerTW"]
|
16
|
+
info.email = 'breaker@gmail.com'
|
17
|
+
info.summary = "Force Brute, Cipher, Cryptography"
|
18
|
+
|
19
|
+
info.extensions = %w[ext/cobreak/extconf.rb]
|
20
|
+
|
21
|
+
info.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(/^.gitignore/)
|
23
|
+
end
|
24
|
+
|
25
|
+
info.homepage = 'https://github.com/BreakingTWS/CoBreak'
|
26
|
+
info.license = 'MIT'
|
27
|
+
info.post_install_message = "thanks for installing my gem"
|
28
|
+
end
|
@@ -0,0 +1,341 @@
|
|
1
|
+
#include<cobreak_cipher.h>
|
2
|
+
|
3
|
+
VALUE mCoBreakCipher;
|
4
|
+
VALUE cCoBreakBase16;
|
5
|
+
VALUE cCoBreakBase32;
|
6
|
+
VALUE cCoBreakBase64;
|
7
|
+
VALUE cCoBreakCesar;
|
8
|
+
VALUE cCoBreakBinary;
|
9
|
+
|
10
|
+
char b32[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
11
|
+
char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
12
|
+
|
13
|
+
//Base16
|
14
|
+
void decodeblock16(const char bl[], char *blstr, size_t length) {
|
15
|
+
for (size_t i = 0; i < length / 2; i++) {
|
16
|
+
int byte = 0;
|
17
|
+
if (sscanf(bl + (i * 2), "%2x", &byte) != 1) {
|
18
|
+
// Manejar error: entrada hex inválida
|
19
|
+
rb_raise(rb_eArgError, "Invalid hex input");
|
20
|
+
return; // Esto no se alcanzará, pero es una buena práctica
|
21
|
+
}
|
22
|
+
blstr[i] = (unsigned char)byte;
|
23
|
+
}
|
24
|
+
blstr[length / 2] = '\0'; // Terminar correctamente la cadena
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE b16_decode(VALUE self, VALUE full) {
|
28
|
+
char *myb16 = RSTRING_PTR(full);
|
29
|
+
char strb16[1024];
|
30
|
+
size_t length = strlen(myb16);
|
31
|
+
|
32
|
+
// Validar longitud
|
33
|
+
if (length % 2 != 0) {
|
34
|
+
rb_raise(rb_eArgError, "Hex string must have an even length");
|
35
|
+
}
|
36
|
+
|
37
|
+
// Decodificación
|
38
|
+
decodeblock16(myb16, strb16, length);
|
39
|
+
return rb_str_new2(strb16);
|
40
|
+
}
|
41
|
+
|
42
|
+
void encodeblock16(const char bl[], size_t length, char b16str[]) {
|
43
|
+
const char *hexDigits = "0123456789ABCDEF";
|
44
|
+
for (size_t i = 0; i < length; i++) {
|
45
|
+
b16str[i * 2] = hexDigits[(bl[i] >> 4) & 0x0F]; // Primer dígito
|
46
|
+
b16str[i * 2 + 1] = hexDigits[bl[i] & 0x0F]; // Segundo dígito
|
47
|
+
}
|
48
|
+
b16str[length * 2] = '\0'; // Agregar el terminador de cadena
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE b16_encode(VALUE self, VALUE full) {
|
52
|
+
char *strb16 = RSTRING_PTR(full);
|
53
|
+
char myb16[1024 * 2 + 1]; // Buffer para la codificación
|
54
|
+
size_t length = strlen(strb16);
|
55
|
+
|
56
|
+
// Codificación
|
57
|
+
encodeblock16(strb16, length, myb16);
|
58
|
+
return rb_str_new2(myb16);
|
59
|
+
}
|
60
|
+
|
61
|
+
//Base32
|
62
|
+
int decodeblock32(const char bl[], char *blstr){
|
63
|
+
int buffer = 0;
|
64
|
+
int bits_left = 0;
|
65
|
+
size_t output_length = 0;
|
66
|
+
|
67
|
+
for (size_t i = 0; i < strlen(bl); i++) {
|
68
|
+
if (bl[i] == '=') {
|
69
|
+
break; // Fin del mensaje
|
70
|
+
}
|
71
|
+
|
72
|
+
int value = strchr(b32, bl[i]) - b32;
|
73
|
+
if (value < 0 || value >= 32) {
|
74
|
+
break; // Carácter inválido
|
75
|
+
}
|
76
|
+
|
77
|
+
buffer = (buffer << 5) | value;
|
78
|
+
bits_left += 5;
|
79
|
+
|
80
|
+
if (bits_left >= 8) {
|
81
|
+
blstr[output_length++] = (buffer >> (bits_left - 8)) & 0xFF;
|
82
|
+
bits_left -= 8;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return output_length;
|
86
|
+
}
|
87
|
+
|
88
|
+
VALUE b32_decode(VALUE self, VALUE full) {
|
89
|
+
char *myb32 = RSTRING_PTR(full);
|
90
|
+
char strb32[1024] = "";
|
91
|
+
char *clrdst = strb32;
|
92
|
+
|
93
|
+
// Decodificar
|
94
|
+
int decoded_length = decodeblock32(myb32, clrdst);
|
95
|
+
clrdst[decoded_length] = '\0'; // Asegurar que la cadena esté terminada
|
96
|
+
|
97
|
+
return rb_str_new2(strb32);
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
void encodeblock32(const char bl[], int len, char b32str[]){
|
102
|
+
int buffer = 0;
|
103
|
+
int bits_left = 0;
|
104
|
+
size_t output_length = 0;
|
105
|
+
|
106
|
+
for (size_t i = 0; i < len; i++) {
|
107
|
+
buffer = (buffer << 8) | bl[i];
|
108
|
+
bits_left += 8;
|
109
|
+
|
110
|
+
while (bits_left >= 5) {
|
111
|
+
b32str[output_length++] = b32[(buffer >> (bits_left - 5)) & 0x1F];
|
112
|
+
bits_left -= 5;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
if (bits_left > 0) {
|
117
|
+
b32str[output_length++] = b32[(buffer << (5 - bits_left)) & 0x1F];
|
118
|
+
}
|
119
|
+
|
120
|
+
// Añadir padding
|
121
|
+
while (output_length % 8 != 0) {
|
122
|
+
b32str[output_length++] = '=';
|
123
|
+
}
|
124
|
+
|
125
|
+
b32str[output_length] = '\0';
|
126
|
+
}
|
127
|
+
|
128
|
+
VALUE b32_encode(VALUE self, VALUE full) {
|
129
|
+
char *strb32 = RSTRING_PTR(full);
|
130
|
+
char myb32[1024] = "";
|
131
|
+
char *clrdst = myb32;
|
132
|
+
|
133
|
+
encodeblock32(strb32, strlen(strb32), clrdst);
|
134
|
+
|
135
|
+
return rb_str_new2(myb32);
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
//Base64
|
140
|
+
void decodeblock64(unsigned char in[], char *clrstr) {
|
141
|
+
unsigned char out[4];
|
142
|
+
out[0] = in[0] << 2 | in[1] >> 4;
|
143
|
+
out[1] = in[1] << 4 | in[2] >> 2;
|
144
|
+
out[2] = in[2] << 6 | in[3] >> 0;
|
145
|
+
out[3] = '\0';
|
146
|
+
strncat(clrstr, out, sizeof(out));
|
147
|
+
}
|
148
|
+
|
149
|
+
VALUE b64_decode(VALUE self, VALUE full){
|
150
|
+
// check_Type(full, T_STRING);
|
151
|
+
int c, phase, i;
|
152
|
+
unsigned char in[4];
|
153
|
+
char *p;
|
154
|
+
|
155
|
+
char *myb64 = RSTRING_PTR(full);
|
156
|
+
char strb64[1024] = "";
|
157
|
+
char *clrdst = strb64;
|
158
|
+
clrdst[0] = '\0';
|
159
|
+
phase = 0; i=0;
|
160
|
+
while(myb64[i]){
|
161
|
+
c = (int) myb64[i];
|
162
|
+
if(c == '='){
|
163
|
+
decodeblock64(in, clrdst);
|
164
|
+
break;
|
165
|
+
}
|
166
|
+
p = strchr(b64, c);
|
167
|
+
if(p){
|
168
|
+
in[phase] = p - b64;
|
169
|
+
phase = (phase + 1) % 4;
|
170
|
+
if(phase == 0){
|
171
|
+
decodeblock64(in, clrdst);
|
172
|
+
in[0]=in[1]=in[2]=in[3]=0;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
i++;
|
176
|
+
}
|
177
|
+
return rb_str_new2(strb64);
|
178
|
+
}
|
179
|
+
|
180
|
+
void encodeblock64(unsigned char bl[], char b64str[], int len){
|
181
|
+
unsigned char out[5];
|
182
|
+
out[0] = b64[ bl[0] >> 2 ];
|
183
|
+
out[1] = b64[ ((bl[0] & 0x03) << 4) | ((bl[1] & 0xf0) >> 4) ];
|
184
|
+
out[2] = (unsigned char) (len > 1 ? b64[ ((bl[1] & 0x0f) << 2) | ((bl[2] & 0xc0) >> 6) ] : '=');
|
185
|
+
out[3] = (unsigned char) (len > 2 ? b64[ bl[2] & 0x3f ] : '=');
|
186
|
+
out[4] = '\0';
|
187
|
+
strncat(b64str, out, sizeof(out));
|
188
|
+
}
|
189
|
+
|
190
|
+
VALUE b64_encode(VALUE self, VALUE full){
|
191
|
+
// check_Type(full, T_STRING);
|
192
|
+
unsigned char in[3];
|
193
|
+
int i, len = 0;
|
194
|
+
int j = 0;
|
195
|
+
//char b64dst[1024];
|
196
|
+
char *strb64 = RSTRING_PTR(full);
|
197
|
+
char myb64[1024] = "";
|
198
|
+
char *b64dst = myb64;
|
199
|
+
b64dst[0] = '\0';
|
200
|
+
while(strb64[j]){
|
201
|
+
len = 0;
|
202
|
+
for(i=0; i<3; i++){
|
203
|
+
in[i] = (unsigned char) strb64[j];
|
204
|
+
if(strb64[j]) {
|
205
|
+
len++; j++;
|
206
|
+
}
|
207
|
+
else in[i] = 0;
|
208
|
+
}
|
209
|
+
if(len){
|
210
|
+
encodeblock64(in, b64dst, len);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
return rb_str_new2(b64dst);
|
214
|
+
}
|
215
|
+
|
216
|
+
//Define Cesar
|
217
|
+
void encodeblock_cesar(const char *input, char *output, int shift){
|
218
|
+
for (size_t i = 0; i < strlen(input); i++) {
|
219
|
+
char c = input[i];
|
220
|
+
|
221
|
+
if (c >= 'A' && c <= 'Z') {
|
222
|
+
output[i] = (c - 'A' + shift) % 26 + 'A';
|
223
|
+
} else if (c >= 'a' && c <= 'z') {
|
224
|
+
output[i] = (c - 'a' + shift) % 26 + 'a';
|
225
|
+
} else {
|
226
|
+
output[i] = c;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
output[strlen(input)] = '\0';
|
230
|
+
}
|
231
|
+
|
232
|
+
|
233
|
+
void decodeblock_cesar(const char *input, char *output, int shift){
|
234
|
+
|
235
|
+
encodeblock_cesar(input, output, 26 - (shift % 26));
|
236
|
+
}
|
237
|
+
|
238
|
+
VALUE cesar_encode(VALUE self, VALUE str, VALUE shift) {
|
239
|
+
char *input = RSTRING_PTR(str);
|
240
|
+
char output[1024]; // Buffer para la salida
|
241
|
+
int shift_value = NUM2INT(shift);
|
242
|
+
|
243
|
+
|
244
|
+
encodeblock_cesar(input, output, shift_value);
|
245
|
+
return rb_str_new2(output);
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
VALUE cesar_decode(VALUE self, VALUE str, VALUE shift) {
|
250
|
+
char *input = RSTRING_PTR(str);
|
251
|
+
char output[1024]; // Buffer para la salida
|
252
|
+
int shift_value = NUM2INT(shift);
|
253
|
+
|
254
|
+
|
255
|
+
decodeblock_cesar(input, output, shift_value);
|
256
|
+
return rb_str_new2(output);
|
257
|
+
}
|
258
|
+
|
259
|
+
//Define Binary
|
260
|
+
void encodeblock_binary(const char bl[], char *blstr, size_t length) {
|
261
|
+
for (size_t i = 0; i < length; i++) {
|
262
|
+
for (int j = 7; j >= 0; j--) {
|
263
|
+
blstr[i * 8 + (7 - j)] = ((bl[i] >> j) & 1) ? '1' : '0';
|
264
|
+
}
|
265
|
+
}
|
266
|
+
blstr[length * 8] = '\0';
|
267
|
+
}
|
268
|
+
|
269
|
+
void decodeblock_binary(const char bl[], char *blstr, size_t length) {
|
270
|
+
for (size_t i = 0; i < length / 8; i++) {
|
271
|
+
char byte = 0;
|
272
|
+
for (int j = 0; j < 8; j++) {
|
273
|
+
byte = (byte << 1) | (bl[i * 8 + j] - '0');
|
274
|
+
}
|
275
|
+
blstr[i] = byte;
|
276
|
+
}
|
277
|
+
blstr[length / 8] = '\0';
|
278
|
+
}
|
279
|
+
|
280
|
+
VALUE binary_encode(VALUE self, VALUE full) {
|
281
|
+
char *strb = RSTRING_PTR(full);
|
282
|
+
char mybinary[1024 * 8 + 1];
|
283
|
+
size_t length = strlen(strb);
|
284
|
+
|
285
|
+
encodeblock_binary(strb, mybinary, length);
|
286
|
+
return rb_str_new2(mybinary);
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
VALUE binary_decode(VALUE self, VALUE full) {
|
291
|
+
char *mybinary = RSTRING_PTR(full);
|
292
|
+
char strb[1024];
|
293
|
+
size_t length = strlen(mybinary);
|
294
|
+
|
295
|
+
if (length % 8 != 0) {
|
296
|
+
rb_raise(rb_eArgError, "Binary string must have a length that is a multiple of 8");
|
297
|
+
}
|
298
|
+
|
299
|
+
decodeblock_binary(mybinary, strb, length);
|
300
|
+
return rb_str_new2(strb);
|
301
|
+
}
|
302
|
+
|
303
|
+
void init_cobreak_cipher() {
|
304
|
+
//Define module Cipher in mCoBreak
|
305
|
+
mCoBreakCipher = rb_define_module_under(mCoBreak, "Cipher");
|
306
|
+
|
307
|
+
//Define class Base16 in module mCoBreakCipher
|
308
|
+
cCoBreakBase16 = rb_define_class_under(mCoBreakCipher, "Base16", rb_cObject);
|
309
|
+
|
310
|
+
//Define method for class Base16
|
311
|
+
rb_define_singleton_method(cCoBreakBase16, "encode", b16_encode, 1);
|
312
|
+
rb_define_singleton_method(cCoBreakBase16, "decode", b16_decode, 1);
|
313
|
+
|
314
|
+
//Define class Base32 in module mCoBreakCipher
|
315
|
+
cCoBreakBase32 = rb_define_class_under(mCoBreakCipher, "Base32", rb_cObject);
|
316
|
+
|
317
|
+
//Define method for class Base32
|
318
|
+
rb_define_singleton_method(cCoBreakBase32, "encode", b32_encode, 1);
|
319
|
+
rb_define_singleton_method(cCoBreakBase32, "decode", b32_decode, 1);
|
320
|
+
|
321
|
+
//Define class Base64 in module mCoBreakCipher
|
322
|
+
cCoBreakBase64 = rb_define_class_under(mCoBreakCipher, "Base64", rb_cObject);
|
323
|
+
|
324
|
+
//Define method for class Base64
|
325
|
+
rb_define_singleton_method(cCoBreakBase64, "encode", b64_encode, 1);
|
326
|
+
rb_define_singleton_method(cCoBreakBase64, "decode", b64_decode, 1);
|
327
|
+
|
328
|
+
//Define class Cesar in module mCoBreakCipher
|
329
|
+
cCoBreakCesar = rb_define_class_under(mCoBreakCipher, "Cesar", rb_cObject);
|
330
|
+
|
331
|
+
//Define method for class Cesar
|
332
|
+
rb_define_singleton_method(cCoBreakCesar, "encode", cesar_encode, 2);
|
333
|
+
rb_define_singleton_method(cCoBreakCesar, "decode", cesar_decode, 2);
|
334
|
+
|
335
|
+
//Define class Cesar in module mCoBreakCipher
|
336
|
+
cCoBreakBinary = rb_define_class_under(mCoBreakCipher, "Binary", rb_cObject);
|
337
|
+
|
338
|
+
//Define method for class Binary
|
339
|
+
rb_define_singleton_method(cCoBreakBinary, "encode", binary_encode, 1);
|
340
|
+
rb_define_singleton_method(cCoBreakBinary, "decode", binary_decode, 1);
|
341
|
+
}
|