1. c語言實現密碼加密
unsignedchar*encrypt(unsignedchar*psw,intenc){
intsum=0,i;
if(enc){
for(i=0;i<6;i++){
psw[i]-=15;
sum+=psw[i];
}
psw[6]=(unsignedchar)sum;
psw[7]=0;
}
else{
for(i=0;i<6;i++){
sum+=psw[i];
psw[i]+=15;
}
if((unsignedchar)sum!=psw[6]){
printf("Badpassword ");
psw[0]=0;
returnpsw;
}
else{
psw[6]=0;
}
}
for(i=0;i<3;i++){
unsignedchart=psw[i];
psw[i]=psw[5-i];
psw[5-i]=t;
}
returnpsw;
}
intmain()
{
unsignedcharpsw[128];
scanf("%s",psw);
printf("encodeto:%s ",encrypt(psw,1));
printf("decodeto:%s ",encrypt(psw,0));
return0;
}
2. 關於dat文件如何在c語言中進行簡單加密
讀取一個位元組,然後左移3位+110 輸出到另外的一個文件。思路是這樣。
一個位元組的話,完全不用考慮位過長問題。
讀取8位並 -『0』,使其變為整數,改10進制(此類代碼我空間中正好有,你可以參考),
然後:(n<<3)|110
在輸入到另外的一個文件中
如此循環。
3. 如何給c/c++源代碼加密
#include#include#includevoid findKey(char* key, char* mark){int len = strlen(key);int i = 0;int j = 0;memset(mark,0,26);for (i = 0; i 96){encrypt[i] = map[encrypt[i] - 97];}}outputFile = fopen("output.txt", "w+");fwrite(encrypt,nFileLen,1,outputFile);printf("加密的密文:%s\n", encrypt);fclose(outputFile);fclose(inputFile);free(encrypt);system("pause");return 0;}