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