Hello! help solve the problem with the functions. there are two functions, one for encryption, the other for decryption, both implemented in C. It is necessary to make them run in vs 2010 environment. when these functions work, they need to pass parameters through argc and argv. I need it so that I can enter what I need from the keyboard. for example: in order to encrypt / decrypt a file the following should be displayed: enter the name of the source file: d: \ rfc796.txt // enter the name and path to the file you want to encrypt / decrypt. I have already tried to do so in order to enter from the keyboard myself what I need, and not to ask the data in advance in St. Vs 2010, but nothing came of it. help them redo them so that when they run the program in vs 2010 in C ++, they worked. replaced the variables argc and argv with others added lines like:

printf(enter src file name: ) cin >> fname or gets_s(fname) 

but as a result, when you press the F5 button,

 Missing argument. для продолжения нажмите на любую клавишу или File read error. для продолжения нажмите на любую клавишу 

these functions normally work with argc and argv, if you run them through the console in OS Linex and makentosh, while in these systems you can implement a program in C, and in Windows in vs 2010 environment this is impossible because vs 2010 supports only vc ++, vc #, vbasic, vf # ================================ DECRYPT.C ========== =====================

 #include <stdio.h> #include "rijndael.h" #define KEYBITS 256 int main(int argc, char **argv) { unsigned long rk[RKLENGTH(KEYBITS)]; unsigned char key[KEYLENGTH(KEYBITS)]; int i; int nrounds; char *password; FILE *input; if (argc < 3) { fputs("Missing argument", stderr); return 1; } password = argv[1]; for (i = 0; i < sizeof(key); i++) key[i] = *password != 0 ? *password++ : 0; input = fopen(argv[2], "rb"); if (input == NULL) { fputs("File read error", stderr); return 1; } nrounds = rijndaelSetupDecrypt(rk, key, 256); while (1) { unsigned char plaintext[16]; unsigned char ciphertext[16]; int j; if (fread(ciphertext, sizeof(ciphertext), 1, input) != 1) break; rijndaelDecrypt(rk, nrounds, ciphertext, plaintext); fwrite(plaintext, sizeof(plaintext), 1, stdout); } fclose(input); } 

=============================== ENCRYPT.C ================ ===============

 #include <stdio.h> #include "rijndael.h" #define KEYBITS 256 int main(int argc, char **argv) { unsigned long rk[RKLENGTH(KEYBITS)]; unsigned char key[KEYLENGTH(KEYBITS)]; int i; int nrounds; char *password; FILE *output; if (argc < 3) { fputs("Missing argument\n", stderr); return 1; } password = argv[1]; for (i = 0; i < sizeof(key); i++) key[i] = *password != 0 ? *password++ : 0; output = fopen(argv[2], "wb"); if (output == NULL) { fputs("File write error", stderr); return 1; } nrounds = rijndaelSetupEncrypt(rk, key, 256); while (!feof(stdin)) { unsigned char plaintext[16]; unsigned char ciphertext[16]; int j; for (j = 0; j < sizeof(plaintext); j++) { int c = getchar(); if (c == EOF) break; plaintext[j] = c; } if (j == 0) break; for (; j < sizeof(plaintext); j++) plaintext[j] = ' '; rijndaelEncrypt(rk, nrounds, plaintext, ciphertext); if (fwrite(ciphertext, sizeof(ciphertext), 1, output) != 1) { fclose(output); fputs("File write error", stderr); return 1; } } fclose(output); } 
  • Code format. In the "issue edit" there is a button " {} ". Select the text fragment with the mouse code and press it. - avp

1 answer 1

Doing nonsense. Obviously, if the program is launched without command line arguments, the argc parameter has a different value. Those. The problem is here:

  if (argc < 3) { fputs("Missing argument", stderr); return 1; } 

I suggest rewriting this fragment and not making the exit from the program, but a request for the input of the file name. Those. you get something in the spirit of:

 char filename[255]; ... if (argc < 3) { fputs("Missing argument", stderr); printf("Please enter filename:\n"); fgets(filename); } // погнали дальше, теперь имя файла в переменной filename // чтобы не пришлось думать откуда его брать, скопируем его из argv // если действительно его задали через командную строку else { strcpy(filename, argv[2]); } ...