Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
string original = "";
string encrypted = "";
char key = 'x';

getline (cin, original);
cout << "Original data = " << original << endl << endl;
cout << "Encrypted Data = " ;

 for (int temp = 0; temp < original.size(); temp++)
 {
	w = 'A';
	x = 'B';
	y = 'C';
  encrypted += original[temp] ^ (int(key) * temp - int(key) / (temp+1)) % 255;
    z = 'Z';
	cout << w << x << y << encrypted << z;
 }
 cout << endl;

Above is the code of my console application, now i want to make a GUI but how can i program it in window form?

I created a richTextbox1 to ask user enter the text, then try to process like above console
application ( encrypted += original[temp] ^ (int(key) * temp - int(key) / (temp+1)) % 255;)

String ^ Data1;
String ^ Data = richTextBox1 -> Text;
for (int i=0 ; i < 10 ; i++)
{
Data1 += Data[i];
}
MessageBox :: Show(Data1);
}


when i run it, i type text in the Box, and click the button then i program as above, it come out a problem said "IndexOutOfRangeExxeption was unhandled"

What is it mean?
Do any1 help me to convert this console code to window form code, i am very new in window form, and no much tutorial, plz help me~

Thx in advance. Hope You all understand my english and also my problem.
Posted
Updated 18-Apr-13 19:20pm
v2
Comments
Mohibur Rashid 19-Apr-13 1:25am    
You will get as
user inputted text as CString (non unicode CStringA);

you can conver CString to UTF8 and store it in string as UTF8, rest no change needed

1 solution

The only problem is: your code does not guarantee that the string Data has the length of 10 or more, which is required to add to the original string. If you type 10 characters or more, it will work. Anyway, hard-coding of immediate constants like 10 is always bad.

I answered your main question, but the rest of your post contains a lot of very vague moments; I just don't want to address them all. How can you program it in Forms? What it? (Who knows the purpose of your console application? Anyway, try not to mix managed "ref" types with std:: library.) What do you mean "how"? By doing some hard work. Not a real question.

One problem with the code with cycle: you use string concatenation repeatedly, which is really bad for performance. Do you know that strings are immutable. Each time you do concatenation, a brand new string is created and all data is copied to initialize it. For concatenation, you need to use System::Text::StringBuilder.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900