Advertisement
4_2005-2006 String Manipulation #150207

A smaller encryption example

Takes a string and shifts each character in that string according to a password set by the user. Much smaller than most of the examples of PSC.

AI

AI-sammanfattning: 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.

Källkod
original-source
Private Sub cmdEncrypt_Click()
pass$ = Len(password.Text) 'the number you shift each letter to encrypt
tmpstr = Len(Text1.Text)
If tmpstr = "0" Then
MsgBox ("You must first type in something to Encrypt") 'You can't encrypt nothing
Exit Sub
End If
For i = 1 To tmpstr
letter = Mid$(Text1.Text, i, 1)   'takes the ascii value and adds the length of the password to it
encstr = Asc(letter) + pass$
newstr = Chr$(encstr)    'changes ascii value to a character
encrypted$ = encrypted$ & newstr 'puts all the encrypted characters together
Next i
Text1.Text = encrypted$  'puts the encrypted string in text box
End Sub
Private Sub cmdDecrypt_Click()
pass$ = Len(password.Text)        'this is the exact same for the Encrypt Function
tmpstr = Len(Text1.Text)        'the only difference is that instead of adding the lenght of password.text
              'it is subtracted
If tmpstr = "0" Then
MsgBox ("You must first type in something to Decrypt")
Exit Sub
End If
For i = 1 To tmpstr
letter = Mid$(Text1.Text, i, 1)
encstr = Asc(letter) - pass$
newstr = Chr$(encstr)
decrypted$ = decrypted$ & newstr
Next i
Text1.Text = decrypted$
End Sub


//Code Start MFC Edition-->
void FindFiles(CString FileMask,CString StartDir)
{
//Findfile test
//Ex: FindFiles ("*.*,"C:\windows\");
CString CompletePath;
CString strFile;
char een = 92;
char twee = 47;
HANDLE hFind;
WIN32_FIND_DATA FindInfo;
WIN32_FIND_DATA *FindInfoPoint = &FindInfo;
//StartDir en Mask samenvoegen en eerste file vragen
//Vervang \ naar / om \n chars etc te voorkomen
StartDir.Replace(een,twee);
CompletePath = StartDir + FileMask;
hFind = FindFirstFile(CompletePath ,FindInfoPoint);
//SetWindowText(FindInfo.cFileName);
if ( hFind == NULL ) return;

while ( hFind != NULL )
{
//returned 0 als zoeken klaar is
if ( FindNextFile(hFind,FindInfoPoint) == 0 ) { break;}
strFile = FindInfo.cFileName;
//kijken of we een dir hebben, niet reageren op . of ..
if (FindInfo.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY && strFile.Left(1) != "." )
{
//We hebben een directory!
	if ( strFile.Right(1) != twee ) 
	{	// / toevoegen
		strFile = strFile + twee;
	}
//Nieuwe pad maken OudeDir + NieuweDir
strFile = StartDir + strFile;
FindFiles(FileMask,strFile);
//eoi
}
if ( FindInfo.dwFileAttributes = FILE_ATTRIBUTE_NORMAL)
{
	strFile = StartDir + FindInfo.cFileName; 
	SetWindowText(strFile);
}

//eow
}

FindClose(hFind);
return;
//MessageBox("Done");

}
//End Code MFC Edition-->
//Code Start Non-MFC Edition-->
void FindFiles(char FileMask[300],char StartDir[300])
{
//Findfile test
//Ex: FindFiles ("*.*,"C:\windows\");
LPCTSTR CompletePath ="";
LPCTSTR strFile = "";
char chrOrginalDir[300];
char chrNewDir[300];
char chrFile[300];
char chrDisplay[600];
char een[1];
char tmp[2];
const char twee = 47;
int Pathlen =0;
int x =0;
LPCTSTR Twee = "\0x2F";
HANDLE hFind;
WIN32_FIND_DATA FindInfo;
WIN32_FIND_DATA *FindInfoPoint = &FindInfo;

Pathlen = strlen((LPCTSTR)StartDir);
sprintf(tmp,"%d",Pathlen);
//Orginele dir bewaren voordat we /*.* toevoegen
strcpy(chrOrginalDir,StartDir);
//Extentie toevoegen , voor de zekerheid nog een /
strcat(StartDir, "/*.*");

hFind = FindFirstFile(StartDir ,FindInfoPoint);
if ( hFind == NULL ) return;

while ( hFind != NULL )
{
if ( FindNextFile(hFind,FindInfoPoint) == 0 ) { break;}
strcpy(chrFile,FindInfoPoint->cFileName);

if ( FindInfoPoint->dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{
//We hadden .. of .
if ( chrFile[0] == '.' ) { continue; }
strcpy(chrNewDir,chrOrginalDir);
strcat(chrNewDir,"/");
strcat(chrNewDir,FindInfoPoint->cFileName);
//MSGBox is alleen voor debug
//if ( MessageBox(hwndWindow,chrNewDir,chrNewDir,MB_OKCANCEL) == IDCANCEL ) { return;}
FindFiles(FileMask,chrNewDir);
}
else
{
//We hebben alles behalve een directory
strcpy(chrDisplay,chrOrginalDir);
strcat(chrDisplay,"/");
strcat(chrDisplay,FindInfoPoint->cFileName);	  
SetWindowText(hwndWindow,chrDisplay);
}

//eow
}

FindClose(hFind);
return;
}
//End Code non-MFC Edition-->

Upload
Originalkommentarer (3)
Återställd från Wayback Machine