-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkrypt.cpp
More file actions
120 lines (103 loc) · 3.36 KB
/
krypt.cpp
File metadata and controls
120 lines (103 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <sstream>
#include <algorithm>
using namespace std;
char abc[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
char abcbig[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
char nbr[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
char sym[8] = { '!', '@', '#', '$', '%', '^', '&', '*'};
string krypt(string input, bool show_status){
if(!input.empty() && show_status){
cout << "encrypting..." << endl << endl;
}
else if(input.empty() && show_status){
cout << "error: string is empty!" << endl << endl;
return 0;
}
string str_obj(input);
char* chr = new char[input.length() + 1];
strcpy(chr, input.c_str());
int length = input.length();
int delta = 2 * pow(length - 1, 2);
int s1, s2, s3;
s1 = ((sqrt(delta) + length) * length) - (sqrt(length) * 2) + 1;
s2 = ((sqrt(delta) - length) * length) + (sqrt(length) * 2) - 1;
s3 = sqrt(pow(sqrt(s1 + s2), 3) + 1);
while(s3 > 10){
s3 -= (s3 / 2) + (s3 % 2);
}
unsigned long long int encryptionkey = ((((length * 10 + s3) / length) * sqrt(s3)) + s3 * length + chr[0]) * pow(chr[1], 2) / sqrt(chr[0]);
int symnbr;
symnbr = encryptionkey;
while(symnbr > 8){
symnbr /= 8;
}
int a = 0;
for(int i = 1; i<=s3 * 2; i++){
for(int i = 0; i<length; i++){
for(int j = 0; j<26; j++){
if(chr[i] == abc[j]){
a = j + s3;
if(a >= 26){
a = a - 26;
}
chr[i] = abc[a];
break;
}
else if(chr[i] == abcbig[j]){
a = j + s3;
if(a >= 26){
a = a - 26;
}
chr[i] = abcbig[a];
break;
}
}
}
}
for(int i = 0; i<length; i++){
for(int j = 0; j<10; j++){
if(chr[i] == nbr[j]){
a = j + s3;
if(a >= 10){
a = a - 10;
}
chr[i] = nbr[a];
break;
}
}
}
string krypted;
for(int i = 0; i<length; i++){
krypted.push_back(chr[i]);
}
auto to_hex = [](string input) -> string{
int length = input.length();
stringstream ss;
for(int i = 0; i<length; i++){
ss << hex << (int)input[i];
}
return ss.str();
};
string hexxed = to_hex(krypted);
int hexlength = hexxed.length();
int spd2 = 0;
transform(hexxed.begin(), hexxed.end(), hexxed.begin(), ::toupper);
string encstr = to_string(encryptionkey);
string symbol (1, sym[symnbr]);
string fullenc = symbol + to_string(encryptionkey);
string layer3 = hexxed + fullenc;
if(show_status){
cout << layer3;
}
return layer3;
}
int main(){
string input;
getline(cin, input);
krypt(input, true);
return 0;
}