vor einem weilchen war mir langweilig und ich bin auf die Idee
gekommen mir ein kleines Prog zu schreiben das Text verschlüsselt,
bzw wieder entschlüsselt.
Gesagt getan.
Es funktioniert auch ganz gut, es hat nur eine kleine Macke.
Wenn man den ersten Buchstaben aus der Codierungsliste
verwendet, stürtzt das Prog ab.
BSP:
char code3 []="cdefghijklmnopqrstuvwxyz äöü,.ab";
char code31[]="CDEFGHIJKLMNOPQRSTUVWXYZ*ÄÖÜ**AB";
hier wäre es "c" bzw "C".
Hier ist das Prog:
Code: Alles auswählen
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
HWND hWnd;
HMENU hMenu;
HMENU hSubMenu;
HMENU hSubSubMenu1;
HMENU hSubSubMenu2;
HINSTANCE hInst2;
HWND textfeld;
HWND Codiren;
HWND Decodiren;
HWND Ausgabe;
char tAusgabe[30001];
int Code=1;
int zV;
char code1 []="abcdefghijklmnopqrstuvwxyz äöü,.";
char code11[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ*ÄÖÜ**";
char code2 []="bcdefghijklmnopqrstuvwxyz äöü,.a";
char code21[]="BCDEFGHIJKLMNOPQRSTUVWXYZ*ÄÖÜ**A";
char code3 []="cdefghijklmnopqrstuvwxyz äöü,.ab";
char code31[]="CDEFGHIJKLMNOPQRSTUVWXYZ*ÄÖÜ**AB";
char bin[32][6]= {"00000","00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010","11011","11100","11101","11110","11111"};
void textdrucken(char code[30001])
{
DestroyWindow(Ausgabe);
Ausgabe = CreateWindow("STATIC",
code,
WS_VISIBLE | WS_CHILD | ES_CENTER | ES_AUTOVSCROLL,
5, 85,
290, 200,
hWnd,
(HMENU) 1000,
hInst2,
NULL);
}
void codieren()
{
char ende[]="\0";
sprintf(tAusgabe,"%s", ende);
char text[5001];
char code[30001];
char vcode[32];
char vcode2[32];
int durchgang;
if(Code==1)
{
strcpy(vcode, code1);
strcpy(vcode2, code11);
}
else if(Code==2)
{
strcpy(vcode, code2);
strcpy(vcode2, code21);
}
else
{
strcpy(vcode, code3);
strcpy(vcode2, code31);
}
durchgang++;
GetWindowText(textfeld, text, 5000);
int zeichen = strlen(text);
for(int i=0; i<zeichen; i++)
{
if(text[i]==vcode[0] || text[i]==vcode2[0])
{
sprintf(code,"%s%s", code, bin[0]);
}
else if(text[i]==vcode[1] || text[i]==vcode2[1])
{
sprintf(code,"%s%s", code, bin[1]);
}
else if(text[i]==vcode[2] || text[i]==vcode2[0])
{
sprintf(code,"%s%s", code, bin[2]);
}
else if(text[i]==vcode[3] || text[i]==vcode2[3])
{
sprintf(code,"%s%s", code, bin[3]);
}
else if(text[i]==vcode[4] || text[i]==vcode2[4])
{
sprintf(code,"%s%s", code, bin[4]);
}
else if(text[i]==vcode[5] || text[i]==vcode2[5])
{
sprintf(code,"%s%s", code, bin[5]);
}
else if(text[i]==vcode[6] || text[i]==vcode2[6])
{
sprintf(code,"%s%s", code, bin[6]);
}
else if(text[i]==vcode[7] || text[i]==vcode2[7])
{
sprintf(code,"%s%s", code, bin[7]);
}
else if(text[i]==vcode[8] || text[i]==vcode2[8])
{
sprintf(code,"%s%s", code, bin[8]);
}
else if(text[i]==vcode[9] || text[i]==vcode2[9])
{
sprintf(code,"%s%s", code, bin[9]);
}
else if(text[i]==vcode[10] || text[i]==vcode2[10])
{
sprintf(code,"%s%s", code, bin[10]);
}
else if(text[i]==vcode[11] || text[i]==vcode2[11])
{
sprintf(code,"%s%s", code, bin[11]);
}
else if(text[i]==vcode[12] || text[i]==vcode2[12])
{
sprintf(code,"%s%s", code, bin[12]);
}
else if(text[i]==vcode[13] || text[i]==vcode2[13])
{
sprintf(code,"%s%s", code, bin[13]);
}
else if(text[i]==vcode[14] || text[i]==vcode2[14])
{
sprintf(code,"%s%s", code, bin[14]);
}
else if(text[i]==vcode[15] || text[i]==vcode2[15])
{
sprintf(code,"%s%s", code, bin[15]);
}
else if(text[i]==vcode[16] || text[i]==vcode2[16])
{
sprintf(code,"%s%s", code, bin[16]);
}
else if(text[i]==vcode[17] || text[i]==vcode2[17])
{
sprintf(code,"%s%s", code, bin[17]);
}
else if(text[i]==vcode[18] || text[i]==vcode2[18])
{
sprintf(code,"%s%s", code, bin[18]);
}
else if(text[i]==vcode[19] || text[i]==vcode2[19])
{
sprintf(code,"%s%s", code, bin[19]);
}
else if(text[i]==vcode[20] || text[i]==vcode2[20])
{
sprintf(code,"%s%s", code, bin[20]);
}
else if(text[i]==vcode[21] || text[i]==vcode2[21])
{
sprintf(code,"%s%s", code, bin[21]);
}
else if(text[i]==vcode[22] || text[i]==vcode2[22])
{
sprintf(code,"%s%s", code, bin[22]);
}
else if(text[i]==vcode[23] || text[i]==vcode2[23])
{
sprintf(code,"%s%s", code, bin[23]);
}
else if(text[i]==vcode[24] || text[i]==vcode2[24])
{
sprintf(code,"%s%s", code, bin[24]);
}
else if(text[i]==vcode[25] || text[i]==vcode2[25])
{
sprintf(code,"%s%s", code, bin[25]);
}
else if(text[i]==vcode[26] || text[i]==vcode2[26])
{
sprintf(code,"%s%s", code, bin[26]);
}
else if(text[i]==vcode[27] || text[i]==vcode2[27])
{
sprintf(code,"%s%s", code, bin[27]);
}
else if(text[i]==vcode[28] || text[i]==vcode2[18])
{
sprintf(code,"%s%s", code, bin[28]);
}
else if(text[i]==vcode[29] || text[i]==vcode2[29])
{
sprintf(code,"%s%s", code, bin[29]);
}
else if(text[i]==vcode[30] || text[i]==vcode2[30])
{
sprintf(code,"%s%s", code, bin[30]);
}
else if(text[i]==vcode[31] || text[i]==vcode2[31])
{
sprintf(code,"%s%s", code, bin[31]);
}
else if(text[i]==vcode[32] || text[i]==vcode2[32])
{
sprintf(code,"%s%s", code, bin[32]);
}
else
{
sprintf(code,"%s%s", code, text[i]);
}
srand(time(NULL)+i);
int zufall = rand() % 2;
sprintf(code,"%s%d", code, zufall);
}
sprintf(tAusgabe,"%s%s", tAusgabe, code);
return;
}
LRESULT CALLBACK WindowProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX windowclass;
MSG message;
hInst2 = hInst;
const char szClassName[] = "SL Coder";
windowclass.cbSize = sizeof (WNDCLASSEX);
windowclass.style = CS_HREDRAW | CS_VREDRAW;
windowclass.lpfnWndProc = WindowProc;
windowclass.cbClsExtra = 0;
windowclass.cbWndExtra = 0;
windowclass.hInstance = hInst;
windowclass.hIcon =LoadIcon (NULL, IDI_APPLICATION);
windowclass.hIconSm =LoadIcon (NULL, IDI_APPLICATION);
windowclass.hCursor =LoadCursor (NULL, IDC_ARROW);
windowclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND+1;
windowclass.lpszMenuName = NULL;
windowclass.lpszClassName = szClassName;
if(!RegisterClassEx (&windowclass))
return (0);
hWnd = CreateWindowEx(NULL,
szClassName,
"Wecker",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100,
308, 200,
NULL,
NULL,
hInst,
NULL);
textfeld = CreateWindow("EDIT",
"",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOVSCROLL,
5, 5,
290, 50,
hWnd,
(HMENU) 1002,
hInst,
NULL);
Codiren = CreateWindow("Button",
"Codiren",
BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD,
5, 60,
142, 20,
hWnd,
(HMENU) 10000,
hInst,
NULL);
Decodiren = CreateWindow("Button",
"Decodiren",
BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD,
153, 60,
142, 20,
hWnd,
(HMENU) 10001,
hInst,
NULL);
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
hSubSubMenu1 = CreatePopupMenu();
hSubSubMenu2 = CreatePopupMenu();
AppendMenu(hSubSubMenu1, MF_STRING | MF_CHECKED, 1000, "Code 1");
AppendMenu(hSubSubMenu1, MF_STRING, 1001, "Code 2");
AppendMenu(hSubSubMenu1, MF_STRING, 1002, "Code 3");
AppendMenu(hSubMenu, MF_STRING | MF_POPUP, (UINT) hSubSubMenu1, "Code");
AppendMenu(hSubSubMenu2, MF_STRING, 2000, "Zweit Verschlüsselung");
AppendMenu(hSubSubMenu2, MF_SEPARATOR, 0, "");
AppendMenu(hSubSubMenu2, MF_STRING | MF_GRAYED, 2001, "Sicherheits Stufe 1");
AppendMenu(hSubSubMenu2, MF_STRING | MF_GRAYED, 2002, "Sicherheits Stufe 2");
AppendMenu(hSubSubMenu2, MF_STRING | MF_GRAYED, 2003, "Sicherheits Stufe 3");
AppendMenu(hSubSubMenu2, MF_STRING | MF_GRAYED, 2004, "Sicherheits Stufe 4");
AppendMenu(hSubSubMenu2, MF_STRING | MF_GRAYED, 2005, "Sicherheits Stufe 5");
AppendMenu(hSubMenu, MF_STRING | MF_POPUP, (UINT) hSubSubMenu2, "Zweit Verschlüsselung");
AppendMenu(hSubMenu, MF_SEPARATOR, 0, "");
AppendMenu(hSubMenu, MF_STRING, 5000, "Beenden");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT) hSubMenu, "Einstellungen");
AppendMenu(hMenu, MF_STRING, 1000, "Anleitung");
AppendMenu(hMenu, MF_STRING, 1000, "Anleitung");
SetMenu(hWnd, hMenu);
if(hWnd == NULL)
return (0);
while (GetMessage (&message, NULL, 0, 0))
{
TranslateMessage (&message);
DispatchMessage (&message);
}
return (int)(message.wParam);
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return (0);
}
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_ESCAPE:
{
PostQuitMessage (0);
return (0);
}
}
}
case WM_COMMAND:
{
switch(wParam)
{
case 1000:
{
CheckMenuItem(hMenu, 1000, MF_CHECKED);
CheckMenuItem(hMenu, 1001, MF_UNCHECKED);
CheckMenuItem(hMenu, 1002, MF_UNCHECKED);
Code =1;
return (0);
}
case 1001:
{
CheckMenuItem(hMenu, 1000, MF_UNCHECKED);
CheckMenuItem(hMenu, 1001, MF_CHECKED);
CheckMenuItem(hMenu, 1002, MF_UNCHECKED);
Code =2;
return (0);
}
case 1002:
{
CheckMenuItem(hMenu, 1000, MF_UNCHECKED);
CheckMenuItem(hMenu, 1001, MF_UNCHECKED);
CheckMenuItem(hMenu, 1002, MF_CHECKED);
Code =3;
return (0);
}
case 2000:
{
if(zV==0)
{
CheckMenuItem(hMenu, 2000, MF_CHECKED);
EnableMenuItem(hMenu, 2001, MF_ENABLED);
EnableMenuItem(hMenu, 2002, MF_ENABLED);
EnableMenuItem(hMenu, 2003, MF_ENABLED);
EnableMenuItem(hMenu, 2004, MF_ENABLED);
EnableMenuItem(hMenu, 2005, MF_ENABLED);
CheckMenuItem(hMenu, 2005, MF_CHECKED);
zV=5;
return (0);
}
else
{
CheckMenuItem(hMenu, 2000, MF_UNCHECKED);
CheckMenuItem(hMenu, 2001, MF_UNCHECKED);
CheckMenuItem(hMenu, 2002, MF_UNCHECKED);
CheckMenuItem(hMenu, 2003, MF_UNCHECKED);
CheckMenuItem(hMenu, 2004, MF_UNCHECKED);
CheckMenuItem(hMenu, 2005, MF_UNCHECKED);
EnableMenuItem(hMenu, 2001, MF_GRAYED);
EnableMenuItem(hMenu, 2002, MF_GRAYED);
EnableMenuItem(hMenu, 2003, MF_GRAYED);
EnableMenuItem(hMenu, 2004, MF_GRAYED);
EnableMenuItem(hMenu, 2005, MF_GRAYED);
zV=0;
return (0);
}
}
case 2001:
{
CheckMenuItem(hMenu, 2001, MF_CHECKED);
CheckMenuItem(hMenu, 2002, MF_UNCHECKED);
CheckMenuItem(hMenu, 2003, MF_UNCHECKED);
CheckMenuItem(hMenu, 2004, MF_UNCHECKED);
CheckMenuItem(hMenu, 2005, MF_UNCHECKED);
zV=1;
return (0);
}
case 2002:
{
CheckMenuItem(hMenu, 2001, MF_UNCHECKED);
CheckMenuItem(hMenu, 2002, MF_CHECKED);
CheckMenuItem(hMenu, 2003, MF_UNCHECKED);
CheckMenuItem(hMenu, 2004, MF_UNCHECKED);
CheckMenuItem(hMenu, 2005, MF_UNCHECKED);
zV=2;
return (0);
}
case 2003:
{
CheckMenuItem(hMenu, 2001, MF_UNCHECKED);
CheckMenuItem(hMenu, 2002, MF_UNCHECKED);
CheckMenuItem(hMenu, 2003, MF_CHECKED);
CheckMenuItem(hMenu, 2004, MF_UNCHECKED);
CheckMenuItem(hMenu, 2005, MF_UNCHECKED);
zV=3;
}
case 2004:
{
CheckMenuItem(hMenu, 2001, MF_UNCHECKED);
CheckMenuItem(hMenu, 2002, MF_UNCHECKED);
CheckMenuItem(hMenu, 2003, MF_UNCHECKED);
CheckMenuItem(hMenu, 2004, MF_CHECKED);
CheckMenuItem(hMenu, 2005, MF_UNCHECKED);
zV=4;
return (0);
}
case 2005:
{
CheckMenuItem(hMenu, 2001, MF_UNCHECKED);
CheckMenuItem(hMenu, 2002, MF_UNCHECKED);
CheckMenuItem(hMenu, 2003, MF_UNCHECKED);
CheckMenuItem(hMenu, 2004, MF_UNCHECKED);
CheckMenuItem(hMenu, 2005, MF_CHECKED);
zV=5;
return (0);
}
case 5000:
{
PostQuitMessage (0);
return (0);
}
case 10000:
{
codieren();
return (0);
}
}
return (0);
}
}
return (DefWindowProc (hWnd, message, wParam, lParam));
}
Programm auf das für die Problem behebung wichtigen teil gekürtz habe.
(ich will ja nicht das jeder weis wie man es am ende entschlüsselt).
Vermutlich ist der Fehler ganz banal und ich seh ihn nicht weil ich das Programm
zu lange angestart habe auf der suche nach dem Fehlerteufel.
Würde mich freuen wenn mir jemand helfen kann.
mfg
Empire