Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<sstream>
- #include<string>
- #include<cstring>
- using namespace std;
- #include"cryptopp/cryptlib.h"
- #include"cryptopp/hex.h"
- #include"cryptopp/filters.h"
- #include"cryptopp/des.h"
- #include"cryptopp/modes.h"
- using namespace CryptoPP;
- void des_encryption_8(unsigned char *input, unsigned char *key, unsigned char *output)
- {
- DESEncryption desEncryptor;
- unsigned char xorBlock[8];
- memset(xorBlock,0,8);
- desEncryptor.SetKey(key,8);
- desEncryptor.ProcessAndXorBlock(input,xorBlock,output);
- }
- int main(int argc, char * argv[])
- {
- //Files
- fstream pFile; //Input plaintext file
- fstream cFile; //Output ciphertext file
- fstream kFile; //Input key file
- //Incorrect commandline usage
- if(argc!=4)
- {
- cout<<"usage:cbc_des_encode infile outfile keyfile"<<endl;
- }
- //Open files
- pFile.open(argv[1],ios::in);
- cFile.open(argv[2],ios::out);
- kFile.open(argv[3],ios::in);
- //Read plaintext
- stringstream buffer;
- buffer << pFile.rdbuf();
- string pString(buffer.str());
- cout<< "Plaintext: " << pString << endl;
- //unsigned char *plain[pString.size + 1];
- //strcpy((char*)plain, pString.c_str()); //Convert to unsigned char
- //Read Key
- stringstream buffer2;
- buffer2 << kFile.rdbuf();
- string kString(buffer2.str());
- cout << "Key: " << kString << endl;
- unsigned char *key[DES::DEFAULT_KEYLENGTH];
- strcpy((char*)key, kString.c_str()); //Convert to unsigned char
- //Assign init vector
- unsigned char iv[DES::BLOCKSIZE] = {0x4c, 0xa0, 0x0f, 0xd6, 0xdb, 0xf1, 0xfb, 0x28}; //Test case 1
- //{0x0f, 0xf4, 0xc8, 0xd6, 0x1e, 0x80, 0x06, 0x18}; //Test case 2
- //Encrypt
- int numblocks = (pString.size() / DES::BLOCKSIZE);
- //Pad
- if (pString.size() % DES::BLOCKSIZE != 0) {
- numblocks++; //Add an extra block of the message is not a multiple of 8 byts
- int difference = (numblocks * DES::BLOCKSIZE) - pString.size();
- for (int i = 0; i < difference; i++) {
- pString += difference;
- cout << difference << endl;
- }
- }
- cout << "number of block: " << numblocks << endl;
- cout << "padded plaintext: " << pString << endl;
- unsigned char *plainblock[DES::BLOCKSIZE];
- for (int block = 0; block < numblocks; block++) {
- for (int i = block * 8; i < block * 8; i++) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement