-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
210 lines (180 loc) · 4.53 KB
/
main.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <bits/stdc++.h>
using namespace std;
struct Node {
double key;
vector<Node*> child;
};
Node* newNode(int key)
{
Node* temp = new Node;
temp->key = key;
return temp;
}
// Driver program
int main()
{
cout<<"Enter 1 to create new node";
cout<<"Enter 2 to view existing node";
cout<<"Enter 3 to modify node";
cout<<"Enter 4 to view longest chain";
int n;
cin>>n;
switch(n)
{
case 1:
void enter_new_node();
break;
case 2:
void view_node();
break;
case 3:
void modify_node();
break;
case 4:
void longest_chain();
break;
}
return 0;
}
void enter_new_node()
{
cout<<"Enter a new node";
double abc;
cin>>abc;
int no;
cout<<"Enter the level of new node";
cin>>no;
Node* root =NULL;//Creating Genesis node and making it null;
vector<double>sum;//to store summ of parent node of different levels
if(sum[no==0])//checking the sum of parent node if exists
sum[no]=abc;//assign the sum if not existed;
if(sum[no]-abc>)
unordered_map <string, string> hash_srt;//creating a hash set
string name;
cout<<"Enter your name";
cin>>name;
double data = encryption(abc,name,hash_srt);
`if(Node*root == NULL)//checking root node to be null or not
Node* root = newNode(data);//Creating Genesis node and making it null;
else
{
if(no==2)
(root->child).push_back(newNode(data));//pushing no of nodes at level 1
else
(root->child[no-1]->child).push_back(newNode(data));// pushinh no of nodes at any level
}
}
void view_node()
{
cout<<"Enter your name";
string name;
cin>>string;
if(hash_srt.find(name))//if the owner name is present in the hash set
{
cout<<"enter your key";
int b;
cin>>b;//enter the private key for decryption
cout<<decryption(b,name,hash_srt);
}
}
double encryption(double msg,string name,unordered_map hash_srt)
{
//2 random prime numbers
double p = 3;
double q = 7;
double n=p*q;
double count;
double totient = (p-1)*(q-1);
//public key
//e stands for encrypt
double e=2;
//for checking co-prime which satisfies e>1
while(e<totient){
count = gcd(e,totient);
if(count==1)
break;
else
e++;
}
//private key
//d stands for decrypt
double d;
//k can be any arbitrary value
double k = 2;
//choosing d such that it satisfies d*e = 1 + k * totient
d = (1 + (k*totient))/e;
hash_srt.insert(pair <string, string> (c, abc));//hashing the owner name to the encrypted data of key
hash_srt.insert(pair <string, string> (c, d));//hashing the private key to the encrypted data of key
return c;
}
double decryption(double key,string name,unordered_map hash_srt)
{
//2 random prime numbers
double p = 3;
double q = 7;
double n=p*q;
double count;
double totient = (p-1)*(q-1);
//public key
//e stands for encrypt
double e=2;
//for checking co-prime which satisfies e>1
while(e<totient){
count = gcd(e,totient);
if(count==1)
break;
else
e++;
}
//private key
//d stands for decrypt
double d;
//k can be any arbitrary value
double k = 2;
//choosing d such that it satisfies d*e = 1 + k * totient
d = (1 + (k*totient))/e;
double c = pow(msg,e);
double m = pow(c,d);
c=fmod(c,n);
m=fmod(m,n);
if(hash_srt.find(m))
cout<<hash_srt->second;
}
void modify_node()
{
cout<<"Enter your name";
string name;
cin>>string;
if(hash_srt.find(name))//if name is present in hash table
{
cout<<"enter new key";
double b;
cout<<"enter level";
hash_srt.delete(key,name);//delete the existing key
void encryption(key,name,hash_srt);//and create a new one at that level
}
}
void transfer_ownership()
{
cout<<"Enter your name";
string name;
cin>>string;
if(hash_srt.find(name))//if name is present in hash table
{
string abc;
cout<<"Enter new owner name";
cin>>abc;
hash_srt->second=abc;//updating hash table on a new owner
}
}
void diameter(struct node * root)
{
if (root == NULL)
return 0;
int lheight = height(root->left);
int rheight = height(root->right);
/* get the diameter of left and right sub-trees */
int ldiameter = diameter(root->left);
int rdiameter = diameter(root->right);
return max(lheight + rheight + 1, max(ldiameter, rdiameter));
}