Guest User

Untitled

a guest
Jan 7th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. void cipher(fstream& input, fstream& output, fstream& key) {
  2. char keyBuffer[9];
  3. char inputBuffer[2];
  4. uint16_t in;
  5. uint16_t out;
  6. uint32_t k;
  7. int fileLength = 0;
  8. stringstream stream;
  9. bitset<4> outputBitset;
  10.  
  11.  
  12. int i,j;
  13. bool a;
  14.  
  15. input.seekg(0);
  16. output.seekg(0);
  17.  
  18. fileLength = input.tellg();
  19.  
  20. input.clear();
  21. key.clear();
  22.  
  23. //Weź klucz
  24. key.get(keyBuffer, 9);
  25. stream << hex << keyBuffer;
  26. stream >> k;
  27. stream.clear();
  28. bitset<32> keyBitset(k);
  29. //CZYTAJ
  30.  
  31. for (i = 0; i < fileLength; i++) {
  32. input.get(inputBuffer,2);
  33. stream << hex << inputBuffer;
  34. stream >> in;
  35. stream.clear();
  36. bitset<4> inputBitset(in);
  37.  
  38. for(j = 0; j < 4;j++) {
  39. a = keyBitset[0] ^ keyBitset[3] ^ keyBitset[31];
  40. outputBitset[j] = inputBitset[j] ^ keyBitset[j];
  41. keyBitset <<= 1;
  42. keyBitset[0] = a;
  43. }
  44. stream << hex << outputBitset.to_ulong();
  45. stream >> out;
  46. stream.clear();
  47. //wypełnij zerami
  48. inputBitset.reset();
  49. outputBitset.reset();
  50. output << hex << out;
  51. cout << hex << out;
  52. }
  53. cout << endl;
  54. input.close();
  55. key.close();
  56. output.close();
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment