BOOL Ckgb_arch_decompressDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. /*ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000);*/ /*CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } }*/ // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon //SetIcon(m_hIcon, TRUE); // Set small icon // TODO: Add extra initialization here lFiles.InsertColumn(0, loadString(IDS_FILE), LVCFMT_LEFT, 300); lFiles.InsertColumn(1, loadString(IDS_SIZE), LVCFMT_RIGHT, 100); char curDir[MAX_PATH]; GetCurrentDirectory(MAX_PATH, curDir); eDestination.SetWindowText(curDir); vector<string>files; vector<unsigned long>fsize; char arch[MAX_PATH]; HANDLE hProc = GetCurrentProcess(); HMODULE hMod; DWORD cbNeeded; EnumProcessModules(hProc, &hMod, sizeof(hMod), &cbNeeded); GetModuleFileNameEx(hProc, hMod, arch, MAX_PATH); //pierwszy modu³ jest aplikacj¹ //MessageBox(""); if(isSFXencrypted(arch)){ //wo³amy o has³o dlgPasswd dlgPass; if(dlgPass.DoModal() != IDOK){ theApp.ExitInstance(); return false; } strcpy(passwd, dlgPass._passwd); for(int i=strlen(passwd);i<32;i++) passwd[i] = '\0'; char arch2[MAX_PATH]; //strcpy(arch2, arch.c_str()); GetTempPath(MAX_PATH, arch2); GetLongPathName(arch2, arch2, sizeof(arch2)); strcat(arch2, "temp.kgb"); //arch2[strlen(arch2)-1] = 'b'; aes_ctx ctx[1]; ctx->n_rnd = 0; // ensure all flags are initially set to zero ctx->n_blk = 0; aes_dec_key((const unsigned char*)passwd, 32, ctx); /*CDialog dProgress; dProgress.Create(IDD_DECODING); dProgress.ShowWindow(SW_SHOW); dProgress.UpdateWindow();*/ FILE *fin = fopen(arch, "rb"); if(fin == 0) return false; fseek(fin, isSFXencrypted(arch), SEEK_SET); FILE *fout = fopen(arch2, "wb"); if(fout == 0) return false; decfile(fin, fout, ctx, arch, arch2); fclose(fin); fclose(fout); /*dProgress.ShowWindow(SW_HIDE); dProgress.~CDialog();*/ if(!checkArchiveFormat(arch2)){ _fcloseall(); DeleteFile(arch2); //eArchName.SetWindowText(""); MessageBox(loadString(IDS_WRONG_PASSWD), "KGB Archiver"); theApp.ExitInstance(); return false; } strcpy(arch, arch2); getFilesFromArchive(arch, files, fsize); }else{ getFilesFromArchive(arch, files, fsize); } strcpy(globalARCH, arch); //MessageBox(""); for(unsigned long i=0;i<files.size();i++){ char buffer[32]; /*if(filesizes[i] < 1024) sprintf(buffer, "%dB", filesizes[i]); else if(filesizes[i] < 1024*1024) sprintf(buffer, "%dKB", filesizes[i]/1024); else sprintf(buffer, "%dMB", filesizes[i]/1024/1024); */ sprintf(buffer, "%.1fKB", (double)fsize[i]/1024.0); lFiles.InsertItem(0, i, 0, 0, 0, 0, 0); lFiles.SetItemText(i, 0, files[i].c_str()); lFiles.SetItemText(i, 1, buffer); } //MessageBox(""); //delete curDir; /*char *cmd = theApp.m_lpCmdLine; char temp[MAX_PATH]; bool isArchName = true; /*sscanf(cmd, "-%c", &mode); switch(mode){ case 'c': cmd += 2; //przesówamy wskaŸnik* / for(unsigned long i=0;i<strlen(cmd);i++){ if(cmd[i] == '"'){ for(unsigned long j=0;i+j+1<strlen(cmd);j++){ if(cmd[i+j+1] != '"') temp[j] = cmd[i+j+1]; else if(cmd[i+j+1] == '"'){ temp[j] = 0; i += j+1; if(!isArchName) //lFiles.AddString(temp); eDestination.SetWindowText(temp); else{ eArchName.SetWindowText(temp); isArchName = false; } break; } } } }*/ //MessageBox(cmd); /*if(strlen(temp) == 0 || strlen(cmd) <= 2) return TRUE; vector<string> files; vector<unsigned long> filesizes; if(!getFilesFromArchive(temp, files, filesizes)){ MessageBox("Wybrany plik nie jest prawid³owym archiwum KGB!"); eArchName.SetWindowText(""); eDestination.SetWindowText(""); return TRUE; } //lFiles.DeleteAllItems(); for(unsigned long i=0;i<files.size();i++){ char buffer[32]; /*if(filesizes[i] < 1024) sprintf(buffer, "%dB", filesizes[i]); else if(filesizes[i] < 1024*1024) sprintf(buffer, "%dKB", filesizes[i]/1024); else sprintf(buffer, "%dMB", filesizes[i]/1024/1024); * / sprintf(buffer, "%.1fKB", (double)filesizes[i]/1024.0); lFiles.InsertItem(0, i, 0, 0, 0, 0, 0); lFiles.SetItemText(i, 0, files[i].c_str()); lFiles.SetItemText(i, 1, buffer); }*/ return TRUE; // return TRUE unless you set the focus to a control }
int main(int argc, char *argv[]) { FILE *fin = 0, *fout = 0; char *cp, ch, key[32]; int i=0, by=0, key_len=0, err = 0; aes ctx[1]; if(argc != 5 || (toupper(*argv[3]) != 'D' && toupper(*argv[3]) != 'E')) { printf("usage: rijndael in_filename out_filename [d/e] key_in_hex\n"); err = -1; goto exit; } cp = argv[4]; /* this is a pointer to the hexadecimal key digits */ i = 0; /* this is a count for the input digits processed */ while(i < 64 && *cp) /* the maximum key length is 32 bytes and */ { /* hence at most 64 hexadecimal digits */ ch = toupper(*cp++); /* process a hexadecimal digit */ if(ch >= '0' && ch <= '9') by = (by << 4) + ch - '0'; else if(ch >= 'A' && ch <= 'F') by = (by << 4) + ch - 'A' + 10; else /* error if not hexadecimal */ { printf("key must be in hexadecimal notation\n"); err = -2; goto exit; } /* store a key byte for each pair of hexadecimal digits */ if(i++ & 1) key[i / 2 - 1] = by & 0xff; } if(*cp) { printf("The key value is too long\n"); err = -3; goto exit; } else if(i < 32 || (i & 15)) { printf("The key length must be 32, 48 or 64 hexadecimal digits\n"); err = -4; goto exit; } key_len = i / 2; if(!(fin = fopen(argv[1], "rb"))) /* try to open the input file */ { printf("The input file: %s could not be opened\n", argv[1]); err = -5; goto exit; } if(!(fout = fopen(argv[2], "wb"))) /* try to open the output file */ { printf("The output file: %s could not be opened\n", argv[1]); err = -6; goto exit; } if(toupper(*argv[3]) == 'E') { /* encryption in Cipher Block Chaining mode */ set_key(key, key_len, enc, ctx); err = encfile(fin, fout, ctx, argv[1]); } else { /* decryption in Cipher Block Chaining mode */ set_key(key, key_len, dec, ctx); err = decfile(fin, fout, ctx, argv[1], argv[2]); } exit: if(fout) fclose(fout); if(fin) fclose(fin); return err; }
int main(int argc, char *argv[]) { FILE *fin = 0, *fout = 0; char *cp, ch, key[32]; int i, by = 0, key_len, err = 0; if(argc != 5 || toupper(*argv[3]) != 'D' && toupper(*argv[3]) != 'E') { printf("usage: aesxam in_filename out_filename [d/e] key_in_hex\n"); err = -1; goto exit; } gen_tabs(); // in case dynamic AES tables are being used cp = argv[4]; // this is a pointer to the hexadecimal key digits i = 0; // this is a count for the input digits processed while(i < 64 && *cp) // the maximum key length is 32 bytes and { // hence at most 64 hexadecimal digits ch = toupper(*cp++); // process a hexadecimal digit if(ch >= '0' && ch <= '9') by = (by << 4) + ch - '0'; else if(ch >= 'A' && ch <= 'F') by = (by << 4) + ch - 'A' + 10; else // error if not hexadecimal { printf("key must be in hexadecimal notation\n"); err = -2; goto exit; } // store a key byte for each pair of hexadecimal digits if(i++ & 1) key[i / 2 - 1] = by & 0xff; } if(*cp) { printf("The key value is too long\n"); err = -3; goto exit; } else if(i < 32 || (i & 15)) { printf("The key length must be 32, 48 or 64 hexadecimal digits\n"); err = -4; goto exit; } key_len = i / 2; if(!(fin = fopen(argv[1], "rb"))) // try to open the input file { printf("The input file: %s could not be opened\n", argv[1]); err = -5; goto exit; } if(!(fout = fopen(argv[2], "wb"))) // try to open the output file { printf("The output file: %s could not be opened\n", argv[2]); err = -6; goto exit; } if(toupper(*argv[3]) == 'E') // encryption in Cipher Block Chaining mode { aes_encrypt_ctx ctx[1]; aes_encrypt_key((unsigned char*)key, key_len, ctx); err = encfile(fin, fout, ctx, argv[1], argv[2]); } else // decryption in Cipher Block Chaining mode { aes_decrypt_ctx ctx[1]; aes_decrypt_key((unsigned char*)key, key_len, ctx); err = decfile(fin, fout, ctx, argv[1], argv[2]); } exit: if(err == READ_ERROR) printf("Error reading from input file: %s\n", argv[1]); if(err == WRITE_ERROR) printf("Error writing to output file: %s\n", argv[2]); if(fout) fclose(fout); if(fin) fclose(fin); return err; }
void compute_aes(){ //printf("Start Rijndael encryption/decryption\n\n",0,0,0,0); char *cp, ch; int i=0, by=0, key_len=0, err = 0, n; //repeatfactor = 4096 >> 9 for(n = 0; n < 4096 >> 9; n++) { aes ctx[1]; by=0; key_len=0; err = 0; cp = presetkey; /* this is a pointer to the hexadecimal key digits */ i = 0; /* this is a count for the input digits processed */ while(i < 64 && *cp) /* the maximum key length is 32 bytes and */ { /* hence at most 64 hexadecimal digits */ ch = *cp++; /* process a hexadecimal digit */ if(ch >= '0' && ch <= '9') by = (by << 4) + ch - '0'; else if(ch >= 'A' && ch <= 'F') by = (by << 4) + ch - 'A' + 10; else /* error if not hexadecimal */ { err = -2; goto exit; } /* store a key byte for each pair of hexadecimal digits */ if(i++ & 1) key[i / 2 - 1] = by & 0xff; } if(*cp) { err = -3; goto exit; } else if(i < 32 || (i & 15)) { err = -4; goto exit; } key_len = i / 2; // ENCRYPTION //printf("Set encryption key\n",0,0,0,0); set_key(key, key_len, enc, ctx); //printf("Key: %d\n\n",key,0,0,0); //printf("Start encryption\n\n",0,0,0,0); err = encfile(ctx, encoutbuf); // DECRYPTION //printf("Set decryption key\n",0,0,0,0); set_key(key, key_len, dec, ctx); //rintf("Key: %d\n\n",key,0,0,0); //printf("Start decryption\n",0,0,0,0); err = decfile(ctx, decoutbuf); } exit: i=0; }