|
// dctdialog.cpp : implementation file
//
#include "stdafx.h"
#include "eikona.h"
#include "dctdialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// dctdialog dialog
dctdialog::dctdialog(CWnd* pParent /*=NULL*/)
: CDialog(dctdialog::IDD, pParent)
{
//{{AFX_DATA_INIT(dctdialog)
m_message ="You can put here the creators / owners name, date of creation, copyright notice or anything that will confirm the owner";
m_key ="";
m_result ="UnScrambled";
//}}AFX_DATA_INIT
}
void dctdialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(dctdialog)
DDX_Text(pDX, IDC_MESSAGE, m_message);
DDX_Text(pDX, IDC_KEY, m_key);
DDX_Text(pDX, IDC_RESULT, m_result);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(dctdialog, CDialog)
//{{AFX_MSG_MAP(dctdialog)
ON_BN_CLICKED(IDC_SCRAMBLE, OnScramble)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// dctdialog message handlers
void dctdialog::OnScramble()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_message.GetLength()<m_key.GetLength())
AfxMessageBox("Key can't be longer than the message!");
else
{
if (m_key.GetLength()!=8)
AfxMessageBox("8 - digits");
else
{
int length=m_message.GetLength();
unsigned char *message=new unsigned char[length];
for (int j=0;j<length;j++)
message[j]=m_message[j];
for (int k=0;k<length;k=k+8)
{
if (k+8>length)
break;
message[k+0]^=m_key[0]; //xoring every 8 bytes
message[k+1]^=m_key[1];
message[k+2]^=m_key[2];
message[k+3]^=m_key[3];
message[k+4]^=m_key[4];
message[k+5]^=m_key[5];
message[k+6]^=m_key[6];
message[k+7]^=m_key[7];
}
m_message.Empty();
for (int q=0;q<length;q++)
m_message+=message[q];
m_result="Scrambled";
delete message;
}
}
UpdateData(FALSE);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.