下面**利用tea演算法實現加密密碼檔案生成與解密,一共有五個檔案,分別是main.cpp, encode.h,encode.cpp,encodepwfile.h,encodepwfile.cpp。分別將下面的**拷貝到對應檔案中,然後到dev-c++建個工程,把檔案新增到工程中編譯即可。
//mail.cpp
#include
#include "encodepwfile.h"
#include "encode.h"
int main(int argc, char *argv)
else if (2 == argc)
else
system("pause");
return exit_success;}
//encode.h file
#ifndef __encode__h__
#define __encode__h__
//helper function
void printstr(char* s, int n);
//encode function
void decrypttea(unsigned long *firstchunk, unsigned long *secondchunk);
void encrypttea(unsigned long *firstchunk, unsigned long *secondchunk);
void decryptbuffer(char* buffer, int size);
void encryptbuffer(char* buffer, int size);
//testing function
void testencodetea();
void testencodebuf();
#endif
//encode.cpp file
#include
#include "encode.h"
//helper function
void printstr(char* s, int n)
printf("/n");
}//encode function
void decrypttea(unsigned long *firstchunk, unsigned long *secondchunk)
*firstchunk = y;
*secondchunk = z;
return;
} void encrypttea(unsigned long *firstchunk, unsigned long *secondchunk)
*firstchunk = y;
*secondchunk = z;
}void decryptbuffer(char* buffer, int size)
printf("after decryptbuffer/n");
printstr(buffer, size);
void encryptbuffer(char* buffer, int size)
printf("after encryptbuffer/n");
printstr(buffer, size);
}//testing function
void testencodetea()
void testencodebuf()
//encodepwfile.cpp file
#ifndef __encode_pw_file__h__
#define __encode_pw_file__h__
void outputpw(char* filename);
void writepwfile(char* filename, char* userid, char* password);
#endif
//encodepwfile.cpp file
#include
#include "encode.h"
#include "encodepwfile.h"
#define null_char '/0'
#define exit_error -1
#define datasize 32
//help function
void trimblanks(char *buffer)
return;
}void encryptuseridpassword(char *encrypteddata, int len, char *userid, char *password)
void decryptuseridpassword(char *encrypteddata, int len, char *userid, char *password)
memset(encrypteddata, null_char, buffersize);
fgets(encrypteddata, buffersize, f_ptr);
if (eof == fclose(f_ptr))
return;
}void outputpw(char* filename)
void writepwfile(char* filename, char* userid, char* password)
char encrypteddata[datasize];
encryptuseridpassword(encrypteddata, sizeof(encrypteddata), userid, password);
fwrite(encrypteddata, 1, sizeof(encrypteddata), f_ptr);
if (eof == fclose(f_ptr))
printf("write the userid:%s, password:%s to %s successfully!/n/n/n", userid, password, filename);
}
流密碼檔案加密
檔案加密不同於實時通訊加密在速度上要求不高,所以金鑰陣列可以做得更強大一些,這也就避免了什麼流密碼金鑰混亂程度不夠的偏見,要想資訊保安金鑰陣列要做到唯一性,獨一無二的金鑰陣列只能用一次,這樣就避免了已知明文攻擊的陰影。但是如果使用者使用了相同的密碼,如果生成金鑰的方法固定仍然可以形成相同的金鑰陣列,...
TDS協議 加密密碼演算法
看freetds的原始碼 unsigned char tds7 crypt pass const unsigned char clear pass,int len,unsigned char crypt pass 呼叫 tds7 crypt pass unsigned char unicode st...
利用佇列實現密碼加密解密
使用佇列基本操作解決密碼加密和解密問題。密碼加密原理描述如下 將明文 乙個字串 的每個字元按照字母表後移,每個字元的後移個數由秘鑰值列表確定,如果明文比金鑰值列表長,可以從頭再使用這個金鑰值列表。如明文 student,秘鑰 2345,則加密方法是 s 向後移動2位 變成u,t 向後移動3位 變成w...