C++ How to put a line of a data file into an array for encryption? (AES) -
I have completed my AES encryption program at that point where I get the right answer at the command prompt with this code :
zero main () {int a; Unsigned four syfaris [16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4f, 0x3c}; Unsigned four plain text [16] = {0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34}; For (a = 0; a & lt; 16; a ++) {key [a] = cipher [a]; Input [A] = plain text [A]; } KeyExpansion (); Cipher (); Cout & lt; & Lt; Endl; Cout & lt; & Lt; "Encrypted Output Text:" & lt; & Lt; Endl; (A = 0; a & lt; 16; a ++) // Loop is used to print each letter of the output array for the coupon {printf ("% 02x", output [A]); // printf is used to print encrypted text in HexSideCal Print & lt; & Lt; Endl; }
However, I need to get data blocks for data from seeper and plain text instead of program. I have my data file Input.dat Looks like:
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3c
0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34
So I need to take this information from one file and Place it in these arrays:
Unsigned four syphilis [16]; Unsigned four plain text [16]; The program will then use this data normally to encrypt plain text and then create a new output file with an encrypted text in it (this is still concerned about this part No)
Here's my attempt:
zero main () {int a; Unsigned four syphilis [16]; Unsigned four plain text [16]; Ifstream inFile; Offream outfile; InFile.open ("Input.dat"); // opens the input file with the required information, which should be placed in the starting array for above (A = 0; a & lt; 16; a ++) {inFile & gt; & Gt; CipherKey [A]; In the // file, the first 16 unsigned character array is placed in CipherKey [16] // that is placed in CipherKey for 0x2B [0], 0xAE is placed in CipherKey [5] etc.} (a = 0; ; 16; a ++) {inFile & gt; & Gt; Plane [a]; The file has the last 16 unsigned character array in PlainText [16]} inFile.close (); ... // The remaining code should be The answer should be: 39 25 84 1d 02 DC 09 FB DC 11 85 97 1 9 32 A B 32 while I am getting: 60 A6 F1 D6 7A 14 32 1A 40 55 50 e8 0C FC 5F CC
I use this method for a small program to get yoga integer values in a file So this is designed to be seen to work with the AES program and it seems like it can do it.
Does it look like a raid from the right lines or impressions?
When someone uses the input stream to read char It is not read as an integer (hex or otherwise), but as a text character. As such, inFile & gt; & Gt; Cipherkey [A] , you will fill the code with CipherKey ascii the first 16 bytes of your file (OK, technically it will encode your input file and your c ++ compiler depends on) :. For example, if it starts with the first four letters of "0x2B", CipherKey 0x30 0x78 0x32 0x42 < / Div>
Comments
Post a Comment