// EncryptImageDialog.cpp // implementation file #include "stdafx.h" #include "encryptthis.h" "-"include "EncryptImageDialog.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[) = __ FILE __ ; #endif ///////////////////////////////////////////////////////////////////////////// // EncryptImageDialog dialog EncryptImageDialog: : EncryptImageDialog (CWnd* pParent /*=NULL*/) : CDialog(EncryptImageDialog: :IDD, pParent) //{{AFX_DATA_INIT(EncryptImageDialog) //}}AFX_DATA_INIT void EncryptImageDialog: : DoDataExchange (CDataExchange* pDX) { CDialog: : DoDataExchange (pDX) ; //{{AFX_DATA_MAP(EncryptImageDialog) DDX_Control(pDX, IDC_PROGRESS1, m_Progress); //}}AFX_DATA_MAP BEGIN_MESSAGE_MAP(EncryptImageDialog, CDialog) //{{AFX_MSG_MAP(EncryptImageDialog) // NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAP --END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // EncryptImageDialog message handlers 1 #if !defined(AFX_ENCRYPTIMAGEDIALOG_H__ E4C49521_ED2F_11D2_ADF2_A228685DC33C __ INCLUDED_) #define AFX_ENCRYPTIMAGEDIALOG_H__ E4C49521_ED2F_11D2_ADF2_A228685DC33C __ INCLUDED_ #if _MSC_VER > 1000 #pragma once ~endif // _MSC_VER > 1000 / EncryptImageDialog.h : header file // ///////////////////////////////////////////////////////////////////////////// // EncryptImageDialog dialog class EncryptImageDialog : public CDialog { // Construction pUblic: EncryptImageDialog(CWnd* pParent NULL); // standard constructor // Dialog Data //{{AFX_DATA(EncryptImageDialog) enum { IDD = IDD_DIALOG5 }; CProgressCtrl m_Progress; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(EncryptImageDialog) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: ~ // Generated message map functions //{{AFX_MSG(EncryptImageDialog) // NOTE: the ClassWizard will add member functions here //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual c++ will insert additional declarations immediately before the previous line. 1 // EncryptThis.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "EncryptThis.h" "...... include #include #include #include "MainFrm.h" "ChildFrm.h" "EncryptThisDoc.h" "EncryptThisView.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[) #endif = __ FILE __ ; ///////////////////////////////////////////////////////////////////////////// // CEncryptThisApp BEGIN_MESSAGE_MAP(CEncryptThisApp, CWinApp) //{{AFX_MSG_MAP(CEncryptThisApp) ON COMMAND(ID APP ABOUT, OnAppAbout) - // NOTE --the-ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP // Standard file based document commands ON_COMMAND (ID_FILE_NEW, CWinApp: :OnFileNew) ON_COMMAND (ID_FILE_OPEN, CWinApp: :OnFileOpen) // Standard print setup command ON_COMMAND (ID_FILE_PRINT_SETUP, CwinApp: :OnFilePrintSetup) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEncryptThisApp construction CEncryptThisApp::CEncryptThisApp() { ~ // TODO: add construction code here, // Place all significant initialization in InitInstance ///////////////////////////////////////////////////////////////////////////// // The one and only CEncryptThisApp object CEncryptThisApp theApp; ///////////////////////////////////////////////////////////////////////////// // CEncryptThisApp initialization BOOL CEncryptThisApp: :InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef AFXDLL Enable3dControls(); #else Enable3dControlsStatic() ; #endif // Call this when using MFC in a shared DLL // Call this when linking to MFC statically // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; 1 ~ pDocTemplate = new CMultiDocTemplate( IDR_ENCRYPTYPE, RUNTIME_CLASS (CEncryptThisDoc) , RUNTIME_CLASS (CChildFrame), // custom MDI child frame RUNTIME_CLASS(CEncryptThisView)) ; AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m-pMainWnd = pMainFrame; // Enable drag/drop open m-pMainWnd->DragAcceptFiles(); // Enable DDE Execute open EnableShellOpen() ; RegisterShellFileTypes(TRUE); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo) ; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow) ; pMainFrame->UpdateWindow() ; return TRUE; ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About .,-class CAboutDlg : public CDialog public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() } ; CAboutDlg: :CAboutDlg() : CDialog(CAboutDlg: :IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT void CAboutDlg: : DoDataExchange (CDataExchange* pDX) { CDialog::DoDataExchange(pDX); ~ //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 2 //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ~I App command to run the dialog oid CEncryptThisApp: :OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal() ; ///////////////////////////////////////////////////////////////////////////// // CEncryptThisApp commands 3 // EncryptThis.h : main header file for the ENCRYPTTHIS application // <- - --- - - - - -- - #if !defined(AFX_ENCRYPTTHIS_H__ 66759686_A327_11D2_B20A_444553540000 __ INCLUDED_) #define AFX ENCRYPTTHIS H 66759686 A327 11D2 B20A 444553540000 INCLUDED if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols /////1//1////////////////////////////////////////////////////////////1//////1 // CEncryptThisApp: // See EncryptThis.cpp for the implementation of this class // class CEncryptThisApp : public CWinApp { public: CEncryptThisApp() ; // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEncryptThisApp) pUblic: virtual BOOL InitInstance(); //}}AFX_VIRTUAL // Implementation //{{AFX_MSG(CEncryptThisApp) afx_msg void OnAppAbout(); // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code! / /} }AFX_MSG DECLARE_MESSAGE_MAP() }; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / ///////////////1/////// //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. 1 // EncryptThisDoc.cpp II implementation of the CEncryptThisDoc class #include "stdafx.h" #include "EncryptThis.h" ".... include "EncryptThisDoc.h" #include "EncryptAlgorithrn.h" #include "Progress.h" #include <fstream> using namespace std; #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__ ; #endif ///////////////////////////////////////////////////////////////////////////// // CEncryptThisDoc IMPLEMENT_DYNCREATE(CEncryptThisDoc, CDocument) BEGIN_MESSAGE_MAP(CEncryptThisDoC, CDocument) //{{AFX_MSG_MAP(CEncryptThisDoc) ON_COMMAND (ID_ENCRYPTION_OPTIONS, OnEncryptionOptions) ON_COMMAND (ID_ENCRYPTION_ENCRYPTTHIS, OnEncryptionEncryptThis) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEncryptThisDoc construction/destruction CEncryptThisDoc::CEncryptThisDoc() { encObj=NULL; .EncryptThisDoc: :-CEncryptThisDoc() { if(encObj!=NULL) delete encObj; BOOL CEncryptThisDoc: :OnNewDocument() { if (!CDocument: :OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return FALSE; ///////////////////////////////////////////////////////////////////////////// // CEncryptThisDoc serialization void CEncryptThisDoc::Serialize(CArchive& ar) { CString filename; // Filename of the file the user // wishes to load ifstream bmpifile; // File stream used to load up II the user selected file of stream bmpofile; /I File stream used to write out /I the user selected file int x, y; int width, height; /I Used for looping /I Width and height of the bitmap /I loaded ,..... 1 UBYTEl r, g, b; // Red, green, and blue values at // a selected pixel of the bitmap CDC dcMem; // Memory DC used to create the // bitmap image for later display CClientDC *background; // Represents the current DC being // used by our window CProgress *prog_dialog; // Dialog box to display how far // along the load process is POSITION pos; // Position variable used to find // the current view // Get the position of the first view pos=GetFirstViewPosition() ; // Initialize background so it actually holds // the DC currently being used by our window background=new CClientDC(GetNextView(pos)); // Create our memory DC so that it is compatible // with the DC currently being used. Otherwise // the bitmap might not be displayed correctly // (ie. wrong bits per pixel) dcMem.CreateCompatibleDC(background) ; // Get the filename and path of the file selected // by user from dialog filename=ar.GetFile()->GetFilePath(); // Convert the path and filename from above from // Win95 long filename format to short filename // format for the pfile fstream GetShortPathName(filename, filename.GetBuffer(filename.GetLength()), if (ar.IsStoring()) { // If no encryption method has been chosen ... if (encObj==NULL) { // Use the BmpEncoder's default saving method // Open the file for output bmpofile.open(filename, ios: :binary); // Write out the image bmpEnc.WriteImage(bmpofile, bmpData); // Close the output file bmpofile.close() ; else { // Otherwise we have the encryption object do the // saving encObj->SaveEncData(filename); else { /1 Create the progress dialog box and display it prog_dialog=new CProgress(); prog_dialog->Create(IDD_DIALOG2); prog_dialog->ShowWindow(SW_SHOW) ; // Open the file containing the data that // the user has chosen. bmpifile.open(filename, ios::binary); 1/ Use BMPDecoder to decode the chosen file 1/ into it's BitmapImage bmpDec.Readlmage(bmpifile, bmpData); 2 filename.GetLength()); // Display the value being stored in the first // row and column of the bitmap for debugging // AfxMessageBox(CString((char)bmpData[O] [0])); // Close the stream bmpifile.close() ; // Initialize the width and height values // to reflect the loaded bitmap width=bmpData.width(); height=bmpData.Height(); // // // if If this doesn't equal NULL, then we have a bitmap loaded already and should delete it before attempting to load another one (bData.m_hObject != NULL) bData.DeleteObject(); // get rid of old bitmap // (Re)Initialize the bitmap so that it is // compatible with the DC currently being // used by our window. This needs to be done // for the same reason the memory DC has to // be initialized to be compatible with the // current DC. bData. CreateCompatibleBitmap (background, width, height); bData.SetBitmapDimension(width, height); // Make sure the creation of the bitmap // succeeded ASSERT(bData.m_hObject != NULL); // Create a bitmap and have it hold the bitmap // that was selected into the memory DC CBitmap* pOldBitmap = dcMem.SelectObject(&bData); // Setup progress indicator prog_dialog->m_Progress.SetRange(O, height); prog_dialog->m_Progress.SetStep(l); prog_dialog->m_Progress.SetPos(O); // For each row in the bitmap ... for(y=O; y<height; y++) { // For each column in the bitmap ... for(x=O; x<width; x++) { // Get the red, green, and blue // values at the (x, y) pixel bmpData.GetRGB(y, x, r, g, b); // Write the corresponding pixel // to our memory DC using the // retrieved RGB values dcMem.SetPixel(x, y, RGB(r,g,b)); prog_dialog->m_Progress.StepIt(); prog_dialog->DestroyWindow() ; // Select the bitmap that was being used // before back into the memory DC dcMem.SelectObject(pOldBitmap); // Delete the copy of the CClientDC delete background; // Release the memory DC for Windows dcMem.DeleteDC() ; ///////////////////////////////////////////////////////////////////////////// // CEncryptThisDoc diagnostics 3 #ifdef DEBUG void CEncryptThisDOC: :AssertValid() const { CDocument: :AssertValid(); void CEncryptThisDOC: : Dump (CDumpContext& dc) const { CDocument: :Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CEncryptThisDoc commands void CEncryptThisDoc::SetEncAlgorithm(EncryptAlgorithm *encAlgorithm) { if(encObj!=NULL) delete encObj; encObj=encAlgorithm; } void CEncryptThisDoc: :OnEncryptionOptions() { if(encObj!=NULL) encObj->GetOptions(); else AfxMessageBox("No encryption method selected. Method menu and try again."); Select a method from the EncryptionlChoose } void CEncryptThisDoc: :OnEncryptionEncryptThis() { ~od if(encObj!=NULL) encObj->EncryptThis(&bmpData); else AfxMessageBox("No encryption method selected. menu and try again."); void CEncryptThisDOC: :Enable() { if(encObj!=NULL) encObj->Enable(); void CEncryptThisDoc: :Disable() { if(encObj!=NULL) encObj->Disable(); CBitmap* CEncryptThisDoc::Getlmage() { if(encObj!=NULL) return encObj->GetDisplaylmage(); else return &bData; 4 Select a method from the Encrypt IChoose Met // EncryptThisDoc.h : interface of the CEncryptThisDoc class II ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_ENCRYPTTHISDOC_H__ 6675968E_A327_11D2_B20A_444553540000 __ INCLUDED_) AFX_ENCRYPTTHISDOC_H__ 6675968E_A327_11D2_B20A_444553540OOO __ INCLUDED_ ~define #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include "EncryptAlgorithm.h" class CEncryptThisDoc : public CDocument { protected: // create from serialization only CEncryptThisDoc(); DECLARE_DYNCREATE(CEncryptThisDoc) // Attributes public: CBitmap bData; BitmapImage bmpData; protected: BmpEncoder bmpEnc; BmpDecoder bmpDec; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEncryptThisDoc) public: virtual BOOL OnNewDocument(); virtual void Serialize(CArchive& ar); //}}AFX_VIRTUAL - '/ Implementation public: CBitmap* GetImage(); void Disable(); void Enable(); void SetEncAlgorithm(EncryptAlgorithm *encAlgorithm); virtual -CEncryptThisDoc(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: EncryptAlgorithm* encObj; //{{AFX_MSG(CEncryptThisDoc) afx_msg void OnEncryptionOptions(); afx_msg void OnEncryptionEncryptThis(); / / } }AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. 1 implementation of the CEncryptThisView class // EncryptThisView.cpp II #include "stdafx.h" #include "EncryptThis.h" ..-... include #include #include #include "EncryptThisDoc.h" "EncryptThisView.h" "ShareAlgorithm.h" "TwoOfTwoAlgorithm.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__ ; #endif ///////////////////////////////////////////////////////////////////////////// // CEncryptThisView IMPLEMENT_DYNCREATE(CEncryptThisView, CScrollView) BEGIN_MESSAGE_MAP{CEncryptThisView, CScrollView) //{{AFX_MSG_MAP(CEncryptThisView) ON_COMMAND (BWENC, OnBWENC) ON_UPDATE_COMMAND_UI(BWENC, OnUpdateBWENC) ON_WM_KILLFOCUS() ON_WM_SETFOCUS{) ON_COMMAND {TWO_OF_TWO, OnOfTwo) ON_UPDATE_COMMAND_UI(TWO_OF_TWO, OnUpdateOfTwo) ON_COMMAND {K_OF_K, OnKOfK) ON_UPDATE_COMMAND_UI(K_OF_K, OnUpdateKOfK) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND {ID_FILE_PRINT, CScrollView::OnFilePrint) ON_COMMAND {ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) ON_COMMAND {ID_FILE_PRINT_PREVIEW, CScrollView: :OnFilePrintPreview) END_MESSAGE_MAP() /1////////////1///////////////////1//11/1///////////1//1///1//////////1///// // CEncryptThisView construction/destruction CEncryptThisView::CEncryptThisView() { // TODO: add construction code here encMethod=-l; CEncryptThisView: :-CEncryptThisView() { } BOOL CEncryptThisView: :PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CScrollView: :PreCreateWindow(cs); //1/////11//1///11///1//11////////11/11/11//1/1/////11/11//////1/11//1//11/// /1 CEncryptThisView drawing void CEncryptThisView::OnDraw{CDC* pDC) { /1 Get the current document. This is // inserted automatically by VC++ CEncryptThisDoc* pDoc GetDocument{); ASSERT_VALID(pDoc); CDC dcMem; CBitmap* pbmOld // // // // NULL; Temporary DC. We draw the bitmap on this DC first and then copy it over to the visible DC for faster display // Temporary bitmap to hold the 1 // bitmap which was selected by // the dcMem DC CBitmap* image=pDoc->GetImage(); // Image to be displayed CSize sizeTotal; // // // // This is passed to SetScrollSizes to determine how much the window should be allow to scroll both vertically and horizontally int width=(image->GetBitmapDimension()) .cx; // Width of bitmap to be // displayed int height=(image->GetBitmapDimension()) .cy; // Height of bitmap to be // displayed CString tmp; tmp.Format("width: %d, height: %d", width, height); //AfxMessageBox(tmp); // Set the scroll sizes based on the bitmap's // width and height sizeTotal.cx = width; sizeTotal.cy = height; SetScrollSizes(MM_TEXT, sizeTotal); // // // if If the bitmap hasn't been initialized yet, simply return since we have nothing to display (image->m_hObject == NULL) { AfxMessageBox( "Bleh!"); return; // no bitmap to show // Prepare the memory DC dcMem.CreateCompatibleDC(pDC); ~ // Select the bitmap into the memory DC pbmOld = dcMem.SelectObject(image); // Copy the image from (0, 0) to (width, height) // in the memory DC(dcMem) to the current visible // DC (pDC) starting the image at (0, 0) pDC->BitBlt(O, 0, width, height, &dcMem, 0, 0, SRCCOPY); // Replace the bitmap that was selected before we // select our own bitmap dcMem.SelectObject(pbmOld); // Release the DC for Windows to use dcMem.DeleteDC(); ///////////////////////////////////////////////////////////////////////////// // CEncryptThisView printing BOOL CEncryptThisView: :OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); void CEncryptThisView: :OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing void CEncryptThisView: :OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing ///////////////////////////////////////////////////////////////////////////// // CEncryptThisView diagnostics 2 #ifdef DEBUG void CEncryptThisView: :AssertValid() const { CView: :AssertValid(); ~ .oid CEncryptThisView: : Dump (CDumpContext& dc) const { CView: : Dump (dc) ; CEncryptThisDoc* CEncryptThisview: :GetDocument() II non-debug version is inline { ASSERT (m-pDocument->IsKindOf (RUNTIME_CLASS (CEncryptThisDoc ))); return (CEncryptThisDoc*)m-pDocument; } #endif I I _DEBUG 11////////////////////1/////////////////////////////// /////////////////////// 1/ CEncryptThisView message handlers void CEncryptThisView: :OnBWENC() { if (encMethod!=l) { CEncryptThisDoc* pDoc = GetDocument(); ShareAIgorithm *shareAIg=new ShareAIgorithm(pDoc->GetImage(), this); encMethod=l; pDoc->SetEncAlgorithm(shareAlg); void CEncryptThisView: :OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { /1 TODO: Add your specialized code here and/or call the base class CScrollView: :OnPrepareDC(pDC, pInfo); void CEncryptThisView: :OnInitiaIUpdate() { CScrollView: :OnIni~iaIUpdate(); CSize sizeTotal; 1/ TODO: calculate the total size of this view sizeTotal.cx = sizeTotal.cy = 100; SetScroIISizes(MM_TEXT, sizeTotal); void CEncryptThisview::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { /1 TODO: Add your specialized code here and/or call the base class CScrollView: : OnActivateView (bActivate, pActivateView, pDeactiveView); void CEncryptThisview: :OnUpdateBWENC(CCmdUI* pCmdUI) ( if (encMethod==l) pCmdUI->SetCheck(); else pCmdUI->SetCheck(O); BOOL CEncryptThisView: :IsSelected(const CObject* pDocItem) const { /1 TODO: Add your specialized code here and/or call the base class return CScrollView: :IsSelected(pDocltem); ~id CEncryptThisView: :OnKiIIFocus(CWnd* pNewWnd) { CEncryptThisDoc* pDoc = GetDocument(); 3 CScrollView: :OnKillFocus(pNewWnd); pDoc->Disable(); -')id CEncryptThisView: : OnSetFocus (CWnd* pOldWnd) CEncryptThisDoc* pDoc = GetDocument(); CScrollView: :OnSetFocus(pOldWnd); pDoc->Enable(); void CEncryptThisview: :OnOfTwo() { if (encMethod!=2) { CEncryptThisDoc* pDoc=GetDocument(); TwoOfTwoAlgorithm *twoAlg=new TwoOfTwoAlgorithm(pDoc->GetImage(), this); encMethod=2; pDoc->SetEncAlgorithm(twoAlg) ; void CEncryptThisView: :OnUpdateOfTwo(CCmdUI* pCmdUI) { if (encMethod==2) pCmdUI->SetCheck(); else pCmdUI->SetCheck(O); void CEncryptThisView: :OnKOfK() { - II TODO: Add your command handler code here if (encMethod!=3) { CEncryptThisDoc* pDoc=GetDocument(); KOfKAlgorithm *kAlg=new KOfKAlgorithm(pDoc->GetImage(), this); encMethod=3; pDoc->SetEncAlgorithm(kAlg); void CEncryptThisView: :OnUpdateKOfK(CCmdUI* pCmdUI) { II TODO: Add your command update UI handler code here i f (encMethod==3) pCmdUI->SetCheck(); else pCmdUI->SetCheck(O); 4 II EncryptThisView.h : interface of the CEncryptThisView class 1/ 1111111111111111111111/111111111111111111111111111111111111111111111111111111 ~if !defined(AFX_ENCRYPTTHISVIEW_H__ 66759690_A327_11D2_B20A_444553540000 __ INCLUDED_) iefine AFX_ENCRYPTTHISVIEW_H__ 66759690_A327_11D2_B20A_44455354OOOO __ INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif II _MSC_VER >= 1000 class CEncryptThisView : public CScrollView { protected: II create from serialization only CEncryptThisView() ; DECLARE_DYNCREATE(CEncryptThisView) 1/ Attributes public: CEncryptThisDoc* GetDocument(); protected: CDC *bmpDC; int encMethod; 1/ Operations public: 1/ Overrides - // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEncryptThisView) public: virtual void OnDraw(CDC* pDC); 1/ overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL); virtual void OnInitialUpdate(); virtual BOOL IsSelected(const CObject* pDocItem) const; protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView); /I}}AFX_VIRTUAL 1/ Implementation pUblic: virtual -CEncryptThisView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: /1{{AFX_MSG(CEncryptThisView) afx_msg void OnBWENC(); afx_msg void OnUpdateBWENC(CCmdUI* pCmdUI); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg void OnOfTwo(); afx_msg void OnUpdateOfTwo(CCmdUI* pCmdUI); afx_msg void OnKOfK(); afx_msg void OnUpdateKOfK(CCmdUI* pCmdUI); I/}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef DEBUG II debug version in EncryptThisView.cpp inline CEncryptThisDoc* CEncryptThisview: :GetDocument() { return (CEncryptThisDoc*)m-pDocument; } --=ndif /11/111111//11//111111//11//11111111//1//1//1111//1//11/1//11111/11//11//11/1 /I{{AFX_INSERT_LOCATION}} 1 II Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif II !defined(AFX_ENCRYPTTHISVIEW_H__ 66759690_A327_11D2_B20A_444553540000 __ INCLUDED_) ~ 2 II KOfKAlgorithm.cpp: /! implementation of the KOfKAlgorithm class. 1111111111111111111111111111111111111111111111111111111111111111111111 #include "stdafx.h" ""--include "encryptthis.h" "include "KOfKAlgorithm.h" #ifdef DEBUG #undef THIS_FILE static char THIS_FILE[)= __FILE __ ; #define new DEBUG_NEW #endif 1111111111111111111111111111111111111111111111111111111111111111111111 II Construction/Destruction 1111111111111111111111111111111111111111111111111111111111111111111111 KOfKAlgorithm: : KOfKAlgorithm (CBitmap *img, CView *cwin) ShareAlgorithm(img, cwin) koptDialog=new KOfKOptionsDialog(); koptDialog->Create(IDD_DIALOG6); KOfKAlgorithm::KOfKAlgorithm() { KOfKAlgorithm::-KOfKAlgorithm() { void KOfKAlgorithm::GetOptions() { koptDialog->Showwindow(SW_SHOW) ; void KOfKAlgorithm::EncryptThis(BitmapImage *bmpImage) { optDialog->m_totalShares = koptDialog->m-participants; ShareAlgorithm: : EncryptThis (bmpImage) ; Matrix* KOfKAlgorithm::ConstQualMatrix(int participants) { Matrix* kQual=new Matrix (participants , 1); for(int x=O; x<participants; x++) { (*kQual) [x) [0)=1; return kQual; 1 // KOfKAlgorithm.h: interface for the KOfKAlgorithm class. /! ////////////////////////////////////////////////////////////////////// #if ! defined (AFX_KOFKALGORITHM_H__B0068C41_F4DB_11D2_ADF2_DFC F6F73B63D__ INCLUDED ) - ~jefine AFX_KOFKALGORITHM_H__B0068C41_F4DB_11D2_ADF2_DFCF6F73B63D__ INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif 1/ _MSC_VER > 1000 #include "ShareAlgorithm.h" #include "KOfKOptionsDialog.h" class KOfKAlgorithm : public ShareAlgorithm { public: KOfKAlgorithm(CBitmap *img, CView *cwin); KOfKAlgorithm(); virtual -KOfKAlgorithm(); virtual void GetOptions(); // GetOptions loads up the dialog box for changing the encryption options virtual void EncryptThis(Bitmaplmage* bmplmage); virtual Matrix* ConstQualMatrix(int participants); protected: KOfKOptionsDialog *koptDialog; } ; - 1 // KOfKOptionsDialog.cpp // implementation file #include "stdafx.h" .,.Jtinclude "encryptthis.h" include "KOfKOptionsDialog.h" # i f de f DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __ FILE __ ; #endif ///////////////////////////////////////////////////////////////////////////// // KOfKOptionsDialog dialog KOfKOptionsDialog: : KOfKOptionsDialog (CWnd* pParent /*=NULL*/) : CDialog(KOfKOptionsDialog: :IDD, pParent) //{{AFX_DATA_INIT(KOfKOptionsDialog) m-participants = 0; //}}AFX_DATA_INIT void KOfKOptionsDialog: : DoDataExchange (CDataExchange* pDX) { CDialog: :DoDataExchange(pDX); //{{AFX_DATA_MAP(KOfKOptionsDialog) DDX_Text(pDX, IDC_EDIT1, m-participants); DDV_MinMaxInt(pDX, m-participants, 1, 100); //}}AFX_DATA_MAP BEGIN_MESSAGE_MAP(KOfKOptionsDialog, CDialog) //{{AFX_MSG_MAP(KOfKOptionsDialog) //}}AFX_MSG_MAP - ~ND_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // KOfKOptionsDialog message handlers void KOfKOptionsDialog: :OnOK() { CDialog: : OnOK () ; 1 #if ! defined (AFX_KOFKOPTIONSDIALOG_H__B0068C45_F4DB_11D2_AD F2_DFCF6F73B63D__ INCLUDED_) #define AFX_KOFKOPTIONSDIALOG_H__B0068C4S_F4DB_11D2_ADF2_DFCF6F73B63D__ INCLUDED_ #if _MSC_VER > 1000 #pragma once ~~ndif // _MSC_VER > 1000 , / KOfKOptionsDia1og.h : header file // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /////////////////////1/ // KOfKOptionsDialog dialog class KOfKOptionsDialog : public CDialog { // Construction pUblic: KOfKOptionsDialog(CWnd* pParent NULL); // standard constructor // Dialog Data //{{AFX_DATA(KOfKOptionsDialog) enum { IDD = IDD_DIALOG6 }; int m-participants; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(KOfKOptionsDialog) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(KOfKOptionsDialog) virtual void OnOK(); //}}AFX_MSG DECLARE_MESSAGE_MAP() } ; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 1 // MainFrm.cpp : implementation of the CMainFrame class II #include "stdafx.h" Ainclude "EncryptThis.h" ... include "MainFrm.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] #endif = __ FILE__ ; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /////////////////1//1// // CMainFrame IMPLEMENT_DYNAMIC (CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! ON_WM_CREATE ( ) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] { ID_SEPARATOR, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, // status line indicator } ; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction ""'-:MainFrame: : CMainFrame ( ) // TODO: add member initialization code here CMainFrame: :-CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd: :OnCreate(lpCreateStruct) return -1; == -1) if (!m_wndToolBar.Create(this) I I !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) TRACEO("Failed to create toolbar\n"); return -1; // fail to create if (!m_wndStatusBar.Create(this) II !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) TRACEO("Failed to create status bar\n"); return -1; // fail to create // TODO: Remove this if you don't want tool tips or a resizeable toolbar m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() I CBRS_TOOLTIPS I CBRS_FLYBY I CBRS_SIZE_DYNAMIC); // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY) ; 1 DockControlBar(&m_wndToolBar) ; return 0; ~~OL CMainFrame: :PreCreateWindow(CREATESTRUCT& cs) // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CMDIFrameWnd: :PreCreateWindow(cs) ; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /////////////////////1/ // CMainFrame diagnostics #ifdef DEBUG void CMainFrame: :AssertValid() const { CMDIFrameWnd: :AssertValid(); void CMainFrame: : Dump (CDumpContext& dc) const { CMDIFrameWnd: :Dump(dc); #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers 2 // MainFrm.h : interface of the CMainFrame class // ///////////////////////////////////////////////////////////////////////////// ! defined {AFX_MAINFRM_H__ 6675968A_A327_11D2_B20A_444553540 OOO __ INCLUDED_) 1efine AFX_MAINFRM_H__ 6675968A_A327_11D2_B20A_444553540000 __ INCLUDED_ ~if #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 class CMainFrame : public CMDIFrameWnd { DECLARE_DYNAMIC (CMainFrame) public: CMainFrame{); // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX VIRTUAL (CMainFrame) virtual-BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL // Implementation public: virtual -CMainFrame{); #ifdef _DEBUG virtual void AssertValid{) const; virtual void Dump{CDumpContext& dc) const; #endif - protected: // control bar embedded members CStatusBar m_wndStatusBar; CToolBar m_wndToolBar; // Generated message map functions protected: /1{{AFX_MSG{CMainFrame) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); /1 NOTE - the ClassWizard will add and remove member functions here. /1 DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG DECLARE_MESSAGE_MAP{) } ; /1//////1///1///1///1///1/////////1/////////////////////1//1//1//1///1/////// //{{AFX INSERT LOCATION}} // Micr;soft Developer Studio will insert additional declarations immediately before the previous line. 1 // Matrix.cpp: implementation of the Matrix class. /! ////////////////////////////////////////////////////////////////////// ,,--tinclude "stdafx.h" include "Matrix.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]= __ FILE __ ; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// Matrix: :Matrix () { c=-l; r=-l; Matrix::Matrix(int cols, int rows) { c=-l; r=-l; Resize(cols, rows); Matrix::-Matrix() { // For each column in the matrix ... for(int x=O; x<c; x++) // ... destroy the column delete columns[x]; - ;Array<float, float&>& Matrix: :operator[l (unsigned int index) { // Return a column from the columns array return *(columns[indexl); const CArray<float, float&>& Matrix: :operator[l (unsigned int index) const { // Return a column from the columns array return *(columns[indexl); void Matrix: :Ident() { for(int x=O; x<c; x++) { for(int y=O; y<r; y++) { if (x==y) (*this) [xl [yl =1; else (*this) [xl [yl=O; void Matrix: : Show ( ) { CString t, S; for(int x=O; x<this->Height(); x++) { for(int y=O; y<this->Width(); y++) { s. Format (" %f", t=t+ II II (*this) [yl [xl) ; +8; 1 t+=II\nll; AfxMessageBox(t) ; Matrix* Matrix: :Invert() { Matrix *inverted, *org; inverted=new Matrix(c, r); inverted->Ident(); org=new Matrix(c, r); *org=*this; II int x, y; loop counters II Go through each column of the matrix for(x=O; x<c && x<r; x++) { II II II If our current element is a zero, then we need to flip that row with a row which doesn't have a zero in the current position i f ((*org) [xl [xl ==0) { for(y=x; ((*org) [xl [xl==O)&&(y<r); y++) { II II II If this row doesn't have a zero at the current position, then flip it with the current row i f ( (*org) [xl [yl ! =0) { *inverted=*(inverted->Flip(y, x»; org->Flip (y, x); II II If we managed to find a row that had something other than a zero in the current position i f ( (*org) [xl [xl! =0) { II Make the [x,xl element 1 inverted->MultRow(x, 11 (*org) [xl [xl); org->MultRow(x, 1/(*org) [xl [xl); AfxMessageBox ( "Hrm ... " ) ; for(z=O; z<c; z++) { fliptemp=(*this) [z] [y]; (*this) [z] [y]=(*this) [z] [xl; (*this) [zl [x]=fliptemp; else AfxMessageBox("Attempt to flip a row that doesn't exist."); return this; Matrix* Matrix::MultRow(int x, float y) { int z; if (x<r) { if(c==O) { AfxMessageBox ( "Ack ... " ) ; for(z=O; z<c; z++) { (*this) [z] [x] *=y; } else AfxMessageBox("Attempt to multiply a row that doesn't exist"); - return this; iatrix* Matrix::MultAddRows(int x, float z, int y) { int a; for(a=O; a<c; a++) { (*this) [a] [y]+=(*this) [a] [x]*z; return this; void Matrix::Transpose() { Matrix *tmatrix=new Matrix(r, c); IIMatrix *current=this; for(int x=O; x<c; x++) for(int y=O; y<r; y++) (*tmatrix) [y] [x]=(*this) [x] [y]; this->Resize(r, e); (*this)=(*tmatrix); delete tmatrix; void Matrix::Resize(int cols, int rows) { int x; ~ II Delete columns which are beyond the new eols value for(x=c-l; x>=cols; x--) { delete columns[x]; 3 columns.SetSize(cols); II (Re)Set the size of each column to the number of rows II specified. for(x=O; x<cols; x++) { II If our column index is beyond what current size II of the matrix ... if(x>=c) II Create a new column. columns [x]=new CArray<float, float&>; II Set the size of the row (columns[x])->SetSize(rows); r=rows; c=cols; void Matrix: : Augrnent (Matrix *block) { int x,y; int cols=c; int rows=r; this->Resize(c + block->Width(), (r>block->Height())?r:block->Height()); for(x=cols; x<c; x++) { for(y=O; y<block->Height(); y++) (*this) [x] [y] = (*block) [x-cols] [y] ; int Matrix: : Exchange (int original, int replace) { - int counter=O; for(int x=O; x<c; x++) { for(int y=O; y<r; y++) { if((*this) [x] [y]==original) { (*this) [x] [y]=replace; counter++; return counter; void Matrix: :DeleteRow(int row) { row--; if (row<r) { for(int x=row; x<r-l; x++) { for(int y=O; y<c; y++) { (*this) [y] [x] = (*this) [y] [x+l] ; this->Resize(c, r-l); } ,-.., 4 // Matrix.h: interface for the Matrix class. // ////////////////////////////////////////////////////////////////////// #if ! defined (AFX_MATRIX_H__ 09D58702_650B_11D2_80C9_FF79C5BAE 07E __ INCLUDED_) AFX_MATRIX_H__ 09D58702 650B_11D2 80C9_FF79C5BAE07E __ INCLUDED_ ~define #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include <afxtempl.h> #include "stdafx.h" #ifndef __AFXTEMPL H #include <afxtempl.h> #endif using namespace std; class Matrix { pUblic: // Construct a matrix with cols columns and rows rows Matrix(int cols, int rows); virtual -Matrix(); int Height() {return r;}; int Width() {return c;}; // Return the number of rows in the matrix // Return the number of columns in the // matrix // Take the current matrix and return its inverse Matrix* Invert(); // Take row x of the matrix, mUltiply it by z, and // add it to row y. Return the modified matrix. Matrix* MultAddRows(int x, float z, int y); __ // Multiply the elements of row x by y. // modified matrix. Matrix* MultRow(int x, float y); Return the // Exchange row x with row y within the current matrix. // Return the modified matrix. Matrix* Flip(int x, int y); // Use a Windows message box to display the contents of // the current matrix void Show(); // Return a column of the matrix CArray<float,float&>& operator[] (unsigned int index); const CArray<float,float&>& operator[] (unsigned int index) const; 1/ Multiply the current matrix with a matrix m2 Matrix* operator*(Matrix &m2); void operator=(Matrix &m); // Return matrix to the identity void Ident(); int Exchange(int original, int replace); void Augment (Matrix *block); void Resize(int cols, int rows); void Transpose(); void DeleteRow(int row); protected: Matrix() ; 1/ This constructor should never be called except II possibly by derived classes CArray<CArray<float, float&>*, CArray<float, float&>*> columns; // Array of columns int r,c; /1 Number of rows and columns (respectively) in the matrix } ; 1 inline Matrix* Matrix: :operator*(Matrix &m2) ,..... { Matrix *product; II Resultant matrix of the multiplication product=new Matrix(m2.Width(), r); II For each column in the new matrix for(int x=O; x<r; x++) { // For each row in the new matrix for(int y=O; y<m2.Width(); y++) { (*product) [yl [xl =0; 1/ For every element in the first row for(int z=O; z<c; z++) { // Multiply that element by the corresponding element // in the z'th row of m2. (*product) [yl [xl += ((*this) [zl [xl) *m2 [yl [zl ; return product; inline void Matrix::operator=(Matrix &m) { int a, b; a=(Width(»m.Width())?m.Width() :width(); b=(Height(»m.Height())?m.Height() :Height(); - for(int x=O; x<a; x++) { for(int y=O; y<b; y++) { (*this) [xl [yl =m [xl [yl ; 2 // Progress.cpp : implementation file II #include "stdafx.h" #include "EncryptThis.h" "-"'include "Progress.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[) = __FILE__ ; #endif ///////////////////////////////////////////////////////////////////////////// // CProgress dialog CProgress::CProgress(CWnd* pParent /*=NULL*/) : CDialog(CProgress::IDD, pParent) //{{AFX_DATA_INIT(CProgress) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT void CProgress: : DoDataExchange (CDataExchange* pDX) { CDialog: :DoDataExchange(pDX); //{{AFX_DATA_MAP(CProgress) DDX_Control(pDX, I DC_PROGRESS 1 , m_Progress); //}}AFX_DATA_MAP BEGIN_MESSAGE_MAP(CProgress, CDialog) //{{AFX_MSG_MAP(CProgress) // NOTE: the ClassWizard will add message map macros here / / } }AFX_MSG_MAP ;ND_MESSAGE_MAP () ///////////////////////////////////////////////////////////////////////////// // CProgress message handlers 1 #if !defined(AFX_PROGRESS_H__DDFC99C1_B168_11D2_B20A_444553540000 __ INCLUDED_) #define AFX_PROGRESS_H__ DDFC99C1_B168_11D2_B20A_444553540000 __ INCLUDED_ #if _MSC_VER >= 1000 #pragma once ~:ndif II _MSC_VER >= 1000 ,I Progress.h : header file II 111111111111111111111//1//1///////////////////////////////1//1//1///1///1///1 1/ CProgress dialog class CProgress : public CDialog { // Construction pUblic: CProgress(CWnd* pParent NULL); // standard constructor // Dialog Data /1 {{AFX_DATA(CProgress) enum { IDD = IDD_DIALOG2 }; CProgressCtrl m_Progress; //}}AFX_DATA /1 Overrides 1/ ClassWizard generated virtual function overrides 1/{{AFX_VIRTUAL(CProgress) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CProgress) // NOTE: the ClassWizard will add member functions here //} }AFX_MSG DECLARE_MESSAGE_MAP() } ; I/{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. 1 II{{NO_DEPENDENCIES}} II Microsoft Developer Studio generated II Used by EncryptThis.rc II #define IDD_ABOUTBOX ~define IDR_MAINFRAME define IDR_ENCRYPTYPE #define IDD_DIALOG5 #define IDD_DIALOG2 #define IDD_DIALOG1 #define IDD_DIALOG3 #define IDD_DIALOG4 #define IDD_DIALOG6 #define IDC_RADI01 #define IDC_PROGRESS1 #define IDC_RADI02 #define IDC_LIST1 #define I DC_TOTALSHARES #define I DC_BUTTON1 #define I DC_BUTTON2 #define IDC_LIST2 #define IDC_CHECK1 #define IDC_EDIT1 #define BWENC #define ID_EDIT_ENCRYPTTHIS #define ID_VIEW_ENCRYPTIONOPTIONS #define ID_ENCRYPTION_ENCRYPTTHIS #define ID_ENCRYPTION_OPTIONS #define TWO_OF_TWO #define K_OF_K II Next default values for new objects II #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS #define _APS_NEXT_RESOURCE_VALUE #define _APS_NEXT_COMMAND_VALUE ~define _APS_NEXT_CONTROL_VALUE define _APS_NEXT_SYMED_VALUE #endif #endif include file. 100 128 129 130 131 132 133 134 136 1000 1000 1001 1002 1005 1006 1007 1008 1009 1010 32773 32774 32775 32776 32777 32778 32779 1 137 32785 1011 101 1 // ShareAlgorithm.cpp: implementation of the ShareAlgorithm class. /! ////////////////////////////////////////////////////////////////////// #include "","",,,include include #include #include #include #include #include "stdafx.h" "EncryptThis.h" "ShareAlgorithm.h" "EncryptImageDialog.h" " .. \MyLib\Matrix.h" <stdlib.h> <time.h> <fstream> #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]= __ FILE__ ; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ShareAlgorithm::ShareAlgorithm(CBitmap *img, CView *cwin) { //CSize orgImageSize; qualSets=NULL; orgImg=NULL; vImage=img; encWin=cwin; orgBMP=new CBitmap(); //orgImageSize=img->GetBitmapDimension(); //basisSO=new Matrix(O, 0); //basisSl=new Matrix(O, 0); optDialog=new ShareOptionsDialog(); optDialog->Create(IDD_DIALOG3); sdialog=new ShareDialog(); sdialog->Create(IDD_DIALOG1); Enable() ; ShareAlgorithm: :ShareAlgorithm() { } ShareAlgorithm: :-ShareAlgorithm() { Disable() ; delete sdialog; delete optDialog; void ShareAlgorithm: :GetOptions() { optDialog->ShowWindow(SW_SHOW) ; //optDialog->DoModal() ; qualSets=optDialog->GetQualCollections(); void ShareAlgorithm::EncryptThis(BitmapImage* bmpImage) { - Matrix *qualMatrix; //Matrix *posMaxForb; Matrix *maxForb; // Matrix in which each row represents // a qualified set // Matrix in which each row represents // a possible maximal forbidden set of // the access structure // Matrix in which each row represents 1/ one of the maximal forbidden sets 1 II of the access structure CArray<bool, bool> colPerrnute; II II II II Each boolean value indicates whether a column has already been used in the encryption process II Memory DC used to create the II bitmap image for later display CDC dcMem; int participants=optDialog->m_totalShares; II Number of total participants bool saveRow=false; II Save original image if (orgImg!=NULL) { delete orgImg; orgImg=new BitmapImage(*bmpImage); II If the number of participants is greater than one, then we can II encrypt the image ... if (participants>l) { II Check to see that the bitmap is a black and white image II by making sure it is only a one bit image if (bmpImage->BitCount (»1) { II II II II II Display a message box to the user asking himlher if they want to continue the encryption process even though it is not a black and white image. Doing so will assume any color that is not completely white is black. if(AfxMessageBox("Graphics which are not pure black and white images cannot be encrypt ed using this method. Would you still like to continue? (Note: continuing will assume any colors which are not purely white are black)", MB_YESNO)==IDNO) ,.- { return; II Construct matrix representing qualified sets of participants qualMatrix=ConstQualMatrix(participants); maxForb=FindMaxForbSets(participants, qualMatrix); II If only one maximal forbidden set was found ... if(maxForb->Height() ==1) { II ... then the standard encryption scheme won't work. II Because of this, we have to use a method using II small structures method. AfxMessageBox("Warning: Only one maximal forbidden set was found. thod will be used."); Small structures me II Call small structures method StartSmallStruct(qualMatrix) ; else { II Otherwise, the regular encryption scheme will work StartNormalStruct(qualMatrix); } II Otherwise it's pointless (and maybe impossible) to encrypt the image else { -0 AfxMessageBox("Error: The total number of participants(shares) should be greater than 1.\n into the encryption options to modify this and then attempt to encrypt the image again."); } 2 int ShareAlgorithm: :Factorial(int n) { if(n<2) return 1; else ~ return Factorial(n-l)*n; int ShareAlgorithm: : Permute (int n, int m) { if(n<O I I m<O) return -1; else return Factorial(m) I (Factorial(n) * Factorial(m-n)); void ShareAlgorithm: :Disable() { sdialog->ShowWindow(SW_HIDE) ; void ShareAlgorithm: :Enable() { sdialog->ShowWindow(SW_SHOW) ; void ShareAlgorithm::PermuteFill(int row, int col, int n, int m, int width, Matrix *pmatrix) { int p=Permute(n-l, m-l); for(int x=col; x«p+col); x++) { (*pmatrix) [xl [rowl=l; if(! (n==O && m==O)) { if(p>O) PermuteFill(row+l, col, n-l, m-l, p, pmatrix); if((width-p>O)&&(p!=O)) PermuteFill(row+l, col+p, n, m-l, width-p, pmatrix); void ShareAlgorithm: :UpdateDisplay(int numImg, LPINT selImages) { CDC dcMem; II Memory DC used to create the II bitmap image for later display CDC dcMem2; CClientDC *background; II Represents the current DC being II used by our window CBitmap *pOldBitmap, *pOldBitmap2; CBrush *brush; int x; II Initialize background so it actually holds II the DC currently being used by our window background=new CClientDC(encWin); II II II II Create our memory DC so that it is compatible with the DC currently being used. Otherwise the bitmap might not be displayed correctly (ie. wrong bits per pixel) dcMem.CreateCompatibleDC(background) ; dcMem2.CreateCompatibleDC(background); ,~ pOldBitmap = dcMem.SelectObject(vImage); II If numImg<O, then we display the original image if (numImg<O) { 3 pOldBitmap2 = dcMem2.SelectObject(orgBMP); dcMem.BitBlt(O, 0, orgImg->width(), orgImg->Height(), &dcMem2, 0, 0, SRCCOPY); dcMem2.SelectObject(pOldBitmap2) ; } .",..... /1 Otherwise we have to find out which shares are to be // seen and update the display else { // Erase the previous image by making a white rectangle // to cover it brush=new CBrush(); brush->CreateSolidBrush(RGB(255, 255, 255)); dcMem.Rectangle(-50, -50, 1500, 1500); // For each share to be overlaid for(x=O; x<numImg; x++) { // Select the share's bitmap into its own DC pOldBitmap2 = dcMem2.SelectObject(DCShares[selImages[x]]); // Copy the bitmap from the dcMem2 DC to the dcMem DC using // an AND copy so that the image is overlaid like a transparency // (Generally you would think this would be an OR function but // it becomes an AND function because white is thought of as 1) dcMem.BitBlt(O, 0, memShares[selImages[x]]->Width(), memShares[selImages[x]]->Height() , &dcMem2, 0, 0, SRCAND); dcMem2.SelectObject(pOldBitmap2); // Select the bitmap that was being used // before back into the memory DC dcMem.SelectObject(pOldBitmap); // Delete the copy of the CClientDC delete background; // Release the memory DC for Windows dcMern.DeleteDC() ; dcMern2.DeleteDC(); encWin->Invalidate(); CBitmap* ShareAlgorithrn: :GetDisplayImage() { return vImage; void ShareAlgorithrn: :SaveEncData(CString file) { of stream bmpofile; CString filename=""; CString ext=""; CString newfile=""; int periodIdx; // If the image hasn't been encrypted yet ... if (orgImg==NULL) { AfxMessageBox("Sorry, you can't save the original image (yet) without first encrypting it") else { // If the user chooses to save each individual share as opposed to the - 1/ composite image currently visible ... if(AfxMessageBox("Would you like to save each share as a separate file? (choosing No will save the currently visible image based on which shares are currently selected) ", MB_YESNO)==IDYES) { // Determine where the first period exists in the filename so we can insert the number // of the share in front of it. periodIdx=file.Find('. '); 4 II If a period does not exist in the file string ... if (periodIdx==-l) { II ... then we set the filename string equal to the file I I string ... filename = file + "."; II ... and set ext equal to ".bmp" ext = ".bmp"; else { II Otherwise we split the file string into the filename II and ext strings filename = file.Left(periodIdx); ext = file.Right(file.GetLength() - periodIdx); II Check to ensure that the extension ends with .bmp i f (ext.Right(4) !=" . bmp " ) { II If the end of the extension is not ".bmp" we II add it so that it is ext+=" . bmp " ; for(int x=o; x<memShares.GetSize(); x++) { II Format the filename of the next share to be saved I I like: II <original filename><share number>.<extension> newfile.Format("%s%d%s", filename, x+l, ext); II Open a new file for binary output bmpofile.open(newfile, ios: : binary) ; - II Write out the share to the binary file bmpEnc.WriteImage(bmpofile, *(memShares[xl)); II Close the file bmpofile.close() ; Matrix* ShareAlgorithm: : FindMaxForbSets (int participants, Matrix *qualMatrix) { Matrix *maxForb=new Matrix(O, 0); int x, y, Z, a; bool saveRow=false; for (x=participants; x>O; x--) { II Generate matrix which we'll use to try to find the II maximal forbidden sets maxForb=new Matrix (Permute (x, participants), participants); PermuteFill( 0, 0, x, participants, Permute (x, participants), maxForb); IlmaxForb->Show(); maxForb->Transpose(); IlmaxForb->Show(); for(y=O; y<maxForb->Height(); y++) { for(z=O; z<qualMatrix->Height(); z++) { saveRow=false; for(a=O; a<participants; a++) { if((*qualMatrix) Cal [zl==l) { if( (*maxForb) Cal [yl==O) { saveRow=true; 5 if ( ! saveRow) { maxForb->DeleteRow(y+1); y--; z=qualMatrix->Height() ; II If the height of the matrix is greater than 0 at this II point, then we've found the maximal forbidden sets II so we set x to 0 so we break out of the for loop. if(maxForb->Height(»O) x=O; I IAfxMessageBox ("Maximal Forbidden Sets"); IlmaxForb->Show() ; return maxForb; Matrix* ShareAlgorithm: :ConstQualMatrix(int participants) { int x, y; Matrix *qualMatrix=new Matrix (participants , qualSets->GetSize()); for(x=O; x<qualMatrix->Height(); x++) { II For each element in the next qualified set ... for(y=O; y«*qualSets) [x]->GetSize(); y++) { II ... go to x'th row of the matrix and set the II column which corresponds to the next element - II of the qualified set to 1 (*qualMatrix) [(*(*qualSets) [x]) [y]] [x]=l; return qualMatrix; void ShareAlgorithm: :StartSmallStruct(Matrix* qualMatrix) { Matrix* Matrix* Matrix* Matrix* Matrix* Matrix* Matrix* Matrix* sqMatrix; mForbs; basisRO; basisR1; basisSO; basisS1; CAMatrix; zeroBlock; basisSO=new Matrix(O, 0); basisS1=new Matrix(O, 0); zeroBlock=new Matrix(O, 0); int x, y; for(x=O; x<qualSets->GetSize(); x++) { sqMatrix=new Matrix((*qualSets) [x]->GetSize(), 1); for(y=O; y<sqMatrix->Width(); y++) (*sqMatrix) [y] [0]=1; II Generate the maximal forbidden set for this II qualified set matrix and add it to the array II of maximal forbidden sets array mForbs=FindMaxForbSets(sqMatrix->Width(), sqMatrix); CAMatrix=CalcCAMatrix(mForbs) ; 6 basisRO=new Matrix(O, 0); basisR1=new Matrix(O, 0); CalcBasisMatrices(basisRO, basisR1, CAMatrix); II Insert rows of zeros for participants which do II not participate in this small structure zeroBlock->Resize(basisRO->Width(), 1); for(y=O; y<qualMatrix->Width(); y++) { II If the y'th participant was not involved in II this(the x'th) small structures encryption ... if((*qualMatrix) [y] [x]==O) { II create a block to insert into the RO and R1 II basis matrices. This block will be a single II row with the same width as RO and R1 and will II be filled with O's. basisRO->InsertAtRow(y, zeroBlock); basisR1->InsertAtRow(y, zeroBlock); II II II II Concatenate the RO and R1 basis matrices with the SO and Sl matrices respectively. The resulting matrices (SO and Sl) will be the basis matrices for the complete strong access structure defined by the user. basisSO->Augment(basisRO); basisS1->Augment(basisR1); II Cleanup delete basisRO; delete basisR1; delete sqMatrix; delete mForbs; delete CAMatrix; Encrypt Image (basisSO, basisS1); void ShareAlgorithm: :StartNormalStruct(Matrix *qualMatrix) { Matrix* mForbs; Matrix* basisSO; Matrix* basisS1; Matrix* CAMatrix; basisSO=new Matrix(O, 0); basisS1=new Matrix(O, 0); II Generate the maximal forbidden set for this II qualified set matrix and add it to the array II of maximal forbidden sets array mForbs=FindMaxForbSets(qualMatrix->Width(), qualMatrix); CAMatrix=CalcCAMatrix(mForbs); CalcBasisMatrices(basisSO, basisS1, CAMatrix); EncryptImage(basisSO, basisS1); II Cleanup delete basisSO; delete basisS1; delete mForbs; delete CAMatrix; ~~trix* ShareAlgorithm: :CalcCAMatrix(Matrix *maxForb) II Create Cumulative Array Matrix based on size of II the Maximal Forbidden Sets Matrix. Matrix *CAMatrix=new Matrix(maxForb->Height(), maxForb->Width()); 7 II Take the transpose of the Maximal Forbidden Sets II Matrix and set it equal to the Cumulative Array II Matrix. maxForb->Transpose(); (*CAMatrix) = (*maxForb) ; II II II II Turn all the O's to l's and all the l's to O's. We use the intermediate step of making O's into 2's since actually flipping all O's to l's and all l's to O's would result in a matrix with only O's(if done in that I I order). CAMatrix->Exchange(O, 2); CAMatrix->Exchange(l, 0); CAMatrix->Exchange(2, 1); IICAMatrix->Show(); return CAMatrix; void ShareAlgorithm: :CalcBasisMatrices(Matrix* basisSO, Matrix* basisS1, Matrix* CAMatrix) { II Temporary permutation matrix // Basis matrix RO; II Basis matrix R1; Matrix *pMatrix; Matrix *basisRO; Matrix *basisR1; int x, y, z, c; II Generate RO basisRO=new Matrix(O, 0); c=CAMatrix->Width(); for(x=O; x<=c; x+=2) { pMatrix=new Matrix (Permute (x, c), c); PermuteFill( 0, 0, x, c, Permute (x, c), pMatrix); basisRO->Augment(pMatrix) ; delete pMatrix; - /1 Generate R1 basisR1=new Matrix(O, 0); for(x=l; x<=c; x+=2) { pMatrix=new Matrix (permute (x, c), c); PermuteFill( 0, 0, x, c, Permute (x, c), pMatrix); basisR1->Augment(pMatrix); delete pMatrix; // Generate SO and Sl basisSO->Resize(basisRO->Width(), CAMatrix->Height(»; basisS1->Resize(basisR1->Width(), CAMatrix->Height(»; for(x=O; x<basisSO->Height(); x++) { for(y=O; y<CAMatrix->Width(); y++) { if ( (*CAMatrix) [y] [x] ==1) { for(z=O; z<basisSO->Width(); z++) { if( «*basisRO)[z] [y]==l) II «*basisSO)[z] [x]==l) ) II «*basisS1) [z] [x]==l) ) { (*basisSO) [z] [x]=l; } if( «*basisR1) [z] [y]==l) { (*basisS1) [z] [x]=l; 8 void ShareAlgorithm: : EncryptImage (Matrix *basisSO, Matrix *basisSl) { CArray <int, int> columns; II Array to hold all the columns left to choose II from during encryption II Random value which indexes into the columns int randVal=O; II array to retrieve the value of a thus far II unused column int participants=basisSO->Height(); BitmapImage *tmpBitmap; CBitmap *tmpCBitmap; II Used to create share bitmap array II Used to create share bitmap array for II display use CBitmap *pOldBitmap; Matrix *encBasis; int x, y, z; int colsDone; int randCol; int rgb; CClientDC *background; CDC dcMem; UBYTEl r, g, b; II Create share images for(x=O; x<participants; x++) { tmpBitmap=new BitmapImage(); II Set the bitmap to a 24bit image with a width equal to II the original image's width times the number of participants II and the height equal to the height of the original image. tmpBitmap->SetSize(O, 24, orgImg->Width(), orglmg->Height()); II Add the new bitmap object to the array memShares.Add(tmpBitmap); II Seed the random number generator with the current II time srand( (unsigned) time ( NULL) ); EncryptImageDialog *prog_dialog=new EncryptImageDialog(); prog_dialog->Create(IDD_DIALOG4); prog_dialog->ShowWindow(SW_SHOW); II Setup progress indicator prog_dialog->m_Progress.SetRange(O, orgImg->Height()); prog_dialog->m_Progress.SetStep(l); prog_dialog->m_Progress.SetPos(O) ; for(x=O; x<orgImg->Height(); x++) { for(y=O; y<orgImg->Width(); y++) { colsDone=O; II Get the RGB values of the current pixel in II the original image orgImg->GetRGB(x, y, r, g, b); II If the current pixel in the original image II is white if(r==255 && g==255 && b==255) { II Set the encryption basis matrix to the II SO basis which represents the columns to II be used to encrypt a white pixel encBasis=basisSO; } II Otherwise we treat it as being black even II though it might not be if the image depth 9 II is greater than one bit(but the user was 1/ warned about this if it was) else { // Set the encryption basis matrix to the // Sl basis which represents the columns // to be used to encrypt a black pixel encBasis=basisSl; // Initialize column permutation array for(z=O; z<encBasis->Width(); z++) columns.Add(z) ; while(columns.GetSize(»O) { /1 Select a random column from the remaining columns in // the basis matrix randVal=rand()%(columns.GetSize()); /1 Retrieve the value of this column randCol=columns[randVal] ; /1 Remove the column's value from the array so that it // can't be used again columns.RemoveAt(randVal) ; 1/ For each row of in the basis matrix(corresponding to each 1/ participant) for(b=O; b<encBasis->Height(); b++) { 1/ For each RGB value (red, green, and blue) for(rgb=O; rgb<3; rgb++) { // ... write the appropriate value out(255 or 0 corresponding to white // and black respectively) // Pick up the b'th share and go to the x'th row and (y+colsDone) column // this share. 0 From here, go through each RGB value required to define th e o /1 pixel. The value for the pixel comes from the encryption basis matrix. /1 If the encryption basis matrix holds a 1 for this pixel, we NOT it to a // and multiply it by 255 giving us o (black) . If the encryption basis hoI ds /1 a 0 for this pixel, then we NOT it to get 1 and then mUltiply it by 255 /1 giving us 255 (white) . ((*(memShares[b])) [x] [(y+colsDone)*3 + rgb])=(! ((*encBasis) [randCol] [b]))* 255; colsDone++; prog_dialog->m_Progress.StepIt(); prog_dialog->Destroywindow(); sdialog->EncInfo(participants, this); // Initialize background so it actually holds // the DC currently being used by our window background=new CClientDC(encWin); // Create our memory DC so that it is compatible // with the DC currently being used. Otherwise /1 the bitmap might not be displayed correctly /1 (ie. wrong bits per pixel) dcMem.CreateCompatibleDC(background) ; if (orgBMP->m_hObject != NULL) orgBMP->DeleteObject(); // get rid of old bitmap 10 orgBMP->CreateCompatibleBitmap(background, orglmg->Width(), orglmg->Height()); orgBMP->SetBitmapDimension(orglmg->Width(), orglmg->Height()); II Generate CBitmap for original image pOldBitmap = dcMem.SelectObject(orgBMP); II Write the bitmap out to our memory DC for(y=O; y<orglmg->Width(); y++) { for(z=O; z<orglmg->Height(); z++) { orglmg->GetRGB(z, y, r, g, b); dcMem.SetPixel(y, z, RGB(r, g, b)); dcMem.SelectObject(pOldBitmap); II Generate CBitmaps for each share II Delete any bitmaps being stored from a previous encryption for(x=O; x<DCShares.GetSize(); x++) delete DCShares[x]; II Empty the array DCShares.RemoveAll(); for(x=O; x<participants; x++) { tmpCBitmap=new CBitmap(); DCShares.Add(tmpCBitmap) ; tmpCBitmap->CreateCompatibleBitmap(background, (memShares[x])->width(), (memShares) [x]->He ight()) ; tmpCBitmap->SetBitmapDimension«memShares[x])->Width(), ASSERT(tmpCBitmap->m_hobject != NULL); pOldBitmap = dcMem.SelectObject(tmpCBitmap); II Write the bitmap out to our memory DC for(y=O; y«memShares[x])->width(); y++) { for(z=O; z«memShares[x])->Height(); z++) { memShares[x]->GetRGB(z, y, r, g, b); dcMem.SetPixel(y, z, RGB(r, g, b)); dcMem.SelectObject(pOldBitmap); delete background; dcMem.DeleteDC(); UpdateDisplay(-l, NULL); 11 (memShares) [x]->Height()); // ShareAlgorithm.h: interface for the ShareAlgorithm class. // ////////////////////////////////////////////////1/1///1/////1////////1 #if ! defined (AFX_SHAREALGORITHM_H__ OBE43DAO_A3D3_11D2_B20A_444 553540000 __ INCLUDED_) ~1efine AFX_SHAREALGORITHM_H__ OBE43DAO_A3D3_11D2_B20A_444553540000 __ INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif II _MSC_VER >= 1000 #include #include #include #include "EncryptAlgorithm.h" "ShareDialog.h" "ShareOptionsDialog.h" " . . \MyLib\Matrix.h" class ShareAlgorithm : public EncryptAlgorithm { public: void UpdateDisplay(int numlmg, LPINT sellmages); ShareAlgorithm(); ShareAlgorithm(CBitmap *img, CView *cwin); virtual -ShareAlgorithm(); virtual virtual virtual virtual virtual virtual protected: virtual virtual virtual virtual virtual virtual ~ virtual void GetOptions(); void EncryptThis(Bitmaplmage* bmplmage); void Disable(); void Enable(); CBitmap* GetDisplaylmage(); void SaveEncData(CString file); void Encryptlmage(Matrix* basisSO, Matrix* basisS1); void CalcBasisMatrices(Matrix* basisSO, Matrix* basisS1, Matrix* CAMatrix); Matrix* CalcCAMatrix(Matrix* maxForb); void StartNormalStruct(Matrix* qualMatrix); void StartSmallStruct(Matrix* qualMatrix); Matrix* FindMaxForbSets(int participants, Matrix* qualMatrix); Matrix* ConstQualMatrix(int participants); void PermuteFill(int row, int col, int n, int m, int width, Matrix *pmatrix); int Factorial(int n); int Permute(int n, int p); ShareDialog *sdialog; ShareOptionsDialog *optDialog; IntegerCollection *qualSets; CBitmap *vlmage; CView *encWin; Bitmaplmage *orglmg; CBitmap *orgBMP; II II II II CBitmap used by the view class to display the necessary data Pointer to the view class being used by this encryption object II Original image stored in the format used II by the Bitmaplmage class II Original image stored in the format used 1/ by the CBitmap class. This pointer is II used when the user chooses to view the II original image instead of the encrypted II shares CArray<CBitmap*, CBitmap*> DCShares; CArray<Bi tmaplmage * , Bitmaplmage*> memShares; "....1 I II II II II II Array of encrypted shares stored for immediate (well, almost) viewing in CBitmap's format Array of encrypted shares stored for manipulation BmpEncoder bmpEnc; II Bitmap encoder used to write out either the composite image II created by the currently selected shares or each share as its II own individual bitmap file Matrix *basisSO; Matrix *basisS1; II Basis matrix SO; II Basis matrix S1; } ; 1 2 // ShareDialog.cpp : implementation file // #include "stdafx.h" #include "EncryptThis.h" r<include "ShareDialog.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[) = __ FILE __ ; #endif #include "ShareAIgorithm.h" ///////////////////////////////////////////////////////////////////////////// // ShareDialog dialog ShareDialog: : ShareDialog(CWnd* pParent /*=NULL*/) : CDialog(ShareDialog: :IDD, pParent) shareAIgorithm=NULL; //{{AFX_DATA_INIT(ShareDialog) m_ImageOption = 0; //}}AFX_DATA_INIT void ShareDialog: : DoDataExchange (CDataExchange* pDX) { - CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ShareDialog) DDX_Control(pDX, IDC_LIST1, m_ShareList); DDX_Control(pDX, IDe_RADI01, m_ImageOptionButton); DDX_Radio(pDX, IDC_RADI01, m_ImageOption); //}}AFX_DATA_MAP BEGIN_MESSAGE_MAP(ShareDialog, CDialog) //{{AFX_MSG_MAP(ShareDialog) ON_BN_CLICKED(IDC_RADI01, OnOriginalImage) ON_BN_CLICKED(IDC_RADI02, OnEncImages) ON_LBN_SELCHANGE(IDC_LIST1, OnSharesChanged) ON_BN_CLICKED(IDC_CHECK1, OnScaled) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ShareDialog message handlers void ShareDialog::OnOriginaIImage() { // TODO: Add your control notification handler code here if (shareAIgorithm!=NULL) { shareAIgorithm->UpdateDisplay(-l, NULL); // Disable the shares list since we're displaying the original // image m_ShareList.EnableWindow(FALSE) ; void ShareDialog: :OnEncImages() { // Enable the shares list so the user can select the ones // they want to be overlaid in the window if (shareAIgorithm!=NULL) { m_ShareList.EnableWindow(); OnSharesChanged(); void ShareDialog::OnSharesChanged() 1 int numSel; II Number of items selected in list box LPINT selected; II Buffer to hold the indexes of the selected items ~ numSel=m_ShareList.GetSelCount() ; selected=new int[numSel]; m_ShareList.GetSelltems(numSel, selected); shareAlgorithm->UpdateDisplay(numSel, selected); int ShareDialog: :DoModal() { II TODO: Add your specialized code here and/or call the base class return CDialog: :DoModal(); void ShareDialog::OnScaled() { II TODO: Add your control notification handler code here void ShareDialog::Enclnfo(int numShares, ShareAlgorithm *shareAlg) { CString newShare; shareAlgorithm=shareAlg; for(int x=O; x<numShares; x++) { newShare. Forma t ( "Share %d", x+ 1) ; m_ShareList.AddString(newShare) ; 2 #if !defined(AFX_SHAREDIALOG_H__ 49AB73AO_ADBE_11D2_B20A_444553540000 __ INCLUDED_) #define AFX_SHAREDIALOG_H __ 49AB73AO_ADBE 11D2_B20A_444553540000 INCLUDED_ #if _MSC_VER >= 1000 #pragma once ~endif // _MSC_VER >= 1000 . / ShareDialog.h : header file // class ShareAlgorithm; ///////////////////////////////////////////////////////////////////////////// // ShareDialog dialog class ShareDialog : public CDialog { // Construction public: void EncInfo(int numShares, ShareAlgorithm *shareAlg); ShareDialog(CWnd* pParent NULL); // standard constructor // Dialog Data //{{AFX_DATA(ShareDialog) enum { IDD = IDD_DIALOG1 }; CListBox m_ShareList; CButton m_ImageOptionButton; int m_ImageOption; / /} }AFX_DATA 1/ Overrides - // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(ShareDialog) public: virtual int DoModal(); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL / Implementation protected: ShareAlgorithm *shareAlgorithm; // Generated message map functions //{{AFX_MSG(ShareDialog) afx_msg void OnOriginalImage(); afx_msg void OnEncImages(); afx_msg void OnSharesChanged(); afx_msg void OnScaled(); /I}}AFX_MSG DECLARE_MESSAGE_MAP() } ; //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. 1 II ShareOptionsDialog.cpp II implementation file #include "stdafx.h" #include "EncryptThis.h" ~include "ShareOptionsDialog.h" #ifdef DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __ FILE__ ; #endif 1111//////////////////1//////////1////////1/////////1///////////////////1//// // ShareOptionsDialog dialog ShareOptionsDialog::ShareOptionsDialog(CWnd* pParent /*=NULL*/) : CDialog(ShareOptionsDialog: :IDD, pParent) qualCollections=new IntegerCollection; //{{AFX_DATA_INIT(ShareOptionsDialog) m_totalShares = 0; //}}AFX_DATA_INIT ShareOptionsDialog::-ShareOptionsDialog() { //delete [] (*quaICollections); for(int x=O; x<quaICollections->GetSize(); x++) { delete (*quaICollections) [xl; - delete qualCollections; 'oid ShareOptionsDialog: : DoDataExchange (CDataExchange* pDX) { CDialog: :DoDataExchange(pDX); //{{AFX_DATA_MAP(ShareOptionsDialog) DDX_Control(pDX, IDC_LIST2, m_Qualified); DDX_Control(pDX, IDC_LIST1, m_AIIShares); DDX_Text(pDX, IDC_TOTALSHARES, m_totaIShares); //}}AFX_DATA_MAP BEGIN_MESSAGE_MAP(ShareOptionsDialog, CDialog) //{{AFX_MSG_MAP(ShareOptionsDialog) ON_EN_CHANGE(IDC_TOTALSHARES, OnChangeTotalShares) ON_BN_CLICKED(IDC_BUTTON1, OnAddShareCollection) ON_BN_CLICKED(IDC_BUTTON2, OnRemoveShareCollection) ON_BN_CLICKED(IDOK, OnOk) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////1//////////////1/////////////////////////////// /////////////////////// // ShareOptionsDialog message handlers void ShareOptionsDialog: :OnChangeTotaIShares() { 1/ TODO: Add your control notification handler code here CString numConvert; UpdateData() ; if (m_totaIShares!=O) { - if (m_Qualified.GetCount () >0) { if(AfxMessageBox("Doing this will delete all current qualified sets. want to do this?", MB_YESNO)!=IDYES) { 1 Are you sure you m_totalShares=oldTotal; UpdateData(FALSE); return; m_AllShares.ResetContent(); m_Qualified.ResetContent(); for(int x=l; x<=m_totalShares; x++) { numConvert . Forma t ( " %d", x); m_AllShares.AddString(numConvert) ; } oldTotal=m_totalShares; IIUpdateData(FALSE); void ShareOptionsDialog: :OnAddShareCollection() { II TODO: Add your control notification handler code here UpdateData(); IntegerArray *newCollection=new IntegerArray; LPINT intArray; CString collectionStr; CString tmpStr; int selected=m_AllShares.GetSelCount(); intArray=new int[selected]; m_AllShares.GetSelltems(selected, intArray); for(int x=O; x<selected; x++) { - newCollection->Add(intArray[x]); tmpStr. Format ( "%d", intArray [x] + 1) ; collectionStr += tmpStr + " "; if (newCollection->GetSize() >0) { qualCollections->Add(newCollection); m_Qualified.AddString(collectionStr); void ShareOptionsDialog: :OnRemoveShareCollection() { II TODO: Add your control notification handler code here UpdateData() ; LPINT intArray; int selected=m_Qualified.GetSelCount(); if(selected>O) { intArray=new int[selected]; m_Qualified.GetSelltems(selected, intArray); for(int x=O; x<selected; x++) { qualCollections->RemoveAt(intArray[x]) ; m_Qualified.DeleteString(intArray[x]) ; UpdateData(FALSE); } .-. ntegerCollection* ShareOptionsDialog: :GetQualCollections() { return qualCollections; 2 int ShareOptionsDialog::DoModal() { II TODO: Add your specialized code here and/or call the base class return CDialog: :DoModal(); void ShareOptionsDialog: :OnOk() { UpdateData(); EndDialog(IDOK) ; 3 #if ! defined (AFX_SHAREOPTIONSDIALOG_H__ DDFC99C2_B168_11D2_B20 A_444553540000 __ INCLUDED_} #define AFX_SHAREOPTIONSDIALOG_H __DDFC99C2_B168_11D2_B20A_444553540000 __ INCLUDED_ #if _MSC_VER >= 1000 #pragma once ~endif // _MSC_VER >= 1000 / ShareOptionsDialog.h : header file // /11111/11/11111111/1111111/11/11/111/11111/11/11/11111/111111/11/111111/11111 II ShareOptionsDialog dialog II II This class represents the dialog box used for setting the II share encryption settings. class ShareOptionsDialog : public CDialog { 1/ Construction public: IntegerCollection* GetQualCollections(}; ShareOptionsDialog(CWnd* pParent = NULL); virtual -ShareOptionsDialog(); II Dialog Data 11{{AFX_DATA(ShareOptionsDialog) enum { IDD = IDD_DIALOG3 }; CListBox m_Qualified; CListBox m_AllShares; int m_totalShares; I/}}AFX_DATA II standard constructor II Overrides /1 ClassWizard generated virtual function overrides 11{{AFX_VIRTUAL(ShareOptionsDialog) pUblic: virtual int DoModal(); protected: virtual void DoDataExchange(CDataExchange* pDX); II DDX/DDV support II}}AFX_VIRTUAL / Implementation protected: IntegerCollection *qualCollections; int oldTotal; II Generated message map functions 11{{AFX_MSG(ShareoptionsDialog) afx_msg void OnChangeTotalShares(); afx_msg void OnAddShareCollection(); afx_msg void OnRemoveShareCollection() ; afx_msg void OnOk(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; II{{AFX_INSERT_LOCATION}} 1/ Microsoft Developer Studio will insert additional declarations immediately before the previous line. 1 II stdafx.cpp : source file that includes just the standard includes II EncryptThis.pch will be the pre-compiled header II stdafx.obj will contain the pre-compiled type information #include "stdafx.h" ~ 1 II stdafx.h : include file for standard system include files, II or project specific include files that are used frequently, but II are changed infrequently /I ~if !defined{AFX_STDAFX_H__ 66759688_A327_11D2_B20A_44455354OOOO __ INCLUDED_) ,define AFX_STDAFX_H__ 66759688_A327 11D2_B20A_444553540000 INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif II _MSC_VER >= 1000 #define VC_EXTRALEAN II Exclude rarely-used stuff from Windows headers #include <afxwin.h> II MFC #inc1ude <afxext.h> II MFC #include <afxdisp.h> II MFC #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> II MFC #endif II _AFX_NO_AFXCMN_SUPPORT #include <afxtempl.h> #include #inc1ude #inc1ude #include core and standard components extensions OLE automation classes support for Windows Common Controls "bitimage.h" "bmp.h" "bmpdecod.h" "bmpencod.h" typedef CArray<int,int&> IntegerArray; typedef CArray<IntegerArray*, IntegerArray*> IntegerCollection; II{{AFX_INSERT_LOCATION}} II Microsoft Developer Studio will insert additional declarations immediately before the previous line. 1 // TwoOfTwoAlgorithm.cpp: implementation of the TwoOfTwoAlgorithm class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" ......... include "encryptthis.h" ,include "TwoOfTwoAlgorithm.h" #ifdef DEBUG #undef THIS_FILE static char THIS_FILE[]= __FILE __ ; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// TwoOfTwoAlgorithm: :TwoOfTwoAlgorithm() { TwoOfTwoAlgorithm: :-TwoOfTwoAlgorithm() { TwoOfTwoAlgorithm: : TwoOfTwoAlgorithm(CBitmap *img, CView *cwin) KOfKAlgorithm(img, cwin) void TwoOfTwoAlgorithm: :GetOptions() { AfxMessageBox("There are no options for this encryption method."); ",.- roid TwoOfTwoAlgorithm: : EncryptThis (BitmapImage *bmpImage) { optDialog->m_totalShares = 2; ShareAlgorithm: :EncryptThis(bmpImage); Matrix* TwoOfTwoAlgorithm: :ConstQualMatrix(int participants) { return KOfKAlgorithm: :ConstQualMatrix(participants); 1 // TwoOfTwoAlgorithm.h: interface for the TwoOfTwoAlgorithm class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_TWOOFTWOALGORITHM_H__E4C49522_ED2F_llD2_ADF2_A228685DC33C __ INCLUDED ) INCLUDED_ - ~define AFX_TWOOFTWOALGORITHM_H__ E4C49522_ED2F_llD2_ADF2_A228685DC33C #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "KOfKAlgorithm.h" class TwoOfTwoAlgorithm : public KOfKAlgorithm { public: TwoOfTwoAlgorithm(CBitrnap *irng, CView *cwin); TwoOfTwoAlgorithm() ; virtual -TwoOfTwoAlgorithm(); virtual void GetOptions(); // GetOptions loads up the dialog box for changing the encryption options virtual void EncryptThis(Bitrnaplrnage* brnplrnage); virtual Matrix* ConstQualMatrix(int participants); }; 1