?? csha1test.cpp
字號:
#define WIN32_LEAN_AND_MEAN
#include <stdlib.h>
#include <string.h> // Needed for strlen(...)
#include "CSHA1Test.h" // Test driver header file
#include "CSHA1ClassSource/SHA1.h" // The CSHA1 class
int main(int argc, char *argv[])
{
int ch = 0;
// Print some information
printf("\r\n [ Test driver for the CSHA1 class ]\r\n\r\n");
while(ch != 3)
{
printf("\r\n 1) Hash a string\r\n");
printf(" 2) Hash a file\r\n");
printf(" 3) Exit\r\n");
printf("\r\n Enter [1], [2] or [3]: ");
// User's choice
fflush(stdin);
ch = getchar();
// Process user's choice
if(ch == '3') return(0);
else if(ch == '1') HashString();
else if(ch == '2') HashFile();
else { printf("\r\n Input error: Enter 1, 2 or 3 plus [Enter]!\r\n"); }
}
// Print information and exit
printf("\r\n Operation successfully completed.\r\n Press any key to exit.\r\n");
fflush(stdin);
getchar();
fflush(stdin);
return(0);
}
void HashString()
{
char szString[1024];
char szReport[1024];
CSHA1 sha1;
szString[0] = 0; szReport[0] = 0;
printf("\r\n Enter the string to hash:\r\n ");
fflush(stdin);
gets(szString);
sha1.Reset();
sha1.Update((UINT_8 *)szString, strlen(szString));
sha1.Final();
sha1.ReportHash(szReport, CSHA1::REPORT_HEX);
printf("\r\n String hashed to:\r\n ");
printf(szReport);
printf("\r\n");
}
void HashFile()
{
char szFilename[1024];
char szReport[1024];
bool bSuccess = false;
CSHA1 sha1;
szFilename[0] = 0; szReport[0] = 0;
printf("\r\n Filename: ");
fflush(stdin);
gets(szFilename);
sha1.Reset();
bSuccess = sha1.HashFile(szFilename);
sha1.Final();
sha1.ReportHash(szReport, CSHA1::REPORT_HEX);
if(bSuccess == true)
{
printf("\r\n File contents hashed to:\r\n ");
printf(szReport);
printf("\r\n");
}
else
printf("\r\n An error occured (does the file really exist?) !\r\n");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -