Accueil > > > ...UN PETIT ET SIMPLE CRYPTEUR TRÈS UTILE...
...UN PETIT ET SIMPLE CRYPTEUR TRÈS UTILE...
Information sur la source
Description
Voici le plus simple crypteur que la terre a connu !!! :) Mais bon je voulais juste que cela sert d'exmple ... Bon voila si vous avez des remarques intelligentes veuilliez s'il vous pliat les faire ;)
Source
- /************************************************************************
- * IRC - Internet Relay Chat, Sirck.cpp
- * Copyright (C) 2002 Elakoui Salim
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 164 Avenue de clichy 75017 Paris 0619238178
- */
-
- //Include Systeme
- #include <windows.h>
- #include <math.h>
- #include <time.h>
-
- //Mes Includes
- #include "resource.h"
-
- //Defines
- #define ID_AUTO_DETECT 0
- #define ID_CRYPTE 1
- #define ID_DECRYPTE 2
- #define CODE_CRYP 5203
-
- //Prototypes de fonctions
- int CALLBACK Crypt(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
- int depard(char *Name_of_fichier,int mmm);
- int CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
- int CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam);
- DWORD WINAPI convert(LPVOID);
-
-
- //Déclaration et Définition des classes et des stuctes
- struct Header
- {
- public:
- int code;
- double octec_coded;
- char Name_of_file[255];
- int len_name;
- };
-
-
- //Varaibles Globales
- HWND hWnd;
- HANDLE thread = 0;
- HANDLE th_dlg;
- HANDLE hFile = NULL;
- HANDLE hFile2 = NULL;
- Header buf_haed;
- int len_buff;
- int len_buff2;
- int modeb = 0;
- int anim = 0;
- int mode;
- char Name_of_fichier[255];
- char New_Name[255];
- char buff2[255];
- char buff[255];
-
- //Les fonctions et leurs définitions
-
- /************************************************************************
- - FONCTION : WinMain
- - ARGUMENTS : (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
- int nCmdShow) données par le systeme
- - RETERN : true ou false ca dépend
- - REMARQUE : principale fonction de ce programme ! donc faire tres attention
- dans la manipulation et a tt les therars la concernant...
- *************************************************************************/
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
-
- if (lpCmdLine[0] != 0)
- {
- depard(lpCmdLine,ID_AUTO_DETECT);//,ID_CRYPTE);
-
- }
- else
- {
- DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL, (DLGPROC)AppDlgProc);
- }
- return TRUE;
-
- }
-
-
- /************************************************************************
- - FONCTION : AppDlgProc
- - ARGUMENTS : HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam
- - RETERN : Pas d'importance à notre échelle
- - REMARQUE : C'est la principale fonction de procédure .... Y faire
- tres attention
- *************************************************************************/
- int CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
- {
- hWnd = hdlg;
-
- switch (mssg)
- {
- case WM_INITDIALOG:
- SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
- SetWindowText(hdlg,".:: @Crypter et Décrypter@ ::.");
- SetTimer(hdlg,12,500,NULL);
- break;
- case WM_TIMER:
- if (anim == 0)
- SetWindowText(hdlg,":.: @Crypter et Décrypter@ :.:");
- else if (anim == 1)
- SetWindowText(hdlg,"::. @Crypter et Décrypter@ .::");
- else
- {
- anim = 0;
- return SetWindowText(hdlg,".:: @Crypter et Décrypter@ ::.");
-
- }
- anim++;
- break;
- case WM_COMMAND:
- switch (wParam)
- {
- case IDCANCEL:
- EndDialog(hdlg,TRUE);
- break;
- case ID_HELP_ABOUT:
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hdlg,(DLGPROC) AboutDlgProc);
- break;
- case IDCANCEL2:
- OPENFILENAME ofn;
- char szFileName[255];
- memset(szFileName,0,255);
-
- //Remplissage de la structure
- ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
- ofn.lStructSize = sizeof( OPENFILENAME );
- ofn.hwndOwner = hdlg;
- ofn.hInstance = GetModuleHandle(NULL);
- lstrcpy( szFileName, TEXT("") );
- ofn.lpstrFile = szFileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_FILEMUSTEXIST;
- ofn.lpstrFilter = "Seb Files (*.SEB)\0*.SEB\0All Files (*.*)\0*.*\0";
- ofn.lpstrTitle = "...::Décrypter un fichier::...";
-
- //Utiliser la dialoque commune.. standard
- GetOpenFileName( &ofn );
-
- if (szFileName[0] != 0)
- {
- depard(szFileName,ID_DECRYPTE);
- }
- break;
- case IDCANCEL3:
- //Remplissage de la structure
- ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
- ofn.lStructSize = sizeof( OPENFILENAME );
- ofn.hwndOwner = hdlg;
- ofn.hInstance = GetModuleHandle(NULL);
- lstrcpy( szFileName, TEXT("") );
- ofn.lpstrFile = szFileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_FILEMUSTEXIST;
- ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
- ofn.lpstrTitle = "...::Crypter un fichier::...";
-
- //Utiliser la dialoque commune.. standard
- GetOpenFileName( &ofn );
-
- if (szFileName[0] != 0)
- depard(szFileName,ID_CRYPTE);
- break;
- }
- break;
- }
- return FALSE;
- }
-
-
- /************************************************************************
- - FONCTION : AboutDlgProc
- - ARGUMENTS : HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam
- - RETERN : Pas d'importance...
- - REMARQUE : La procédure de la dialogue About/a propos
- *************************************************************************/
- int CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDCANCEL:
- case IDOK:
- EndDialog(hwnd, IDCANCEL);
- break;
- }
- default:
- return FALSE;
- }
- return TRUE;
- }
-
-
- /************************************************************************
- - FONCTION : Confirm
- - ARGUMENTS : HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam
- - RETERN : Pas d'importance
- - REMARQUE : C'est la procédure de la dialogue confirme....
- *************************************************************************/
- int CALLBACK Confirm(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_INITDIALOG:
- if (mode == ID_CRYPTE)
- {
- SetDlgItemText(hwnd, IDC_EDIT2,buff);
- memset(buff2,0,255);
- strcpy(buff2,buff);
- len_buff2 = len_buff;
- buff2[len_buff2-1] = 'b';
- buff2[len_buff2-2] = 'e';
- buff2[len_buff2-3] = 's';
- SetDlgItemText(hwnd, IDC_EDIT3,buff2);
- SetWindowText(hwnd,"==============> Crypter");
-
- }
- else
- {
- SetDlgItemText(hwnd, IDC_EDIT2,buff);
- memset(buff2,0,255);
- for (int i =0; i < len_buff; i++)
- {
- buff2[i]= 255-buf_haed.Name_of_file[i];
- }
-
-
- len_buff2 = buf_haed.len_name;
- SetDlgItemText(hwnd, IDC_EDIT3,buff2);
- SetWindowText(hwnd,"==============> Décrypter");
-
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDOK:
- if (mode == ID_CRYPTE)
- {
- memset(&buf_haed,0,sizeof(buf_haed));
- for (int i =0; i < len_buff; i++)
- {
- buf_haed.Name_of_file[i]= 255-buff[i];
- }
-
- buf_haed.len_name = len_buff;
- memset(New_Name,0,255);
-
- GetDlgItemText(hwnd, IDC_EDIT3,New_Name,255);
- buf_haed.code = CODE_CRYP;
- memset(Name_of_fichier,0,255);
- strcpy(Name_of_fichier,buff);
-
- modeb = ID_CRYPTE;
- thread = CreateThread(NULL,
- NULL,
- convert,
- NULL,
- NULL,NULL);
-
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CRYPT), hwnd,(DLGPROC) Crypt);
- }
- else //ID_DECRYPTE
- {
- memset(Name_of_fichier,0,255);
- memset(New_Name,0,255);
- strcpy(Name_of_fichier,buff);
- GetDlgItemText(hwnd, IDC_EDIT3,New_Name,255);
-
- modeb = ID_DECRYPTE;
- thread = CreateThread(NULL,
- NULL,
- convert,
- NULL,
- NULL,NULL);
-
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CRYPT), hwnd,(DLGPROC) Crypt);
- }
- break;
- case IDCANCEL:
- EndDialog(hwnd, IDCANCEL);
- break;
- case IDPARCOURIR :
- OPENFILENAME ofn;
- char szFileName[255];
- memset(szFileName,0,255);
-
- // Fill out the OPENFILENAME struct
- ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
- ofn.lStructSize = sizeof( OPENFILENAME );
- ofn.hwndOwner = hwnd;
- ofn.hInstance = GetModuleHandle(NULL);
-
- ofn.lpstrFile = szFileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_OVERWRITEPROMPT;
-
- if (mode == ID_DECRYPTE)
- {
- ofn.lpstrFilter = "Seb Files (*.SEB)\0*.SEB\0";
- ofn.lpstrDefExt = ".SEB";
- }
- else
- {
- ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
- //ofn.lpstrDefExt = ".";
- }
- ofn.lpstrTitle = "...Choix du fichier...";
-
- // Use the common dialog
- GetSaveFileName( &ofn );
- if (szFileName[0] != 0)
- SetDlgItemText(hwnd, IDC_EDIT3,szFileName);
- break;
- }
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
-
- /************************************************************************
- - FONCTION : Crypt
- - ARGUMENTS : HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam
- - RETERN : Pas d'importance
- - REMARQUE : Idem
- *************************************************************************/
- int CALLBACK Crypt(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- th_dlg = hwnd;
- switch(Message)
- {
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDOK:
- EndDialog(hwnd, IDOK);
- break;
- case IDCANCEL:
- if (thread != 0)
- {
- SuspendThread(thread);
- int y = 0;
- if (mode == 1)
- y = MessageBox(hwnd,"Etes vous bien sur de vouloir quitter le déroulement du decryptage???","Confirmation",MB_YESNO | MB_ICONQUESTION );
- else
- y = MessageBox(hwnd,"Etes vous bien sur de vouloir quitter le déroulement du cryptage???","Confirmation",MB_YESNO | MB_ICONQUESTION );
- if (y == IDYES)
- {
- TerminateThread(thread,TRUE);
- CloseHandle(hFile2);
- CloseHandle(hFile);
- thread = 0;
- DeleteFile(New_Name);
- EndDialog(hwnd, IDCANCEL);
- }
- else
- ResumeThread(thread);
- }
-
- break;
- }
- break;
-
- default:
- return FALSE;
- }
- return TRUE;
- }
-
-
- /************************************************************************
- - FONCTION : depard
- - ARGUMENTS : char *Name_of_fichier,int mmm (le nouveau nom et le mode
- voulu)
- - RETERN : ca dépend (reussite - Echec)
- - REMARQUE : C'est la fonction que va etudier le ficier qu'on veut
- dé/crypter... Elle est importante dans la mesure ou elle
- repère les fautes et dans la mesure ou elle lit le heard
- et décode le nom.
- *************************************************************************/
- int depard(char *Name_of_fichier,int mmm)
- {
-
- int size = 0;
- int i = 0;
-
- memset(buff,0,255);
-
-
- //decodage du nom
- if (Name_of_fichier[0] == 34)
- {
- for (i =0 ;i < 255; i++)
- {
- if (Name_of_fichier[i+1] == 0 || Name_of_fichier[i+1] == 34)
- break;
- buff[i] = Name_of_fichier[i+1];
- }
- size = i;
-
- }
- else
- {
- for (i = 0 ;i < 255; i++)
- {
- if (Name_of_fichier[i] == 0)
- break;
- }
- strcpy(buff,Name_of_fichier);
- size = i;
-
- }
-
-
-
- len_buff = size;
- hFile = CreateFile(buff,
- GENERIC_READ,
- NULL,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
-
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- MessageBox(hWnd,buff,"Erreur Ouverture Impossible !",MB_ICONWARNING);
- return FALSE;
- }
-
-
- DWORD dw;
- ReadFile(hFile,&buf_haed,sizeof(Header),&dw,NULL);
-
-
- CloseHandle(hFile);
-
- if (mmm == ID_DECRYPTE)
- {
- if (dw != sizeof(Header) || CODE_CRYP != buf_haed.code)
- {
- MessageBox(NULL,"Ce fichier n'a pas été crypté par ce logiciel","Erreur",MB_ICONWARNING);
- }
- else
- {
- mode = ID_DECRYPTE;
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
- }
-
- }
- else if (mmm == ID_CRYPTE )
- {
- mode = ID_CRYPTE;
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
- }
- else if (mmm == ID_AUTO_DETECT )
- {
- if (dw != sizeof(Header) || CODE_CRYP != buf_haed.code )
- {
- mode = ID_CRYPTE;
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
- }
- else
- {
- mode = ID_DECRYPTE;
- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
- }
- }
- return TRUE;
- }
-
- /************************************************************************
- - FONCTION : convert
- - ARGUMENTS : RIEN
- - RETERN : TRUE ou FALSE
- - REMARQUE : fonction appelé par le thread.. c'est cettte dernière qui
- va s'occuper de la dé/cryptation :) (mot inventé)
- *************************************************************************/
- DWORD WINAPI convert(LPVOID)
- {
-
- if (modeb == ID_CRYPTE )
- {
- hFile = CreateFile(buff,
- GENERIC_READ,
- NULL,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
- hFile2 = CreateFile(New_Name,
- GENERIC_WRITE,
- NULL,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- DWORD dw;
- /*for (int i = 0; i <
- buf_haed.Name_of_file[i]*/
- WriteFile(hFile2,&buf_haed,sizeof(Header),&dw,NULL);
- if (hFile == INVALID_HANDLE_VALUE || hFile2 == INVALID_HANDLE_VALUE )
- {
- MessageBox(hWnd,"Eureur d'ouverture de fichier","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
-
- int gg = GetFileSize(hFile,NULL);
- char *a = new char [512];
- memset(a,0,512);
-
- for (int i = 0; i < gg ; i+=512)
- {
-
- if ((i + 512 ) >= gg)
- {
- int y = ReadFile(hFile,a,gg-i,&dw,NULL);
-
-
-
-
- if (y == FALSE || dw != (unsigned)(gg-i) )
- {
- MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
- for (int h = 0; h < (gg-i);h++)
- a[h] = 255-a[h];
- y = WriteFile(hFile2,a,gg-i,&dw,NULL);
- if (y == FALSE || dw != (unsigned)(gg-i))
- {
- MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
-
- memset(a,0,512);
- break;
- }
- else
- {
- int y = ReadFile(hFile,a,512,&dw,NULL);
-
- if (y == FALSE || dw != 512)
- {
- MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
- for (int h = 0; h < 512;h++)
- a[h] = 255-a[h];
- y = WriteFile(hFile2,a,512,&dw,NULL);
- if (y == FALSE || dw != 512)
- {
- MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
-
- memset(a,0,512);
- }
-
- }
-
- CloseHandle(hFile2);
- }
- else
- {
- hFile = CreateFile(buff,
- GENERIC_READ,
- NULL,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
-
- hFile2 = CreateFile(New_Name,
- GENERIC_WRITE,
- NULL,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (hFile == INVALID_HANDLE_VALUE || hFile2 == INVALID_HANDLE_VALUE )
- {
- MessageBox(hWnd,"Erreur d'ouverture de fichier","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
- DWORD dw;
-
- SetFilePointer(hFile,sizeof(Header),NULL,FILE_BEGIN);
-
- int gg = GetFileSize(hFile,NULL)-sizeof(Header);
- char *a = new char [512];
- memset(a,0,512);
-
- char b[255];
- memset(b,0,255);
- wsprintf(b,"%ld",gg);
-
- for (int i = 0; i < gg ; i+=512)
- {
-
- if ((i + 512 ) >= gg)
- {
- int y = ReadFile(hFile,a,gg-i,&dw,NULL);
-
-
- if (y == FALSE || dw != (unsigned)(gg-i))
- {
- MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
- for (int h = 0; h < (gg-i);h++)
- a[h] = 255-a[h];
- y = WriteFile(hFile2,a,gg-i,&dw,NULL);
- if (y == FALSE || dw != (unsigned)(gg-i))
- {
- MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
-
- memset(a,0,512);
- break;
- }
- else
- {
- int y = ReadFile(hFile,a,512,&dw,NULL);
-
- if (y == FALSE || dw != 512)
- {
- MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
- for (int h = 0; h < 512;h++)
- a[h] = 255-a[h];
- y = WriteFile(hFile2,a,512,&dw,NULL);
-
- if (y == FALSE || dw != 512)
- {
- MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return FALSE;
- }
-
- memset(a,0,512);
- }
-
- }
-
- CloseHandle(hFile2);
-
-
- }
- CloseHandle(hFile);
- thread = 0;
- EndDialog(th_dlg,IDOK);
- return TRUE;
- }
-
-
/************************************************************************
* IRC - Internet Relay Chat, Sirck.cpp
* Copyright (C) 2002 Elakoui Salim
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 164 Avenue de clichy 75017 Paris 0619238178
*/
//Include Systeme
#include <windows.h>
#include <math.h>
#include <time.h>
//Mes Includes
#include "resource.h"
//Defines
#define ID_AUTO_DETECT 0
#define ID_CRYPTE 1
#define ID_DECRYPTE 2
#define CODE_CRYP 5203
//Prototypes de fonctions
int CALLBACK Crypt(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
int depard(char *Name_of_fichier,int mmm);
int CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
int CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam);
DWORD WINAPI convert(LPVOID);
//Déclaration et Définition des classes et des stuctes
struct Header
{
public:
int code;
double octec_coded;
char Name_of_file[255];
int len_name;
};
//Varaibles Globales
HWND hWnd;
HANDLE thread = 0;
HANDLE th_dlg;
HANDLE hFile = NULL;
HANDLE hFile2 = NULL;
Header buf_haed;
int len_buff;
int len_buff2;
int modeb = 0;
int anim = 0;
int mode;
char Name_of_fichier[255];
char New_Name[255];
char buff2[255];
char buff[255];
//Les fonctions et leurs définitions
/************************************************************************
- FONCTION : WinMain
- ARGUMENTS : (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow) données par le systeme
- RETERN : true ou false ca dépend
- REMARQUE : principale fonction de ce programme ! donc faire tres attention
dans la manipulation et a tt les therars la concernant...
*************************************************************************/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
if (lpCmdLine[0] != 0)
{
depard(lpCmdLine,ID_AUTO_DETECT);//,ID_CRYPTE);
}
else
{
DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL, (DLGPROC)AppDlgProc);
}
return TRUE;
}
/************************************************************************
- FONCTION : AppDlgProc
- ARGUMENTS : HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam
- RETERN : Pas d'importance à notre échelle
- REMARQUE : C'est la principale fonction de procédure .... Y faire
tres attention
*************************************************************************/
int CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
hWnd = hdlg;
switch (mssg)
{
case WM_INITDIALOG:
SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
SetWindowText(hdlg,".:: @Crypter et Décrypter@ ::.");
SetTimer(hdlg,12,500,NULL);
break;
case WM_TIMER:
if (anim == 0)
SetWindowText(hdlg,":.: @Crypter et Décrypter@ :.:");
else if (anim == 1)
SetWindowText(hdlg,"::. @Crypter et Décrypter@ .::");
else
{
anim = 0;
return SetWindowText(hdlg,".:: @Crypter et Décrypter@ ::.");
}
anim++;
break;
case WM_COMMAND:
switch (wParam)
{
case IDCANCEL:
EndDialog(hdlg,TRUE);
break;
case ID_HELP_ABOUT:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hdlg,(DLGPROC) AboutDlgProc);
break;
case IDCANCEL2:
OPENFILENAME ofn;
char szFileName[255];
memset(szFileName,0,255);
//Remplissage de la structure
ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hdlg;
ofn.hInstance = GetModuleHandle(NULL);
lstrcpy( szFileName, TEXT("") );
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.lpstrFilter = "Seb Files (*.SEB)\0*.SEB\0All Files (*.*)\0*.*\0";
ofn.lpstrTitle = "...::Décrypter un fichier::...";
//Utiliser la dialoque commune.. standard
GetOpenFileName( &ofn );
if (szFileName[0] != 0)
{
depard(szFileName,ID_DECRYPTE);
}
break;
case IDCANCEL3:
//Remplissage de la structure
ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hdlg;
ofn.hInstance = GetModuleHandle(NULL);
lstrcpy( szFileName, TEXT("") );
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
ofn.lpstrTitle = "...::Crypter un fichier::...";
//Utiliser la dialoque commune.. standard
GetOpenFileName( &ofn );
if (szFileName[0] != 0)
depard(szFileName,ID_CRYPTE);
break;
}
break;
}
return FALSE;
}
/************************************************************************
- FONCTION : AboutDlgProc
- ARGUMENTS : HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam
- RETERN : Pas d'importance...
- REMARQUE : La procédure de la dialogue About/a propos
*************************************************************************/
int CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
case IDOK:
EndDialog(hwnd, IDCANCEL);
break;
}
default:
return FALSE;
}
return TRUE;
}
/************************************************************************
- FONCTION : Confirm
- ARGUMENTS : HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam
- RETERN : Pas d'importance
- REMARQUE : C'est la procédure de la dialogue confirme....
*************************************************************************/
int CALLBACK Confirm(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
if (mode == ID_CRYPTE)
{
SetDlgItemText(hwnd, IDC_EDIT2,buff);
memset(buff2,0,255);
strcpy(buff2,buff);
len_buff2 = len_buff;
buff2[len_buff2-1] = 'b';
buff2[len_buff2-2] = 'e';
buff2[len_buff2-3] = 's';
SetDlgItemText(hwnd, IDC_EDIT3,buff2);
SetWindowText(hwnd,"==============> Crypter");
}
else
{
SetDlgItemText(hwnd, IDC_EDIT2,buff);
memset(buff2,0,255);
for (int i =0; i < len_buff; i++)
{
buff2[i]= 255-buf_haed.Name_of_file[i];
}
len_buff2 = buf_haed.len_name;
SetDlgItemText(hwnd, IDC_EDIT3,buff2);
SetWindowText(hwnd,"==============> Décrypter");
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
if (mode == ID_CRYPTE)
{
memset(&buf_haed,0,sizeof(buf_haed));
for (int i =0; i < len_buff; i++)
{
buf_haed.Name_of_file[i]= 255-buff[i];
}
buf_haed.len_name = len_buff;
memset(New_Name,0,255);
GetDlgItemText(hwnd, IDC_EDIT3,New_Name,255);
buf_haed.code = CODE_CRYP;
memset(Name_of_fichier,0,255);
strcpy(Name_of_fichier,buff);
modeb = ID_CRYPTE;
thread = CreateThread(NULL,
NULL,
convert,
NULL,
NULL,NULL);
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CRYPT), hwnd,(DLGPROC) Crypt);
}
else //ID_DECRYPTE
{
memset(Name_of_fichier,0,255);
memset(New_Name,0,255);
strcpy(Name_of_fichier,buff);
GetDlgItemText(hwnd, IDC_EDIT3,New_Name,255);
modeb = ID_DECRYPTE;
thread = CreateThread(NULL,
NULL,
convert,
NULL,
NULL,NULL);
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CRYPT), hwnd,(DLGPROC) Crypt);
}
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
case IDPARCOURIR :
OPENFILENAME ofn;
char szFileName[255];
memset(szFileName,0,255);
// Fill out the OPENFILENAME struct
ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hwnd;
ofn.hInstance = GetModuleHandle(NULL);
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_OVERWRITEPROMPT;
if (mode == ID_DECRYPTE)
{
ofn.lpstrFilter = "Seb Files (*.SEB)\0*.SEB\0";
ofn.lpstrDefExt = ".SEB";
}
else
{
ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
//ofn.lpstrDefExt = ".";
}
ofn.lpstrTitle = "...Choix du fichier...";
// Use the common dialog
GetSaveFileName( &ofn );
if (szFileName[0] != 0)
SetDlgItemText(hwnd, IDC_EDIT3,szFileName);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
/************************************************************************
- FONCTION : Crypt
- ARGUMENTS : HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam
- RETERN : Pas d'importance
- REMARQUE : Idem
*************************************************************************/
int CALLBACK Crypt(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
th_dlg = hwnd;
switch(Message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
if (thread != 0)
{
SuspendThread(thread);
int y = 0;
if (mode == 1)
y = MessageBox(hwnd,"Etes vous bien sur de vouloir quitter le déroulement du decryptage???","Confirmation",MB_YESNO | MB_ICONQUESTION );
else
y = MessageBox(hwnd,"Etes vous bien sur de vouloir quitter le déroulement du cryptage???","Confirmation",MB_YESNO | MB_ICONQUESTION );
if (y == IDYES)
{
TerminateThread(thread,TRUE);
CloseHandle(hFile2);
CloseHandle(hFile);
thread = 0;
DeleteFile(New_Name);
EndDialog(hwnd, IDCANCEL);
}
else
ResumeThread(thread);
}
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
/************************************************************************
- FONCTION : depard
- ARGUMENTS : char *Name_of_fichier,int mmm (le nouveau nom et le mode
voulu)
- RETERN : ca dépend (reussite - Echec)
- REMARQUE : C'est la fonction que va etudier le ficier qu'on veut
dé/crypter... Elle est importante dans la mesure ou elle
repère les fautes et dans la mesure ou elle lit le heard
et décode le nom.
*************************************************************************/
int depard(char *Name_of_fichier,int mmm)
{
int size = 0;
int i = 0;
memset(buff,0,255);
//decodage du nom
if (Name_of_fichier[0] == 34)
{
for (i =0 ;i < 255; i++)
{
if (Name_of_fichier[i+1] == 0 || Name_of_fichier[i+1] == 34)
break;
buff[i] = Name_of_fichier[i+1];
}
size = i;
}
else
{
for (i = 0 ;i < 255; i++)
{
if (Name_of_fichier[i] == 0)
break;
}
strcpy(buff,Name_of_fichier);
size = i;
}
len_buff = size;
hFile = CreateFile(buff,
GENERIC_READ,
NULL,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
MessageBox(hWnd,buff,"Erreur Ouverture Impossible !",MB_ICONWARNING);
return FALSE;
}
DWORD dw;
ReadFile(hFile,&buf_haed,sizeof(Header),&dw,NULL);
CloseHandle(hFile);
if (mmm == ID_DECRYPTE)
{
if (dw != sizeof(Header) || CODE_CRYP != buf_haed.code)
{
MessageBox(NULL,"Ce fichier n'a pas été crypté par ce logiciel","Erreur",MB_ICONWARNING);
}
else
{
mode = ID_DECRYPTE;
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
}
}
else if (mmm == ID_CRYPTE )
{
mode = ID_CRYPTE;
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
}
else if (mmm == ID_AUTO_DETECT )
{
if (dw != sizeof(Header) || CODE_CRYP != buf_haed.code )
{
mode = ID_CRYPTE;
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
}
else
{
mode = ID_DECRYPTE;
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONFIRME),hWnd,(DLGPROC) Confirm);
}
}
return TRUE;
}
/************************************************************************
- FONCTION : convert
- ARGUMENTS : RIEN
- RETERN : TRUE ou FALSE
- REMARQUE : fonction appelé par le thread.. c'est cettte dernière qui
va s'occuper de la dé/cryptation :) (mot inventé)
*************************************************************************/
DWORD WINAPI convert(LPVOID)
{
if (modeb == ID_CRYPTE )
{
hFile = CreateFile(buff,
GENERIC_READ,
NULL,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
hFile2 = CreateFile(New_Name,
GENERIC_WRITE,
NULL,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
DWORD dw;
/*for (int i = 0; i <
buf_haed.Name_of_file[i]*/
WriteFile(hFile2,&buf_haed,sizeof(Header),&dw,NULL);
if (hFile == INVALID_HANDLE_VALUE || hFile2 == INVALID_HANDLE_VALUE )
{
MessageBox(hWnd,"Eureur d'ouverture de fichier","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
int gg = GetFileSize(hFile,NULL);
char *a = new char [512];
memset(a,0,512);
for (int i = 0; i < gg ; i+=512)
{
if ((i + 512 ) >= gg)
{
int y = ReadFile(hFile,a,gg-i,&dw,NULL);
if (y == FALSE || dw != (unsigned)(gg-i) )
{
MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
for (int h = 0; h < (gg-i);h++)
a[h] = 255-a[h];
y = WriteFile(hFile2,a,gg-i,&dw,NULL);
if (y == FALSE || dw != (unsigned)(gg-i))
{
MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
memset(a,0,512);
break;
}
else
{
int y = ReadFile(hFile,a,512,&dw,NULL);
if (y == FALSE || dw != 512)
{
MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
for (int h = 0; h < 512;h++)
a[h] = 255-a[h];
y = WriteFile(hFile2,a,512,&dw,NULL);
if (y == FALSE || dw != 512)
{
MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
memset(a,0,512);
}
}
CloseHandle(hFile2);
}
else
{
hFile = CreateFile(buff,
GENERIC_READ,
NULL,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
hFile2 = CreateFile(New_Name,
GENERIC_WRITE,
NULL,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE || hFile2 == INVALID_HANDLE_VALUE )
{
MessageBox(hWnd,"Erreur d'ouverture de fichier","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
DWORD dw;
SetFilePointer(hFile,sizeof(Header),NULL,FILE_BEGIN);
int gg = GetFileSize(hFile,NULL)-sizeof(Header);
char *a = new char [512];
memset(a,0,512);
char b[255];
memset(b,0,255);
wsprintf(b,"%ld",gg);
for (int i = 0; i < gg ; i+=512)
{
if ((i + 512 ) >= gg)
{
int y = ReadFile(hFile,a,gg-i,&dw,NULL);
if (y == FALSE || dw != (unsigned)(gg-i))
{
MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
for (int h = 0; h < (gg-i);h++)
a[h] = 255-a[h];
y = WriteFile(hFile2,a,gg-i,&dw,NULL);
if (y == FALSE || dw != (unsigned)(gg-i))
{
MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
memset(a,0,512);
break;
}
else
{
int y = ReadFile(hFile,a,512,&dw,NULL);
if (y == FALSE || dw != 512)
{
MessageBox(hWnd,"Erreur de lecteur ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
for (int h = 0; h < 512;h++)
a[h] = 255-a[h];
y = WriteFile(hFile2,a,512,&dw,NULL);
if (y == FALSE || dw != 512)
{
MessageBox(hWnd,"Erreur d'écriture ! Opération echouée","Erreur",MB_ICONWARNING);
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return FALSE;
}
memset(a,0,512);
}
}
CloseHandle(hFile2);
}
CloseHandle(hFile);
thread = 0;
EndDialog(th_dlg,IDOK);
return TRUE;
}
Conclusion
Bon voila ....
COMMENTAIRE !
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|