View Single Post
Old 05-13-2004, 08:46 PM   #3 (permalink)
Amaranthine
Registered User
 
Amaranthine's Avatar
 
Join Date: May 2004
Posts: 47
Amaranthine is on a distinguished road
thankyou very much, I face a new problem.
Code:
void CWinEncrypterDoc::OnOptionEncrypt() 
{
        CWinEncrypterView* aView = CWinEncrypterView::GetView();// get current view
	char* buffer = NULL;    // create holder for text
	int length = aView->GetWindowTextLength();    // get text length
	length++;	// add room for terminating character
	buffer = new char[length];	// set buffer equal to size of text in view
	CString encrypted;    // initialize encryption holding CString
	aView->GetWindowText(buffer,length);    // get the text and store in buffer
	// loop through and xor accordingly
	for(int i = 0; i < length; i++)
		encrypted += buffer[i] |= static_cast<char>(m_Seed);
	// output encrypted text
	CEncryptedDlg aDlg;
	aDlg.m_Encrypted = encrypted;    // set text to show to encrypted text
	aDlg.DoModal();    // show dialog with xored text
}
I wrote this program in assembly a while back, but it got the text out of a file and was a 16 bit program.
This one works kind-of, but when you try to "decrypt"(un-xor) the text by simply xoring it again with the same value it just spits out the same value, why?
Is there an error in my logic?

(GetView() is a function I made that returns a pointer to the current view)
Amaranthine is offline   Reply With Quote