Skip to content

Commit 7a67fae

Browse files
authored
update [2.0.0] : rewrite complete
1 parent 8ee5958 commit 7a67fae

13 files changed

+272
-144
lines changed

README.md

+23-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
# ARS_SHELL_CRYPT
2-
3-
⚒ ARS_SHELL_CRYPT is a modified caesar's-cipher-based encrypt system written in C++.
4-
🔐 ARS_SHELL_CRYPT contains 7 levels of security and even a decrypt system.
5-
6-
### 📌 Usage : (<a href="https://github.com/4m4Sec/ARS_SHELL_CRYPT/blob/main/example.cpp">example.cpp</a>)
7-
```cpp
8-
#include <iostream>
9-
#include "ars.cpp"
10-
11-
int main(){
12-
// Test encrypt :
13-
std::string encrypt_text = encrypt("test", security.STANDARD_SEC_1);
14-
std::cout << encrypt_text << std::endl;
15-
16-
// Test decrypt :
17-
std::string decrypt_text = decrypt(encrypt_text, security.STANDARD_SEC_1);
18-
std::cout << decrypt_text << std::endl;
19-
return 0;
20-
}
21-
```
22-
Require the <a href="https://github.com/4m4Sec/ARS_SHELL_CRYPT/blob/main/ars.cpp">ars.cpp</a> file and use the functions encrypt() & decrypt()
23-
All security constants : (check in <a href="https://github.com/4m4Sec/ARS_SHELL_CRYPT/blob/main/src/standard/standard_security.cpp">standard_security.cpp</a>)
24-
-> <span style="color:grey">STANDARD_SEC_1</span>, STANDARD_SEC_2, <span style="color:grey">STANDARD_SEC_3</span>, STANDARD_SEC_4
25-
-> <span style="color:grey">STANDARD_SEC_5</span>, STANDARD_SEC_6, <span style="color:grey">STANDARD_SEC_7</span>
1+
# ARS_ENCRYPT
2+
3+
⚒ ARS_ENCRYPT is a modified caesar's-cipher-based encrypt system written in C++.
4+
🔐 ARS_ENCRYPT contains 6 layers of security and a decrypt system.
5+
6+
### 📌 Usage : (<a href="https://github.com/4m4Sec/ARS_ENCRYPT/blob/main/example.cpp">example.cpp</a>)
7+
```cpp
8+
#include <iostream>
9+
#include "ars.cpp"
10+
11+
int main(){
12+
// Test encrypt :
13+
std::string encrypt_text = encrypt("test", security.STANDARD_SEC_1);
14+
std::cout << encrypt_text << std::endl;
15+
16+
// Test decrypt :
17+
std::string decrypt_text = decrypt(encrypt_text, security.STANDARD_SEC_1);
18+
std::cout << decrypt_text << std::endl;
19+
return 0;
20+
}
21+
```
22+
Require the <a href="https://github.com/4m4Sec/ARS_ENCRYPT/blob/main/ars.cpp">ars.cpp</a> file and use the functions encrypt() & decrypt()
23+
Security layer goes from 1 to 6. Check in the <a href="https://github.com/4m4Sec/ARS_ENCRYPT/blob/main/src/standard/standard_security.cpp">standard_security.cpp</a> file.

ars.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "ars.h"
2-
#include "src/crypt/cipher_crypt.cpp"
3-
4-
std::string encrypt(std::string plaintext, int sec){
5-
return (new cipher_crypt(plaintext, sec, "", ""))->encrypt();
6-
}
7-
8-
std::string decrypt(std::string hash, int sec){
9-
return (new cipher_crypt("", sec, hash, ""))->decrypt();
1+
#include "ars.h"
2+
#include "src/encrypt/cipher_encrypt.cpp"
3+
4+
std::string encrypt(std::string plaintext, int sec){
5+
return (new cipher_encrypt(plaintext, sec, "", ""))->encrypt();
6+
}
7+
8+
std::string decrypt(std::string hash, int sec){
9+
return (new cipher_encrypt("", sec, hash, ""))->decrypt();
1010
}

ars.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef ARS_SHELL_CRYPT_ARS_H
2-
#define ARS_SHELL_CRYPT_ARS_H
3-
4-
#include "src/standard/standard_security.cpp"
5-
6-
struct standard_security security;
7-
8-
std::string encrypt(std::string plaintext, int sec);
9-
std::string decrypt(std::string hash, int sec);
10-
11-
#endif
1+
#ifndef ARS_SHELL_CRYPT_ARS_H
2+
#define ARS_SHELL_CRYPT_ARS_H
3+
4+
#include "src/standard/standard_security.cpp"
5+
6+
struct standard_security security;
7+
8+
std::string encrypt(std::string plaintext, int sec);
9+
std::string decrypt(std::string hash, int sec);
10+
11+
#endif

example.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include <iostream>
2-
#include "ars.cpp"
3-
4-
int main(){
5-
// Test encrypt :
6-
std::string encrypt_text = encrypt("password_test", security.STANDARD_SEC_6);
7-
std::cout << encrypt_text << std::endl;
8-
9-
// Test decrypt :
10-
std::string decrypt_text = decrypt(encrypt_text, security.STANDARD_SEC_6);
11-
std::cout << decrypt_text << std::endl;
12-
return 0;
1+
#include <iostream>
2+
#include "ars.cpp"
3+
4+
int main(){
5+
// Test encrypt :
6+
std::string encrypt_text = encrypt("azerty123", security.STANDARD_SEC_6);
7+
std::cout << encrypt_text << std::endl;
8+
9+
// Test decrypt :
10+
std::string decrypt_text = decrypt(encrypt_text, security.STANDARD_SEC_6);
11+
std::cout << decrypt_text << std::endl;
12+
return 0;
1313
}

src/encrypt/cipher_encrypt.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "cipher_encrypt.h"
2+
3+
cipher_encrypt::cipher_encrypt(std::string plaintext, int sec, std::string encrypted, std::string decrypted):
4+
plaintext(plaintext),
5+
sec(sec),
6+
encrypted(encrypted),
7+
decrypted(decrypted)
8+
{ this->serialize_data(sec, plaintext.length()); }
9+
10+
std::string cipher_encrypt::encrypt(){
11+
std::string encrypt_s = "";
12+
13+
for (int i = 0; i < this->plaintext.length(); i++){
14+
encrypt_s += this->hash_char(std::string(1, this->plaintext.at(i)), this->_s);
15+
}
16+
this->encrypted = encrypt_s + this->add + this->f_break + this->s_break;
17+
return this->encrypted;
18+
}
19+
20+
std::string cipher_encrypt::decrypt(){
21+
std::string decrypt_s = "";
22+
std::vector<std::string> part = split(this->encrypted, '.');
23+
std::string hash = part.at(0);
24+
25+
for (int i = 0; i < hash.size(); i++){
26+
decrypt_s += this->unhash_char(std::string(1, hash.at(i)), this->_s);
27+
}
28+
this->decrypted = decrypt_s;
29+
return this->decrypted;
30+
}
31+

src/encrypt/cipher_encrypt.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef ARS_ENCRYPT_CIPHER_ENCRYPT_H
2+
#define ARS_ENCRYPT_CIPHER_ENCRYPT_H
3+
4+
#include "../security/security_handler.cpp"
5+
#include "../../utils/utils.cpp"
6+
7+
class cipher_encrypt : public security_handler {
8+
9+
private:
10+
std::string
11+
plaintext = "",
12+
encrypted = "",
13+
decrypted = "";
14+
int sec = 0;
15+
16+
public:
17+
cipher_encrypt(std::string plaintext, int sec, std::string encrypted, std::string decrypted);
18+
std::string encrypt();
19+
std::string decrypt();
20+
};
21+
22+
#endif

src/encrypt/hash_algorithm.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "hash_algorithm.h"
2+
3+
std::string hash_algorithm::hash_char(std::string f_char, int _s){
4+
std::string n_char = "";
5+
6+
for (int i = 0; i <= this->list.get_size() - 1; i++){
7+
if (this->list.CHAR_LIST[i] == f_char){
8+
if (i >= _s){
9+
do {
10+
if (this->list.CHAR_LIST.find(i + _s) != this->list.CHAR_LIST.end()){
11+
n_char = this->list.CHAR_LIST[i + _s];
12+
break;
13+
} else if (this->list.CHAR_LIST.find((i + _s) - this->list.get_size()) != this->list.CHAR_LIST.end()){
14+
n_char = this->list.CHAR_LIST[(i + _s) - this->list.get_size()];
15+
break;
16+
}
17+
} while (true);
18+
break;
19+
} else if (i < _s){
20+
do {
21+
if (this->list.CHAR_LIST.find(i + _s) != this->list.CHAR_LIST.end()){
22+
n_char = this->list.CHAR_LIST[i + _s];
23+
break;
24+
}
25+
} while (true);
26+
break;
27+
}
28+
}
29+
}
30+
return n_char;
31+
}
32+
33+
std::string hash_algorithm::unhash_char(std::string r_char, int _s){
34+
std::string n_char = "";
35+
36+
for (int i = 0; i <= this->list.get_size() - 1; i++){
37+
if (this->list.CHAR_LIST[i] == r_char){
38+
if (i >= _s){
39+
do {
40+
if (this->list.CHAR_LIST.find(i - _s) != this->list.CHAR_LIST.end()){
41+
n_char = this->list.CHAR_LIST[i - _s];
42+
break;
43+
}
44+
} while (true);
45+
break;
46+
} else if (i < _s){
47+
do {
48+
if (this->list.CHAR_LIST.find(i - _s) != this->list.CHAR_LIST.end()){
49+
n_char = this->list.CHAR_LIST[i - _s];
50+
break;
51+
} else if (this->list.CHAR_LIST.find((i - _s) + this->list.get_size()) != this->list.CHAR_LIST.end()){
52+
n_char = this->list.CHAR_LIST[(i - _s) + this->list.get_size()];
53+
break;
54+
}
55+
} while (true);
56+
break;
57+
}
58+
}
59+
}
60+
return n_char;
61+
}

src/encrypt/hash_algorithm.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef ARS_ENCRYPT_HASH_ALGORITHM_H
2+
#define ARS_ENCRYPT_HASH_ALGORITHM_H
3+
4+
#include "../standard/standard_list.cpp"
5+
6+
class hash_algorithm {
7+
8+
protected:
9+
struct standard_list list;
10+
11+
public:
12+
std::string hash_char(std::string f_char, int _s);
13+
std::string unhash_char(std::string r_char, int _s);
14+
};
15+
16+
#endif
17+

src/security/security_handler.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
#include "security_handler.h"
2-
#include <random>
3-
#include <ctime>
4-
#include <math.h>
5-
6-
void security_handler::serialize_data(int sec, int plaintext_lght){
7-
this->_s = sec * 5;
8-
this->add = this->gen_random_string(plaintext_lght, sec * (time(0) + 2));
9-
this->f_break = this->gen_random_string(plaintext_lght, sec * (time(0) - 2));
10-
this->s_break = this->gen_random_string(plaintext_lght, sec * (time(0) / 2));
11-
}
12-
13-
std::string security_handler::gen_random_string(int plaintext_lght, int multiplier){
14-
std::string str = ".";
15-
16-
for (int i = time(0); i < time(0) + plaintext_lght; i++){
17-
srand((unsigned) (time(0) * i * multiplier) + (multiplier * time(0)));
18-
str += this->list.CHAR_LIST[rand() % (this->list.get_size() - 1)];
19-
}
20-
return str;
1+
#include "security_handler.h"
2+
#include <random>
3+
#include <ctime>
4+
#include <math.h>
5+
6+
void security_handler::serialize_data(int sec, int plaintext_lght){
7+
this->_s = sec * 5;
8+
this->add = this->gen_random_string(plaintext_lght, sec * (time(0) + 2));
9+
this->f_break = this->gen_random_string(plaintext_lght, sec * (time(0) - 2));
10+
this->s_break = this->gen_random_string(plaintext_lght, sec * (time(0) / 2));
11+
}
12+
13+
std::string security_handler::gen_random_string(int plaintext_lght, int multiplier){
14+
std::string str = ".";
15+
16+
for (int i = time(0); i < time(0) + plaintext_lght; i++){
17+
srand((unsigned) (time(0) * i * multiplier) + (multiplier * time(0)));
18+
str += this->list.CHAR_LIST[rand() % (this->list.get_size() - 1)];
19+
}
20+
return str;
2121
}

src/security/security_handler.h

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
#ifndef ARS_SHELL_CRYPT_SECURITY_HANDLER_H
2-
#define ARS_SHELL_CRYPT_SECURITY_HANDLER_H
3-
4-
#include "../crypt/hash_algorithm.cpp"
5-
6-
class security_handler : public hash_algorithm {
7-
8-
public:
9-
std::string
10-
add = "",
11-
f_break = "",
12-
s_break = "";
13-
int _s = 0;
14-
15-
public:
16-
void serialize_data(int sec, int plaintext_lght);
17-
std::string gen_random_string(int plaintext_lght, int multiplier);
18-
};
19-
20-
#endif
21-
1+
#ifndef ARS_ENCRYPT_SECURITY_HANDLER_H
2+
#define ARS_ENCRYPT_SECURITY_HANDLER_H
3+
4+
#include "../encrypt/hash_algorithm.cpp"
5+
6+
class security_handler : public hash_algorithm {
7+
8+
public:
9+
std::string
10+
add = "",
11+
f_break = "",
12+
s_break = "";
13+
int _s = 0;
14+
15+
public:
16+
void serialize_data(int sec, int plaintext_lght);
17+
std::string gen_random_string(int plaintext_lght, int multiplier);
18+
};
19+
20+
#endif
21+

src/standard/standard_list.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
#include <iostream>
2-
#include <map>
3-
4-
struct standard_list {
5-
6-
public:
7-
std::map<int, std::string> CHAR_LIST = {
8-
{0, "a"}, {1, "A"}, {2, "b"}, {3, "B"}, {4, "c"}, {5, "C"}, {6, "d"}, {7, "D"}, {8, "e"}, {9, "E"}, {10, "f"},
9-
{11, "F"}, {12, "g"}, {13, "G"}, {14, "h"}, {15, "H"}, {16, "i"}, {17, "I"}, {18, "j"}, {19, "J"}, {20, "k"},
10-
{21, "K"}, {22, "l"}, {23, "L"}, {24, "m"}, {25, "M"}, {26, "n"}, {27, "N"}, {28, "o"}, {29, "O"}, {30, "p"},
11-
{31, "P"}, {32, "q"}, {33, "Q"}, {34, "r"}, {35, "R"}, {36, "s"}, {37, "S"}, {38, "t"}, {39, "T"}, {40, "u"},
12-
{41, "U"}, {42, "v"}, {43, "V"}, {44, "w"}, {45, "W"}, {46, "x"}, {47, "X"}, {48, "y"}, {49, "Y"}, {50, "z"},
13-
{51, "Z"}, {52, "1"}, {53, "2"}, {54, "3"}, {55, "4"}, {56, "5"}, {57, "6"}, {58, "7"}, {59, "8"}, {60, "9"},
14-
{61, "0"}, {62, "_"}
15-
};
16-
17-
int get_size(){
18-
return CHAR_LIST.size();
19-
}
20-
};
21-
1+
#include <iostream>
2+
#include <map>
3+
4+
struct standard_list {
5+
6+
public:
7+
std::map<int, std::string> CHAR_LIST = {
8+
{0, "a"}, {1, "A"}, {2, "b"}, {3, "B"}, {4, "c"}, {5, "C"}, {6, "d"}, {7, "D"}, {8, "e"}, {9, "E"}, {10, "f"},
9+
{11, "F"}, {12, "g"}, {13, "G"}, {14, "h"}, {15, "H"}, {16, "i"}, {17, "I"}, {18, "j"}, {19, "J"}, {20, "k"},
10+
{21, "K"}, {22, "l"}, {23, "L"}, {24, "m"}, {25, "M"}, {26, "n"}, {27, "N"}, {28, "o"}, {29, "O"}, {30, "p"},
11+
{31, "P"}, {32, "q"}, {33, "Q"}, {34, "r"}, {35, "R"}, {36, "s"}, {37, "S"}, {38, "t"}, {39, "T"}, {40, "u"},
12+
{41, "U"}, {42, "v"}, {43, "V"}, {44, "w"}, {45, "W"}, {46, "x"}, {47, "X"}, {48, "y"}, {49, "Y"}, {50, "z"},
13+
{51, "Z"}, {52, "1"}, {53, "2"}, {54, "3"}, {55, "4"}, {56, "5"}, {57, "6"}, {58, "7"}, {59, "8"}, {60, "9"},
14+
{61, "0"}, {62, "_"}
15+
};
16+
17+
int get_size(){
18+
return CHAR_LIST.size();
19+
}
20+
};
21+

0 commit comments

Comments
 (0)