Advertisement
1_2002 Encryption #104123

CipherII

A StreamCipher encryption similar to the first 'Cipher' but now it can encrypt any text or binary file.

AI

ملخص الذكاء الاصطناعي: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

كود المصدر
original-source
Public Function Cipher(PlainText, Secret)
Dim a, b, c
Dim pTb, cTb, cT
For i = 1 To Len(PlainText)
  pseudoi = i Mod Len(Secret)
  If pseudoi = 0 Then pseudoi = 1
  a = Mid(Secret, pseudoi, 1)
  b = Mid(Secret, pseudoi + 1, 1)
  c = Asc(a) Xor Asc(b)
  pTb = Mid(PlainText, i, 1)
  cTb = c Xor Asc(pTb)
  cT = cT + Chr(cTb)
  Form1.Label1.Caption = i
  DoEvents
Next i
EnCipher = cT
End Function
<html>
<body>
<font face="FixedSys" color="#BD0000">
<table width=450>
<tr>
<small><br><b> Win32 C/C++ Platform SDK Tutorial #1 - Intro to Windows Programming </b><br>
</small>
<br><br>
Well, I didnt see any tutorials on the PSC about win32 with platform SDK so I thought Id compliment all my examples with a nice explanation of the api. Im going to start from the bottom.
<br><br>
Programming under Microsoft windows isnt as hard as it might seem. Its actualy quite simple, its just a matter of memorizing the api calls, and knowing when to use them and in what order to get your event across. Doing this, in theory sounds simple but the actual process of memorization at times can become quite tedeious, but its worth the trouble.<br><br>
Now before begin talking about all the different api calls, and disscussing how to put them together with C++ code, lets just talk about how a windows program works. A windows application is just a program, with a main entry. When it starts, Windows, loads your program up, gets the right information and calls the windows main function. This function then is the start of your application just like when writing a console application. What happens is you call some functions create your windows, set there message processes, and then put your program into a loop. This while statement contiously loops, and every time windows recevies a message, it passes it to the correct message process. So basicly the program enters, you setup the window, and then put the program into a loop, the loop then sends the messages to the appropiate location and they are processed. Now that this is said, I am going to take all the api calls from the example skeleton to a win32 application, and describe what is happening step by step (code in green). and then I am going to take all the api and put it together to show you how it makes a windows app. So bear with me:
<br><br><font color="green">
#include "windows.h"</font><br>
this means include the header file, for windows<br><br>
<font color="green">
LRESULT APIENTRY WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);</font><br><br>
this is the function prototype, for a window message process. The window message
process is were windows messages are procecssed. Like when your window is closed
a WM_CLOSE message is sent to the WndProc, and within it you can put a block of code to process it and have it preform an action<br><br>
<font color="green"> int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR cmdline,int CmdShow)</font> <br><br>
this is the entry point for the windows application,this is called when the program starts.
<br><br>
<font color="green">
<br>{<br>HWND hwnd;<br><br></font> The Variable HWND stands for Window handle. Its really just a unsigned long to stand for id of are window.<br><br>
<font color="green">
WNDCLASS wc;<br><br></font> WNDCLASS means window class, and its a structure which has
some important variables we need to fill out, with information about are window<br><br>
<font color="green">
wc.cbClsExtra = 0;<br>
wc.cbWndExtra = 0;<br>
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);<br>
wc.hInstance = hInst;<br>
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);<br>
wc.hCursor = LoadCursor(NULL,IDC_ARROW);<br>
wc.lpszMenuName = NULL;<br>
wc.lpszClassName = "TheWindowClass";<br>
wc.lpfnWndProc = (WNDPROC) WndProc;<br>
wc.style = CS_HREDRAW | CS_VREDRAW;<br>
</font>
<br><br>
What we just did, was fill out the window class with all the appropriate information
cbClsExtra is not used by us 99.9% so we always set it to 0. The same with cbWndExtra.
hbrBackground stands for the background color of the window, and we select one with the function GetStockObject. hInst stands for the Instance of the Application, this variable
is passed in from WinMain entry. hIcon stands for the Icon for this window, and is loaded
into the variable with the LoadIcon function. hCursor stands for the cursor of this application and is loaded in with LoadCursor. lpszMenuName is set to NULL here, but it points to a menu resource if you wanted your window to have menu. lpszClassName is very imoporant. What goes in this variable is the name of the window class. This variable is then used when we create the window, so windows knows what Window information structure to use when it makes your window. lpfnWndProc is also a very important variable. This is a function pointer, which points to the function which will process this windows messages. The one we are going to be using is called WndProc, its prototype was defined near the top of the code, and its body will be after the WinMain function. the style variable stands for the method of which it will update on the redraw, I always choose CS_HREDRAW | CS_VREDRAW
<br><br>
<font color="green">
RegisterClass(&wc);<br><br></font>
What this function does, is register the window class structure we just filled out. Now windows has it registered and understands that the classname "TheWindowClass" stands for this paticular structure and window message process.<br><br>
<font color="green">
hwnd = CreateWindow("TheWindowClass","TheTitle",WS_OVERLAPPEDWINDOW,0,0,640,480,0,0,hInst,0);<br><br></font>
What this function does is fill are hwnd (Window handle we declared eailyer) with the index of the window that was created. The first parameter stands for the window class (we filled that out in the structure, and then registered it), the second parameter stands for the title. The third stands for the window styles (WS) , the forth stands for the x cordinate, the fifth stands for the y cordinate, the sixth stands for with cordinate, the seventh stands for the height cordinate, the eighth stands for a parent window, since we dont want one we set it 0, the ninth stands for the a menu, or a childs id, since this is a not a child window, and we dont not have a menu it is set to 0. The tenth parameter stands for the instance of are application which was passed in by the WinMain entry's first parameter. The eleventh parameter stands for the LPARAM and to us has no value as of now so it is set to 0.<br><br>
<font color="green">
ShowWindow(hwnd,SW_SHOW);
</font><br><br>
This function sets the window we just created, which we can now refernce by its handle to set the window to the show state.<br><br>
<font color="green">
UpdateWindow(hwnd);
</font>
<br><br>
What this function does is update the window after it has been shown. It forces windows to repaint the window.<br><br>
<font color="green">
MSG msg;<br>
while(GetMessage(&msg,0,0,0))<br><br>{<br>
TranslateMessage(&msg);<br>
Dispatchmessage(&msg);<br><br>}<br>
</font>
<br><br>
Now that are window has been created we setup are message loop. This will loop, and when messages are recived they will be sent to the apporpiate window message process<br><br>
<font color="green">
return msg.wParam;<br>
<br>
}
<br><br>
</font>
What this does, is when the loop finaly finishes (when your program has termianted)
the application returns and the program is removed from memory<br><br>
<font color="green">
LRESULT APIENTRY WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)<br>{<br>
switch(msg)<br>{<br>
case WM_DESTROY:<br>
PostQuitMessage(0);<br>
break;<br>
deafult: return DefWindowProc(hwnd,msg,wParam,lParam);<br>}<br>
return 0;<br>}<br>
</font><br><br>
This here is are windows message process. Since are application created are window, whenever are window is sent a message, that message is passed over here to the Message process. What happens is within the switch statement you pick out using cases the different messages you know that your window will be sent so that it can process and do different things. Like when the window is first created a WM_CREATE message is sent. The default case is put within the switch because it is important, that the DefWindowProc is returned<br><br><br>
Wrapping it all up <br><br>
Writing software to manipulate windows for our GUI is not hard since Microsoft pretty much does all the work for us. All we have to do is understand what to call and when to call it to get are task done. 
Now heres the code without all that stuff in the way:<br><br>
<font color="black">
#include "windows.h"<br>
<br>
LRESULT APIENTRY WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);<br><br>
int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR cmdline,int CmdShow)<br>
{<br>
HWND hwnd;<br>
WNDCLASS wc;<br>
wc.cbClsExtra = 0;<br>
wc.cbWndExtra = 0;<br>
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);<br>
wc.hInstance = hInst;<br>
wc.hCursor = LoadCursor(NULL,IDC_ARROW);<br>
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);<br>
wc.lpfnWndProc = (WNDPROC) WndProc;<br>
wc.lpszClassName = "TheWindowClass";<br>
wc.lpszMenuName = NULL;<br>
wc.style = CS_HREDRAW | CS_VREDRAW;<br>
<br>
RegisterClass(&wc);<br>
hwnd = CreateWindow("TheWindowClass","Title",WS_OVERLAPPEDWINDOW,0,0,640,480,0,0,hInst,0);<br>
ShowWindow(hwnd,SW_SHOW);<br>
UpdateWindow(hwnd);<br>
<br>
<br> MSG msg;<br><br>
while(GetMessage(&msg,0,0,0))<br>{<br>
TranslateMessage(&msg);<br>
DispatchMessage(&msg);<br>}<br>
return msg.wParam;<br>}<br>
<br>
LRESULT APIENTRY WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)<br>{<br>
switch(msg)<br>
{<br>
case WM_DESTROY:<br>
PostQuitMessage(0);<br>
break;<br>
default: return DefWindowProc(hwnd,msg,wParam,lParam);<br>}<br>
return 0;<br> }<br>
</font><br><br>
Check out my entrys for Win32 now for real Visual C++ Source Projects to see
Platform SDK in action<br><br>
well im off to sleep <br><br>
- Jared<br><br>
</font>
</tr>
</table>
</font>
</body>
</html>
التعليقات الأصلية (3)
مسترجع من Wayback Machine