//-------------------------------------------------------------------------------- bool WriteFile(CFile& fOut, CFile& fOutBkup) { bool bRv = true; // pre-flight checks if(g_pP3Serial[0] == 0) { printf("Pentium III serial number must be specified\n"); bRv = false; } if(g_pP3SerialBkup[0] == 0) printf("WARNING - Backup Server Pentium III serial not specified\n"); if(g_pDongle[0] == 0) { printf("Dongle serial number must be specified\n"); bRv = false; } if(g_pEmail[0] == 0) { printf("Email information must be specified (ip.ip.ip.ip, from test, to address)\n"); bRv = false; } // this is a run once loop - i do this so that i dont need a goto while(bRv) { BYTE temp[32767]; BYTE temp2[32767]; int nIndex; // write the signature memcpy(temp, "MARKCAREMEDICAL", 16); nIndex = 16; // write the file version DWORD nVersion = 2; memcpy(&temp[nIndex], &nVersion, sizeof(nVersion)); nIndex += sizeof(nVersion); // save the index so we can insert the backup serial number later int nSerialIndex = nIndex; // write the p3 serial number memcpy(&temp[nIndex], g_pP3Serial, sizeof(g_pP3Serial)); nIndex += sizeof(g_pP3Serial); // write the dongle serial number memcpy(&temp[nIndex], g_pDongle, sizeof(g_pDongle)); nIndex += sizeof(g_pDongle); // write the expiration date memcpy(&temp[nIndex], &g_nExpires, sizeof(time_t)); nIndex += sizeof(time_t); // get and write the length of the email address DWORD nLen = strlen(g_pEmail); if(nLen >= 64) { printf("error nLen >= 64\n"); bRv = false; break; } memcpy(&temp[nIndex], &nLen, sizeof(nLen)); nIndex += sizeof(nLen); // write the email info memcpy(&temp[nIndex], g_pEmail, nLen); nIndex += nLen; // we'll need to set true in the backup file // and false in the other file so save the location for later int nBkupIndex = nIndex; // write 1 or 0 for backup nIndex += 1; // write the max backup runtime even if IsBackup is false memcpy(&temp[nIndex], &g_nMaxBackupRunTime, sizeof(g_nMaxBackupRunTime)); nIndex += sizeof(g_nMaxBackupRunTime); // get and write the length of the monitor user name nLen = strlen(g_pMonitorUser); if(nLen >= 64) { printf("error nLen >= 64\n"); bRv = false; break; } memcpy(&temp[nIndex], &nLen, sizeof(nLen)); nIndex += sizeof(nLen); // write the monitor user name memcpy(&temp[nIndex], g_pMonitorUser, nLen); nIndex += nLen; // get and write the length of the monitor password nLen = strlen(g_pMonitorPwd); if(nLen >= 64) { printf("error nLen >= 64\n"); bRv = false; break; } memcpy(&temp[nIndex], &nLen, sizeof(nLen)); nIndex += sizeof(nLen); // write the monitor password memcpy(&temp[nIndex], g_pMonitorPwd, nLen); nIndex += nLen; // write the "extra" data - this version doesnt include any // but future versions may write some additional data nLen = 0; memcpy(&temp[nIndex], &nLen, sizeof(nLen)); nIndex += sizeof(nLen); for(int i = 0; i < g_nNextToken; i++) { if(g_pTokens[i]->m_nMax == 0) { g_pTokens[i]->m_nMax = g_pTokens[i]->m_nCount < 100 ? g_pTokens[i]->m_nCount + 5 : g_pTokens[i]->m_nCount + 20; printf("WARNING - max not specified for '%s', defaulting to %ld\n", g_pTokens[i]->m_token.m_pName, g_pTokens[i]->m_nMax); } else if(g_pTokens[i]->m_nCount > g_pTokens[i]->m_nMax) { printf("count must be <= max\n"); bRv = false; break; } // write the token id memcpy(&temp[nIndex], &g_pTokens[i]->m_token.m_nId, sizeof(g_pTokens[i]->m_token.m_nId)); nIndex += sizeof(g_pTokens[i]->m_token.m_nId); // write the length of the name int nLen = strlen(g_pTokens[i]->m_token.m_pName); if(nLen >= 64) { printf("error nLen >= 64\n"); bRv = false; goto exit; } memcpy(&temp[nIndex], &nLen, sizeof(nLen)); nIndex += sizeof(nLen); // if there's a name, write it if(nLen > 0) memcpy(&temp[nIndex], g_pTokens[i]->m_token.m_pName, nLen); nIndex += nLen; // serialize the token into a string char tempToken[1024]; nLen = g_pTokens[i]->m_token.Encode(tempToken); // write the length of the token memcpy(&temp[nIndex], &nLen, sizeof(nLen)); nIndex += sizeof(nLen); // write the token memcpy(&temp[nIndex], tempToken, nLen); nIndex += nLen; #ifndef _DEBUG const int nSize1 = sizeof(char*); const int nSize2 = sizeof(DWORD); #if nSize1 != nSize2 #error pointers assumed to be the same size as DWORDs #endif #endif // write the available count memcpy(&temp[nIndex], &(DWORD) g_pTokens[i]->m_nCount, sizeof(g_pTokens[i]->m_nCount)); nIndex += sizeof(g_pTokens[i]->m_nCount); // write the max count memcpy(&temp[nIndex], &(DWORD) g_pTokens[i]->m_nMax, sizeof(g_pTokens[i]->m_nMax)); nIndex += sizeof(g_pTokens[i]->m_nMax); // write the parent id memcpy(&temp[nIndex], &(DWORD) g_pTokens[i]->m_nParent, sizeof(g_pTokens[i]->m_nParent)); nIndex += sizeof(g_pTokens[i]->m_nParent); } memcpy(temp2, temp, sizeof(temp)); // set the IsBackup bool for each file temp[nBkupIndex] = 0; temp2[nBkupIndex] = 1; // write the p3 serial number memcpy(&temp2[nSerialIndex], g_pP3SerialBkup, sizeof(g_pP3SerialBkup)); // encrypt the whole deal (nIndex == total size) CMCEncrypt encrypt(temp, nIndex + 1); // write it to the file fOut.Write(encrypt.GetData(), encrypt.GetLength()); // now for the backup file CMCEncrypt encrypt2(temp2, nIndex + 1); // write it to the file fOutBkup.Write(encrypt2.GetData(), encrypt2.GetLength()); break; } exit:; for(int i = 0; i < g_nNextToken; i++) delete g_pTokens[i]; g_nNextToken = 0; return bRv; }
int main() { printf("Welcome to protectit!\n"); printf("Please enter filename(FILENAME.txt)\n"); char* filename = GetString(); printf("Please enter output file name\n"); char* output = GetString(); printf("Would you like to use numbers or strings to encrypt?\n"); char* type = GetString(); char* numbers = "numbers"; char* strings = "strings"; if(strcmp(type, numbers) == 0) { printf("Please enter the Encryption/Decryption Key(A Number)\n"); int key = GetInt(); printf("Please input 1 for Encryption or 2 for Decryption\n"); int mode = GetInt(); //Check for Mode if(mode == 1) { //Start Encryption printf("Encrypting.......\n"); encrypt2(key, filename, output); printf("Done encrypting, Please check outfile.txt :)\n"); } else if(mode == 2) { //Start Decryption printf("Decrypting.......\n"); decrypt2(key, filename, output); printf("Done decrypting, Please check outfile.txt :)\n"); } else { //Yell at user printf("Sorry input must either be 1 or 2"); } } else if(strcmp(type, strings) == 0) { printf("Please enter the Encryption/Decryption Key(A Letter or a Word)\n"); char* key = GetString(); int klen = strlen(key); //Key length variable for(int i = 0; i < klen; i++) { if(isalpha(key[i])) tolower(key[i]); } printf("Please input 1 for Encryption or 2 for Decryption\n"); int mode = GetInt(); //Check for Mode if(mode == 1) { //Start Encryption printf("Encrypting.......\n"); encrypt(key, filename, output); printf("Done encrypting, Please check outfile.txt :)\n"); } else if(mode == 2) { //Start Decryption printf("Decrypting.......\n"); decrypt(key, filename, output); printf("Done decrypting, Please check outfile.txt :)\n"); } else { //Yell at user printf("Sorry input must either be 1 or 2"); } } else { //User didn't input (Numbers or Strings) printf("Error you should specify either numbers or strings\n"); return 1; } }
void encrypt_string2user(unsigned char *source, unsigned char *dest) { encrypt2(source, dest, cbc_user); }
int save_map(char *filename) { long bytesize; FILE *f; char nerr=1;char *pr; int i,j; TSTR_LIST names=NULL; void *temp; char enpass[58]; f=fopen(filename,"wb"); if (f==NULL) return -1; for (i=1;i<maplen;i++) for (j=0;j<4;j++) { TSTENA *w; w=&mapa.sidedef[i][j]; if (w->flags & 0x40000) if ((minfo[i].x+minfo[i].y+j)& 1) w->prim+=(w->prim_anim & 0xf)+1; } bytesize=sizeof(mglob); encrypt2(password,mglob.mappassw,sizeof(mglob.mappassw)); if (nerr) nerr&=(bytesize==save_section(f,&mglob,A_MAPGLOB,bytesize)); bytesize=maplen*sizeof(TSTENA)*4; if (nerr) nerr&=(bytesize==save_section(f,&mapa.sidedef,A_SIDEMAP,bytesize)); bytesize=maplen*sizeof(TSECTOR); if (nerr) nerr&=(bytesize==save_section(f,&mapa.sectordef,A_SECTMAP,bytesize)); if (password[0]) Shift_map_sectors_up(); bytesize=maplen*sizeof(TMAP_EDIT_INFO); if (nerr) nerr&=(bytesize==save_section(f,&minfo,A_MAPINFO,bytesize)); if (password[0]) Shift_map_sectors_down(); pr=pripona(filename,SCR); for (i=1;i<8;i++) { switch (i) { case 1: case 2: case 3:read_side_script_one(pr,NSID,&names,i,4);break; case 4:read_side_script_one(pr,NCEI,&names,1,2);break; case 5:read_side_script_one(pr,NFLR,&names,1,2);break; case 6:read_side_script_one(pr,NOBL,&names,1,3);break; case 7:read_side_script_one(pr,NOBL,&names,2,3);break; } if (nerr) nerr&=save_scr_list(f,names,i==7?A_STRTAB7:A_STRTAB1+i-1); } strcpy(enpass,"Heslo \x8 je heslo"); bytesize=strlen(enpass)+1; if (nerr && bytesize>1) { encrypt(enpass); memcpy(enpass+bytesize,"<BLOCK>\0\x13\x80",12);bytesize+=24; nerr&=(bytesize==save_section(f,enpass,A_PASSW,bytesize)); } temp=save_macros(&bytesize); if (temp!=NULL) { if (nerr) nerr&=(bytesize==save_section(f,temp,A_MAPMACR,bytesize)); free(temp); } if (nerr) nerr&=save_item_map(f,A_MAPITEM); if (mglob.local_monsters) { temp=save_mobs_to_map(&bytesize); if (nerr && temp!=NULL) nerr&=(bytesize==save_section(f,temp,A_MOBS,bytesize)); free(temp); nerr&=save_sound_dat(f,A_MOBSND); } temp=save_mob_map(&bytesize); if (temp!=NULL) { if (nerr) nerr&=(bytesize==save_section(f,temp,A_MAPMOBS,bytesize)); free(temp); } for(i=255;i>1;i--) if (vyklenky[i].sector!=0) break; bytesize=sizeof(TVYKLENEK)*(i+1); if (nerr) nerr&=(bytesize==save_section(f,vyklenky,A_MAPVYK,bytesize)); strcpy(enpass,"To bys \x8 chtel vedet co? \x8 "); bytesize=strlen(enpass)+1; if (nerr && bytesize>1) { encrypt(enpass); memcpy(enpass+bytesize,"<BLOCK>\0\x13\x80",12);bytesize+=12; nerr&=(bytesize==save_section(f,enpass,A_PASSW,bytesize)); } bytesize=sizeof(bytesize); if (nerr) nerr&=(bytesize==save_section(f,&bytesize,A_MAPEND,bytesize)); strcpy(enpass,"Ty si \x8 ale nedas pokoj! \x8"); bytesize=strlen(enpass)+1; if (nerr && bytesize>1) { encrypt(enpass); memcpy(enpass+bytesize,"<BLOCK>\0\x13\x80",12);bytesize+=12; nerr&=(bytesize==save_section(f,enpass,A_PASSW,bytesize)); } bytesize=sizeof(bytesize); if (nerr) nerr&=(bytesize==save_section(f,&bytesize,A_MAPEND,bytesize)); fclose(f); if (names!=NULL) release_list(names); { int x,y; for(x=1;x<maplen;x++) for(y=0;y<4;y++) if (mapa.sidedef[x][y].flags & 0x40000) if ((minfo[x].x+minfo[x].y+y)& 1) mapa.sidedef[x][y].prim-=(mapa.sidedef[x][y].prim_anim & 0xf)+1; } return (int)nerr-1; }
void encrypt_string2(unsigned char *source, unsigned char *dest) { encrypt2(source, dest, cbc_key3); }