Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void cipher(fstream& input, fstream& output, fstream& key) {
- char keyBuffer[9];
- char inputBuffer[2];
- uint16_t in;
- uint16_t out;
- uint32_t k;
- int fileLength = 0;
- stringstream stream;
- bitset<4> outputBitset;
- int i,j;
- bool a;
- input.seekg(0);
- output.seekg(0);
- fileLength = input.tellg();
- input.clear();
- key.clear();
- //Weź klucz
- key.get(keyBuffer, 9);
- stream << hex << keyBuffer;
- stream >> k;
- stream.clear();
- bitset<32> keyBitset(k);
- //CZYTAJ
- for (i = 0; i < fileLength; i++) {
- input.get(inputBuffer,2);
- stream << hex << inputBuffer;
- stream >> in;
- stream.clear();
- bitset<4> inputBitset(in);
- for(j = 0; j < 4;j++) {
- a = keyBitset[0] ^ keyBitset[3] ^ keyBitset[31];
- outputBitset[j] = inputBitset[j] ^ keyBitset[j];
- keyBitset <<= 1;
- keyBitset[0] = a;
- }
- stream << hex << outputBitset.to_ulong();
- stream >> out;
- stream.clear();
- //wypełnij zerami
- inputBitset.reset();
- outputBitset.reset();
- output << hex << out;
- cout << hex << out;
- }
- cout << endl;
- input.close();
- key.close();
- output.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment