rcrypto 1.0
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/LICENSE +21 -0
- data/README.md +193 -0
- data/lib/RCrypto/decode.rb +21 -0
- data/lib/RCrypto/encode.rb +32 -0
- data/lib/RCrypto/version.rb +4 -0
- data/lib/RCrypto.rb +119 -0
- data/spec/rcrypto_spec.rb +106 -0
- data/spec/spec_helper.rb +3 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3af4e1f11c1db798442da56a2f451abd4f77ea7b6ab51d3a8714a055fc77552e
|
4
|
+
data.tar.gz: f39a0a959480d573e635a31c9e9ae70f69dbbd97c53569c2361e44e3dea164da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c567ca02115e156bd8cf620089ea97e6cc3ca0994c160d85a87eee68bda90111c7df839de7528757bee2f855e000a40aba077edbef3dc23234f4dfc345bfa63c
|
7
|
+
data.tar.gz: 60499a2a310c8d9292cbbbc9fc7e95713f7b731b297efeb00353cd82be024f0de2373df87c4b4dbe73e384033117532ca362117add2ebbf7b58a05b90f9761a3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 MAVEN
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# RCrypto
|
4
|
+
|
5
|
+
**RCrypto** is a custom encryption library for Ruby that offers a variety of encryption methods, including XOR encryption, Caesar cipher, and substitution cipher. It is designed for developers looking to implement secure communication features in their Ruby applications.
|
6
|
+
|
7
|
+
## Marketing Message
|
8
|
+
|
9
|
+
Do you want your script to look like this, hidden from prying eyes?
|
10
|
+
|
11
|
+
```
|
12
|
+
ZYLYMBLhG0XONonzLIUpDCeLQ$sWYR5GfbHgdTZAICPJndFRdeOBdzGUpFBNLoIErBxZ0BtBrCPNd==#9defa851ec8ec36149a13815ec6233c1
|
13
|
+
```
|
14
|
+
|
15
|
+
Instead of this?
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
puts "Ruby Is The Best yoo Note: RCrypto Is Easy"
|
19
|
+
```
|
20
|
+
|
21
|
+
Use **RCrypto** to protect your hard-earned code from being stolen. Secure the source code you spent sleepless nights writing.
|
22
|
+
|
23
|
+
## Features
|
24
|
+
|
25
|
+
- **XOR Encryption**: A simple yet effective encryption method.
|
26
|
+
- **Caesar Cipher**: A classic encryption technique with customizable shifts.
|
27
|
+
- **Substitution Cipher**: Encrypt text by substituting characters with a shuffled alphabet.
|
28
|
+
- **Custom Key Generation**: Automatically generate secure keys for encryption.
|
29
|
+
- **Encryption Detection**: Identify whether a given text appears to be encrypted.
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
To use RCrypto, follow the steps below to clone the repository and integrate it into your Ruby project.
|
34
|
+
|
35
|
+
### 1. Clone the Repository
|
36
|
+
|
37
|
+
Clone the RCrypto repository to your local machine:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
git clone https://github.com/Abo5/rcrypto.git
|
41
|
+
```
|
42
|
+
#### or
|
43
|
+
```bash
|
44
|
+
gem install rcrypto
|
45
|
+
```
|
46
|
+
#### or
|
47
|
+
```ruby
|
48
|
+
source 'https://rubygems.org'
|
49
|
+
|
50
|
+
gem 'rcrypto'
|
51
|
+
```
|
52
|
+
```bash
|
53
|
+
bundle install rcrypto
|
54
|
+
```
|
55
|
+
|
56
|
+
### 2. Require the Library in Your Ruby Script
|
57
|
+
|
58
|
+
After cloning the repository, require the library in your Ruby script:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'rcrypto'
|
62
|
+
```
|
63
|
+
|
64
|
+
## Basic Usage
|
65
|
+
|
66
|
+
### Encrypting and Decrypting a Script
|
67
|
+
|
68
|
+
Suppose you have a Ruby script (`test.rb`) that you want to encrypt and later decrypt.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'rcrypto'
|
72
|
+
|
73
|
+
# Read the original script
|
74
|
+
original_script = File.read('test.rb')
|
75
|
+
|
76
|
+
# Encrypt the script
|
77
|
+
encrypted_script = RCrypto::CustomEncryptor.encrypt(original_script)
|
78
|
+
puts "Encrypted script:"
|
79
|
+
puts encrypted_script
|
80
|
+
|
81
|
+
# Decrypt the script
|
82
|
+
decrypted_script = RCrypto::CustomEncryptor.decrypt(encrypted_script)
|
83
|
+
puts "\nDecrypted script:"
|
84
|
+
puts decrypted_script
|
85
|
+
|
86
|
+
# Execute the decrypted script
|
87
|
+
eval(decrypted_script)
|
88
|
+
```
|
89
|
+
|
90
|
+
### Encrypting with an Auto-generated Key
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# Read the original script
|
94
|
+
original_script = File.read('main.rb')
|
95
|
+
|
96
|
+
# Encrypt the script using an auto-generated key
|
97
|
+
encrypted_script = RCrypto::CustomEncryptor.encrypt(original_script)
|
98
|
+
puts "Encrypted script:"
|
99
|
+
puts encrypted_script
|
100
|
+
|
101
|
+
# Decrypt the script
|
102
|
+
decrypted_script = RCrypto::CustomEncryptor.decrypt(encrypted_script)
|
103
|
+
puts "\nDecrypted script:"
|
104
|
+
puts decrypted_script
|
105
|
+
```
|
106
|
+
|
107
|
+
## Advanced Usage
|
108
|
+
|
109
|
+
### Using the SimpleEncryptor for Custom Encryption
|
110
|
+
|
111
|
+
The `SimpleEncryptor` class allows for more flexibility with custom keys and ciphers.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
require 'rcrypto'
|
115
|
+
|
116
|
+
text = "Hello World!"
|
117
|
+
key = RCrypto::SimpleEncryptor.generate_simple_key(20)
|
118
|
+
|
119
|
+
# XOR Encryption
|
120
|
+
encrypted_text = RCrypto::SimpleEncryptor.xor_encrypt(text, key)
|
121
|
+
puts "XOR Encrypted text:"
|
122
|
+
puts encrypted_text
|
123
|
+
|
124
|
+
decrypted_text = RCrypto::SimpleEncryptor.xor_decrypt(encrypted_text, key)
|
125
|
+
puts "Decrypted text:"
|
126
|
+
puts decrypted_text
|
127
|
+
|
128
|
+
# Caesar Cipher Encryption
|
129
|
+
shift = 5
|
130
|
+
caesar_encrypted = RCrypto::SimpleEncryptor.caesar_encrypt(text, shift)
|
131
|
+
puts "Caesar Encrypted text:"
|
132
|
+
puts caesar_encrypted
|
133
|
+
|
134
|
+
caesar_decrypted = RCrypto::SimpleEncryptor.caesar_decrypt(caesar_encrypted, shift)
|
135
|
+
puts "Decrypted text:"
|
136
|
+
puts caesar_decrypted
|
137
|
+
```
|
138
|
+
|
139
|
+
### Detecting Encrypted Text
|
140
|
+
|
141
|
+
RCrypto can help determine if a given text appears to be encrypted.
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
long_text = "This is a longer text that should be more complex to encrypt and easier to detect as encrypted."
|
145
|
+
encrypted_text = RCrypto::SimpleEncryptor.xor_encrypt(long_text, key)
|
146
|
+
|
147
|
+
if RCrypto::SimpleEncryptor.seems_encrypted?(encrypted_text)
|
148
|
+
puts "The text seems to be encrypted."
|
149
|
+
else
|
150
|
+
puts "The text does not appear to be encrypted."
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
## Contributing
|
155
|
+
|
156
|
+
Contributions are welcome! If you'd like to contribute to RCrypto, please follow these steps:
|
157
|
+
|
158
|
+
1. **Fork the repository.**
|
159
|
+
2. **Create a new branch** (`git checkout -b feature/YourFeatureName`).
|
160
|
+
3. **Make your changes** and commit them (`git commit -m 'Add some feature'`).
|
161
|
+
4. **Push to the branch** (`git push origin feature/YourFeatureName`).
|
162
|
+
5. **Open a Pull Request** on GitHub.
|
163
|
+
|
164
|
+
Please ensure your code follows the existing coding conventions and passes all tests.
|
165
|
+
|
166
|
+
## Running Tests
|
167
|
+
|
168
|
+
RCrypto uses RSpec for testing. To run the tests, ensure you have the required dependencies installed and run:
|
169
|
+
|
170
|
+
```bash
|
171
|
+
bundle install
|
172
|
+
bundle exec rspec
|
173
|
+
```
|
174
|
+
|
175
|
+
This will run the test suite and ensure everything is working as expected.
|
176
|
+
|
177
|
+
## License
|
178
|
+
|
179
|
+
This project is licensed under the MIT License. See the [LICENSE](https://github.com/Abo5/rcrypto/LICENSE) file for more details.
|
180
|
+
|
181
|
+
## Issues and Feedback
|
182
|
+
|
183
|
+
If you encounter any issues or have suggestions for improvements, please feel free to [open an issue](https://github.com/Abo5/rcrypto/issues) on GitHub. Your feedback is highly appreciated!
|
184
|
+
|
185
|
+
## Authors
|
186
|
+
|
187
|
+
- **MAVEN** - *Initial work* - [GitHub Profile](https://github.com/Abo5)
|
188
|
+
|
189
|
+
## Acknowledgments
|
190
|
+
|
191
|
+
- Special thanks to the open-source community for their continuous support.
|
192
|
+
- Inspired by classic encryption techniques and the need for secure communication in Ruby applications.
|
193
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# lib/RCrypto/decode.rb
|
2
|
+
|
3
|
+
module RCrypto
|
4
|
+
module Decode
|
5
|
+
def self.xor_decrypt(text, key)
|
6
|
+
RCrypto::Encode.xor_encrypt(text, key) # XOR encryption is its own inverse
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.base64_custom_decode(text)
|
10
|
+
Base64.strict_decode64(text)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.caesar_cipher_decrypt(text, shift)
|
14
|
+
RCrypto::Encode.caesar_cipher_encrypt(text, 26 - shift)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.remove_fake_token(text)
|
18
|
+
text.gsub(/\$[a-zA-Z0-9]{10}/, '')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# lib/RCrypto/encode.rb
|
2
|
+
|
3
|
+
module RCrypto
|
4
|
+
module Encode
|
5
|
+
def self.xor_encrypt(text, key)
|
6
|
+
text.bytes.map.with_index do |byte, i|
|
7
|
+
(byte ^ key.bytes[i % key.length]).chr
|
8
|
+
end.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.base64_custom_encode(text)
|
12
|
+
Base64.strict_encode64(text)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.caesar_cipher_encrypt(text, shift)
|
16
|
+
text.chars.map do |char|
|
17
|
+
if char.match(/[a-zA-Z]/)
|
18
|
+
base = char =~ /[a-z]/ ? 'a'.ord : 'A'.ord
|
19
|
+
((char.ord - base + shift) % 26 + base).chr
|
20
|
+
else
|
21
|
+
char
|
22
|
+
end
|
23
|
+
end.join
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.add_fake_token(text)
|
27
|
+
fake_token = "$" + SecureRandom.alphanumeric(10)
|
28
|
+
insertion_point = SecureRandom.random_number(text.length)
|
29
|
+
text.insert(insertion_point, fake_token)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/RCrypto.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# RCrypto/lib/RCrypto.rb
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
require 'digest'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
require_relative 'RCrypto/encode'
|
8
|
+
require_relative 'RCrypto/decode'
|
9
|
+
|
10
|
+
module RCrypto
|
11
|
+
class CustomEncryptor
|
12
|
+
# Encrypts the given text using a series of encryption steps
|
13
|
+
def self.encrypt(text)
|
14
|
+
key = generate_key
|
15
|
+
stage1 = Encode.xor_encrypt(text, key[0..15])
|
16
|
+
stage2 = Encode.base64_custom_encode(stage1)
|
17
|
+
stage3 = Encode.caesar_cipher_encrypt(stage2, key.bytes.sum % 26)
|
18
|
+
stage4 = Encode.add_fake_token(stage3)
|
19
|
+
final_encrypted = stage4 + "#" + key
|
20
|
+
final_encrypted
|
21
|
+
end
|
22
|
+
|
23
|
+
# Decrypts the given encrypted text using the same steps in reverse
|
24
|
+
def self.decrypt(encrypted_text_with_key)
|
25
|
+
encrypted_text, key = encrypted_text_with_key.split("#", 2)
|
26
|
+
stage4 = Decode.remove_fake_token(encrypted_text)
|
27
|
+
stage3 = Decode.caesar_cipher_decrypt(stage4, key.bytes.sum % 26)
|
28
|
+
stage2 = Decode.base64_custom_decode(stage3)
|
29
|
+
original_text = Decode.xor_decrypt(stage2, key[0..15])
|
30
|
+
original_text
|
31
|
+
end
|
32
|
+
|
33
|
+
# Generates a random key using MD5 hash
|
34
|
+
def self.generate_key
|
35
|
+
Digest::MD5.hexdigest(SecureRandom.bytes(16))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class SimpleEncryptor
|
40
|
+
def initialize(key)
|
41
|
+
@key = key
|
42
|
+
@key = generate_simple_key(20)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Performs XOR encryption using the provided key
|
46
|
+
def self.xor_encrypt(text, key)
|
47
|
+
Encode.xor_encrypt(text, key)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Decrypts text that was encrypted using XOR
|
51
|
+
def self.xor_decrypt(encrypted_text, key)
|
52
|
+
Decode.xor_decrypt(encrypted_text, key)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Encrypts the text using the Caesar cipher with the specified shift
|
56
|
+
def self.caesar_encrypt(text, shift)
|
57
|
+
Encode.caesar_cipher_encrypt(text, shift)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Decrypts text that was encrypted using the Caesar cipher
|
61
|
+
def self.caesar_decrypt(encrypted_text, shift)
|
62
|
+
Decode.caesar_cipher_decrypt(encrypted_text, shift)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Generates a simple substitution cipher key by shuffling the alphabet
|
66
|
+
def self.generate_simple_key(length = 26)
|
67
|
+
alphabet = ('a'..'z').to_a.shuffle.join
|
68
|
+
alphabet
|
69
|
+
end
|
70
|
+
|
71
|
+
# Encrypts the text using a substitution cipher with the provided key
|
72
|
+
def self.substitution_encrypt(text, key)
|
73
|
+
alphabet = ('a'..'z').to_a.join
|
74
|
+
text.downcase.tr(alphabet, key)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Decrypts text that was encrypted using a substitution cipher
|
78
|
+
def self.substitution_decrypt(encrypted_text, key)
|
79
|
+
alphabet = ('a'..'z').to_a.join
|
80
|
+
encrypted_text.tr(key, alphabet)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Generates a simple hash of the text
|
84
|
+
def self.simple_hash(text)
|
85
|
+
hash = 0
|
86
|
+
text.each_byte do |byte|
|
87
|
+
hash = ((hash << 5) - hash) + byte
|
88
|
+
hash = hash & 0xFFFFFFFF
|
89
|
+
end
|
90
|
+
hash.to_s(16)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Analyzes the frequency of characters in the text
|
94
|
+
def self.frequency_analysis(text)
|
95
|
+
text.downcase.chars.group_by(&:itself).transform_values(&:count).sort_by { |_, v| -v }.to_h
|
96
|
+
end
|
97
|
+
|
98
|
+
# Determines if the text appears to be encrypted based on several criteria
|
99
|
+
def self.seems_encrypted?(text)
|
100
|
+
return false if text.length < 20 # Short texts are unlikely to be encrypted
|
101
|
+
|
102
|
+
# Calculate entropy
|
103
|
+
frequency = frequency_analysis(text)
|
104
|
+
entropy = frequency.values.sum { |count| -count * Math.log2(count.to_f / text.length) }
|
105
|
+
normalized_entropy = entropy / Math.log2(text.length)
|
106
|
+
|
107
|
+
# Calculate the ratio of non-alphabetic characters
|
108
|
+
non_alpha_chars_ratio = text.count("^a-zA-Z").to_f / text.length
|
109
|
+
|
110
|
+
# Analyze patterns - number of repeated sequences
|
111
|
+
repeated_patterns = text.scan(/(.+)\1/).size
|
112
|
+
|
113
|
+
# Consider the text encrypted if entropy is very high,
|
114
|
+
# if there is a high ratio of non-alphabetic characters,
|
115
|
+
# or if the number of repeated patterns is very low
|
116
|
+
normalized_entropy > 0.8 || non_alpha_chars_ratio > 0.3 || repeated_patterns < 2
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require_relative '../lib/RCrypto'
|
3
|
+
|
4
|
+
RSpec.describe RCrypto::CustomEncryptor do
|
5
|
+
let(:text) { 'Hello World!' }
|
6
|
+
|
7
|
+
describe '.encrypt and .decrypt' do
|
8
|
+
it 'encrypts and decrypts text correctly' do
|
9
|
+
encrypted_text = RCrypto::CustomEncryptor.encrypt(text)
|
10
|
+
decrypted_text = RCrypto::CustomEncryptor.decrypt(encrypted_text)
|
11
|
+
|
12
|
+
expect(decrypted_text).to eq(text)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'produces different outputs for the same text with different keys' do
|
16
|
+
encrypted_text_1 = RCrypto::CustomEncryptor.encrypt(text)
|
17
|
+
encrypted_text_2 = RCrypto::CustomEncryptor.encrypt(text)
|
18
|
+
|
19
|
+
expect(encrypted_text_1).not_to eq(encrypted_text_2)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.generate_key' do
|
24
|
+
it 'generates a unique key each time' do
|
25
|
+
key1 = RCrypto::CustomEncryptor.generate_key
|
26
|
+
key2 = RCrypto::CustomEncryptor.generate_key
|
27
|
+
|
28
|
+
expect(key1).not_to eq(key2)
|
29
|
+
expect(key1.length).to eq(32)
|
30
|
+
expect(key2.length).to eq(32)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.describe RCrypto::SimpleEncryptor do
|
36
|
+
let(:text) { 'Hello World!' }
|
37
|
+
let(:key) { RCrypto::SimpleEncryptor.generate_simple_key(20) }
|
38
|
+
|
39
|
+
describe '.xor_encrypt and .xor_decrypt' do
|
40
|
+
it 'encrypts and decrypts text correctly' do
|
41
|
+
encrypted_text = RCrypto::SimpleEncryptor.xor_encrypt(text, key)
|
42
|
+
decrypted_text = RCrypto::SimpleEncryptor.xor_decrypt(encrypted_text, key)
|
43
|
+
|
44
|
+
expect(decrypted_text).to eq(text)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '.caesar_encrypt and .caesar_decrypt' do
|
49
|
+
it 'encrypts and decrypts text correctly with Caesar cipher' do
|
50
|
+
shift = 5
|
51
|
+
encrypted_text = RCrypto::SimpleEncryptor.caesar_encrypt(text, shift)
|
52
|
+
decrypted_text = RCrypto::SimpleEncryptor.caesar_decrypt(encrypted_text, shift)
|
53
|
+
|
54
|
+
expect(decrypted_text).to eq(text)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.substitution_encrypt and .substitution_decrypt' do
|
59
|
+
it 'encrypts and decrypts text correctly with substitution cipher' do
|
60
|
+
key = RCrypto::SimpleEncryptor.generate_simple_key(26)
|
61
|
+
encrypted_text = RCrypto::SimpleEncryptor.substitution_encrypt(text, key)
|
62
|
+
decrypted_text = RCrypto::SimpleEncryptor.substitution_decrypt(encrypted_text, key)
|
63
|
+
|
64
|
+
expect(decrypted_text).to eq(text.downcase)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.simple_hash' do
|
69
|
+
it 'produces the same hash for the same input' do
|
70
|
+
hash1 = RCrypto::SimpleEncryptor.simple_hash(text)
|
71
|
+
hash2 = RCrypto::SimpleEncryptor.simple_hash(text)
|
72
|
+
|
73
|
+
expect(hash1).to eq(hash2)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'produces different hashes for different inputs' do
|
77
|
+
hash1 = RCrypto::SimpleEncryptor.simple_hash(text)
|
78
|
+
hash2 = RCrypto::SimpleEncryptor.simple_hash('Different text')
|
79
|
+
|
80
|
+
expect(hash1).not_to eq(hash2)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '.frequency_analysis' do
|
85
|
+
it 'calculates frequency of characters in text' do
|
86
|
+
frequency = RCrypto::SimpleEncryptor.frequency_analysis(text)
|
87
|
+
|
88
|
+
expect(frequency['l']).to eq(3)
|
89
|
+
expect(frequency['o']).to eq(2)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '.seems_encrypted?' do
|
94
|
+
it 'detects if text seems encrypted' do
|
95
|
+
long_text = 'This is a longer text that should be more complex to encrypt and easier to detect as encrypted.'
|
96
|
+
encrypted_text = RCrypto::SimpleEncryptor.xor_encrypt(long_text, key)
|
97
|
+
puts "Encrypted Text: #{encrypted_text}" # طباعة النص المشفر للتحليل
|
98
|
+
expect(RCrypto::SimpleEncryptor.seems_encrypted?(encrypted_text)).to be true
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'detects if text is not encrypted' do
|
102
|
+
expect(RCrypto::SimpleEncryptor.seems_encrypted?(text)).to be false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rcrypto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MAVEN
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: openssl
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: base64
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: digest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: securerandom
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '13.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '13.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: RCrypto provides custom encryption methods including XOR, Caesar cipher,
|
112
|
+
and substitution cipher for secure communication in Ruby applications.
|
113
|
+
email: aszda33@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- lib/RCrypto.rb
|
121
|
+
- lib/RCrypto/decode.rb
|
122
|
+
- lib/RCrypto/encode.rb
|
123
|
+
- lib/RCrypto/version.rb
|
124
|
+
- spec/rcrypto_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
homepage: https://github.com/Abo5/rcrypto
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata:
|
130
|
+
allowed_push_host: https://rubygems.org
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubygems_version: 3.5.16
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: A custom encryption library for Ruby.
|
150
|
+
test_files: []
|