fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. typedef unsigned char byte;
  5.  
  6. byte calc_iv(std::vector<byte> buffer)
  7. {
  8. int iv = 0;
  9. for(int i = 0; i < buffer.size(); i++) {
  10. byte I = buffer[i];
  11. iv += I;
  12. iv *= I + 1;
  13. }
  14. return iv / buffer.size();
  15. }
  16.  
  17.  
  18. int main(){
  19. std::vector<byte> buf = {41, 32, 16};
  20. byte iv = calc_iv(buf);
  21. std::cout<<(int)iv<<std::endl;
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
152