Skip to content

Commit 3a673c9

Browse files
committed
didnt fix anything
1 parent 9024689 commit 3a673c9

3 files changed

Lines changed: 163 additions & 87 deletions

File tree

Notes.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
hexadecimalise program.cs, function, line 218, Generate_Chat()
1+
~hexadecimalise program.cs, function, line 218, Generate_Chat()~ (postponed)
2+
3+
4+
5+
() = encrypted
6+
[] = base64
7+
{} = hex
8+
var = var
9+
10+
11+
12+
name
13+
:
14+
{(key)}
15+
:
16+
{(iv)}
17+
18+
219

320

421

User.cs

Lines changed: 101 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,47 @@ public void Generate_Chat(string Name) {
9696

9797
Tuple<string,string> SymmetricKey = SymmetricEncryption.GenerateKeyAndIV();
9898

99+
// using (StreamWriter writer = new StreamWriter(@"chats\Keys.txt"))
100+
// {
101+
// writer.WriteLine(SymmetricKey.Item1);
102+
// writer.WriteLine(SymmetricKey.Item2);
103+
// }
104+
99105
using (StreamWriter writer = new StreamWriter(@"chats\"+FileName+".txt"))
100106
{
101-
writer.WriteLine( Name+":"+ this.Key.Encrypt(SymmetricKey.Item1+":"+SymmetricKey.Item2, User.Read_User_PublicKey(Name))
102-
);
103-
//writer.WriteLine(Name);
104-
//writer.WriteLine(User.Read_User_PublicKey(Name));
105-
writer.WriteLine(this.Username+":"+ this.Key.Encrypt(SymmetricKey.Item1+":"+SymmetricKey.Item2, User.Read_User_PublicKey(this.Username))
106-
);
107-
//writer.WriteLine(this.Username);
108-
//writer.WriteLine(User.Read_User_PublicKey(this.Username));
109-
/*writer.WriteLine(
110-
SymmetricEncryption.EncryptString(SymmetricKey.Item1, this.Username+" "+Name, SymmetricKey.Item2)
111-
);
112107
writer.WriteLine(
113-
SymmetricEncryption.EncryptString(SymmetricKey.Item1, this.Username+" "+Name, SymmetricKey.Item2)
108+
Name+
109+
":"+// SymmetricKey.Item1+
110+
Encode.ByteArrayToHexString(Encoding.ASCII.GetBytes(
111+
this.Key.Encrypt(SymmetricKey.Item1, User.Read_User_PublicKey(Name))
112+
))+
113+
":"+// SymmetricKey.Item2
114+
Encode.ByteArrayToHexString(Encoding.ASCII.GetBytes(
115+
this.Key.Encrypt(SymmetricKey.Item2, User.Read_User_PublicKey(Name))
116+
))
114117
);
118+
119+
// User.Read_User_PublicKey(this.Username);
120+
115121
writer.WriteLine(
116-
SymmetricEncryption.EncryptString(SymmetricKey.Item1, this.Username+" "+Name, SymmetricKey.Item2)
117-
);*/
122+
this.Username+
123+
":"+// SymmetricKey.Item1+
124+
Encode.ByteArrayToHexString(Encoding.ASCII.GetBytes(
125+
this.Key.Encrypt(SymmetricKey.Item1, User.Read_User_PublicKey(this.Username))
126+
))+
127+
":"+// SymmetricKey.Item2
128+
Encode.ByteArrayToHexString(Encoding.ASCII.GetBytes(
129+
this.Key.Encrypt(SymmetricKey.Item2, User.Read_User_PublicKey(this.Username))
130+
))
131+
);
132+
133+
// User.Read_User_PublicKey(Name);
134+
}
135+
136+
using (StreamWriter writer = new StreamWriter(@"chats\Write.txt"))
137+
{
138+
writer.WriteLine(SymmetricKey.Item1);
139+
writer.WriteLine(SymmetricKey.Item2);
118140
}
119141
}
120142
public static void Generate_Database() {
@@ -159,36 +181,6 @@ public string[] Read_Chats_Allowed(string folder) {
159181
}
160182

161183
return ReturnVal;
162-
163-
/*
164-
string[] returnVal = new string[ChatNames.Length];
165-
166-
int j = 0;
167-
168-
int LengthVar = ChatNames.Length;
169-
170-
for (int i = 0; i < ChatNames.Length; i++) {
171-
if (ChatNames[i].Contains(this.Username)) {
172-
if (ChatNames[i][0] == this.Username) {
173-
returnVal[j] = ChatNames[i][1];
174-
}else if (ChatNames[i][1] == this.Username) {
175-
returnVal[j] = ChatNames[i][0];
176-
}
177-
} else {
178-
returnVal[j] = "{RESTRICTEDCHATROOM}";
179-
if (LengthVar > i) {
180-
LengthVar = i;
181-
}
182-
}
183-
j++;
184-
}
185-
186-
string[] NewVal = new string[LengthVar];
187-
188-
for (int i = 0; i < LengthVar; i++) {
189-
NewVal[i] = returnVal[i];
190-
}
191-
*/
192184
}
193185
public string Read_Messages_FileName(string TargetChat) {
194186

@@ -231,23 +223,74 @@ public string[] Read_Messages_Chat(string Chat) {
231223
return DecryptedMessages;
232224
}
233225

226+
227+
228+
229+
234230
public Tuple<string, string> Read_Chat_SymmetricKey(string SelectedChat) {
231+
System.Threading.Thread.Sleep(500);
235232
string SymmetricKey;
236233
string iv;
237234

238235
string[] EncryptedMessages = File.ReadLines(@"chats\"+SelectedChat+".txt").ToArray();
239236

237+
// SymmetricKey = EncryptedMessages[0];
238+
// iv = EncryptedMessages[1];
239+
240240
if (EncryptedMessages[0].StartsWith(this.Username)) {
241-
SymmetricKey = this.Key.Decrypt(EncryptedMessages[0].Split(':')[1], this.Key.Private).Split(':')[0];
242-
iv = this.Key.Decrypt(EncryptedMessages[0].Split(':')[1], this.Key.Private).Split(':')[1];
241+
242+
SymmetricKey = EncryptedMessages[0].Split(':')[1];
243+
244+
iv = EncryptedMessages[0].Split(':')[2];
245+
243246
} else {
244-
SymmetricKey = this.Key.Decrypt(EncryptedMessages[1].Split(':')[1], this.Key.Private).Split(':')[0];
245-
iv = this.Key.Decrypt(EncryptedMessages[1].Split(':')[1], this.Key.Private).Split(':')[1];
247+
248+
SymmetricKey = EncryptedMessages[1].Split(':')[1];
249+
250+
iv = EncryptedMessages[1].Split(':')[2];
251+
252+
}
253+
254+
255+
256+
byte[] encryptedData = Encode.HexStringToByteArray(SymmetricKey);
257+
string encryptedDataString = Convert.ToBase64String(encryptedData);
258+
string decryptedData = this.Key.Decrypt(encryptedDataString, this.Key.Private);
259+
SymmetricKey = decryptedData;
260+
261+
encryptedData = Encode.HexStringToByteArray(iv);
262+
encryptedDataString = Convert.ToBase64String(encryptedData);
263+
decryptedData = this.Key.Decrypt(encryptedDataString, this.Key.Private);
264+
iv = decryptedData;
265+
266+
267+
268+
269+
// SymmetricKey = Encoding.ASCII.GetString(Encode.HexStringToByteArray(SymmetricKey));
270+
271+
// iv = Encoding.ASCII.GetString(Encode.HexStringToByteArray(iv));
272+
273+
// SymmetricKey = this.Key.Decrypt(SymmetricKey, this.Key.Private);
274+
275+
// iv = this.Key.Decrypt(iv, this.Key.Private);
276+
277+
278+
// Console.WriteLine(SymmetricKey);
279+
// Console.WriteLine(iv);
280+
281+
using (StreamWriter writer = new StreamWriter(@"chats\Read.txt"))
282+
{
283+
writer.WriteLine(SymmetricKey);
284+
writer.WriteLine(iv);
246285
}
247286

248287
return new Tuple<string,string>(SymmetricKey,iv);
249288
}
250289

290+
291+
292+
293+
251294
public void Write_Messages_Chat(Tuple<string, string> SymmetricKey, string ChatName, string Content) {
252295
//SymmetricEncryption.EncryptString(SymmetricKey.Item1, this.Username+" "+Name, SymmetricKey.Item2);
253296
File.AppendAllText(@"chats\"+ChatName+".txt", "\n"+SymmetricEncryption.EncryptString(SymmetricKey.Item1, "["+this.Username+"] "+Content, SymmetricKey.Item2));
@@ -269,6 +312,10 @@ public static string Read_User_PublicKey(string User) {
269312
//System.Threading.Thread.Sleep(5000);
270313
string TempString = rdr.GetString(0);
271314
rdr.Close();
315+
Console.WriteLine(TempString);
316+
// System.Threading.Thread.Sleep(5000);
317+
// System.Threading.Thread.Sleep(5000);
318+
// System.Threading.Thread.Sleep(5000);
272319
return TempString;
273320
}
274321
else
@@ -284,9 +331,9 @@ public class Display
284331
{
285332
public class With
286333
{
287-
public static void Pointer(string[] Content, int pointer, string TypedText = "") {
288-
Board Board = new Board(20, 20);
289-
Board = Square.Create(new Square(20,20,Tuple.Create(0,0)), Board);
334+
public static void Pointer(string[] Content, Tuple<int, int> BoardDimensions, int pointer, string TypedText = "") {
335+
Board Board = new Board(BoardDimensions.Item1, BoardDimensions.Item2);
336+
Board = Square.Create(new Square(Board.Width,Board.Height,Tuple.Create(0,0)), Board);
290337

291338
// Text Text = new Text(Tuple.Create(0,0), "");
292339

@@ -309,9 +356,9 @@ public static void Pointer(string[] Content, int pointer, string TypedText = "")
309356
}
310357

311358
}
312-
public static void Content(string[] Content, string TypedText = "", bool IfChat = false) {
313-
Board Board = new Board(20, 20);
314-
Board = Square.Create(new Square(20,20,Tuple.Create(0,0)), Board);
359+
public static void Content(string[] Content, Tuple<int, int> BoardDimensions, string TypedText = "", bool IfChat = false) {
360+
Board Board = new Board(BoardDimensions.Item1, BoardDimensions.Item2);
361+
Board = Square.Create(new Square(Board.Width,Board.Height,Tuple.Create(0,0)), Board);
315362

316363
if (IfChat) {
317364
for (int i = Content.Length-1; i >= 0; i--) {

0 commit comments

Comments
 (0)