XOR encrypt decrypt help

Hello, i have function to encrypt & decrypt string with XOR, but i have problem, when i encrypt some string, then sometimes encrypted string have newline in a string and when i write it into file, then my string is on two lines and i cant read it with reader->ReadLine(), because i get only part of a string. How can i write with StreamWriter write->WriteLine on one line with newline chars etc? Thanks

Function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
static String ^ XOR_S(String ^ value, String ^ key)
{
	std::string retval(marshal_as<string>(value));
	short unsigned int klen = key->Length;
	short unsigned int vlen = value->Length;
	short unsigned int k = 0;
	short unsigned int v = 0;

	for (v; v < vlen; v++)
	{
		retval[v] = value[v] ^ key[k];
		k = (++k < klen ? k : 0);
	}

	return marshal_as<String^>(retval);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private: System::Void barButtonItem1_ItemClick(System::Object^  sender, DevExpress::XtraBars::ItemClickEventArgs^  e) {
		StreamWriter^ writer = gcnew StreamWriter("encryptdecrypt.txt");
		String^ text = barEditItem1->EditValue->ToString();
		text = XOR_S(text, "key123");
		writer->WriteLine(text);
		MessageBox::Show(text);
		writer->Close();
	}
	private: System::Void barButtonItem2_ItemClick(System::Object^  sender, DevExpress::XtraBars::ItemClickEventArgs^  e) {
		StreamReader^ reader = gcnew StreamReader("encryptdecrypt.txt");
		String^ text = reader->ReadLine();
		text = XOR_S(text, "key123");
		MessageBox::Show(text);
		reader->Close();
	}


output file: http://prntscr.com/bbcms4 this is encrypted "testovacie slovo kofola" string.

Thanks for help
and for example, decryptet string is only "te" not full string "testovacie slovo kofola"
i think i mus use writer->Write and then make while(text = reader->ReadLine()) and put into file split char for example when file readsline, then make decryptedstring+=decryptedstring and when program find split char for example <<>> then decryptedstring = "" and again for next encrypted string lines
Topic archived. No new replies allowed.