fork download
  1. #include <stdio.h>
  2. typedef unsigned char byte;
  3.  
  4. void printBytes(byte *state, int len)
  5. {
  6. int i;
  7. for (i = 0; i < len; i++)
  8. {
  9. printf("%02X ", state[i]);
  10. }
  11.  
  12. printf("\n");
  13. }
  14.  
  15. // Re-invent the byte using arbitrary length array (i.e. BigNumber)
  16. // to increment 16-byte nonce
  17. void incByte(byte *state, int i)
  18. {
  19. // 0000 -> 0001
  20. if (state[i] < 0xff)
  21. {
  22. state[i]++;
  23. return;
  24. }
  25.  
  26. // 0001 -> 0010
  27. state[i] = 0x00;
  28. i--;
  29. incByte(state, i);
  30. }
  31.  
  32.  
  33.  
  34. void testInc()
  35. {
  36. byte state[] = { 0x00, 0xff, 0xff, 0xee };
  37.  
  38. int i;
  39. for (i = 1; i <= 100; i++)
  40. {
  41. incByte(state, sizeof(state) - 1);
  42. printBytes(state, sizeof(state));
  43. }
  44. }
  45.  
  46. int main(void) {
  47. testInc();
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
00 FF FF EF 
00 FF FF F0 
00 FF FF F1 
00 FF FF F2 
00 FF FF F3 
00 FF FF F4 
00 FF FF F5 
00 FF FF F6 
00 FF FF F7 
00 FF FF F8 
00 FF FF F9 
00 FF FF FA 
00 FF FF FB 
00 FF FF FC 
00 FF FF FD 
00 FF FF FE 
00 FF FF FF 
01 00 00 00 
01 00 00 01 
01 00 00 02 
01 00 00 03 
01 00 00 04 
01 00 00 05 
01 00 00 06 
01 00 00 07 
01 00 00 08 
01 00 00 09 
01 00 00 0A 
01 00 00 0B 
01 00 00 0C 
01 00 00 0D 
01 00 00 0E 
01 00 00 0F 
01 00 00 10 
01 00 00 11 
01 00 00 12 
01 00 00 13 
01 00 00 14 
01 00 00 15 
01 00 00 16 
01 00 00 17 
01 00 00 18 
01 00 00 19 
01 00 00 1A 
01 00 00 1B 
01 00 00 1C 
01 00 00 1D 
01 00 00 1E 
01 00 00 1F 
01 00 00 20 
01 00 00 21 
01 00 00 22 
01 00 00 23 
01 00 00 24 
01 00 00 25 
01 00 00 26 
01 00 00 27 
01 00 00 28 
01 00 00 29 
01 00 00 2A 
01 00 00 2B 
01 00 00 2C 
01 00 00 2D 
01 00 00 2E 
01 00 00 2F 
01 00 00 30 
01 00 00 31 
01 00 00 32 
01 00 00 33 
01 00 00 34 
01 00 00 35 
01 00 00 36 
01 00 00 37 
01 00 00 38 
01 00 00 39 
01 00 00 3A 
01 00 00 3B 
01 00 00 3C 
01 00 00 3D 
01 00 00 3E 
01 00 00 3F 
01 00 00 40 
01 00 00 41 
01 00 00 42 
01 00 00 43 
01 00 00 44 
01 00 00 45 
01 00 00 46 
01 00 00 47 
01 00 00 48 
01 00 00 49 
01 00 00 4A 
01 00 00 4B 
01 00 00 4C 
01 00 00 4D 
01 00 00 4E 
01 00 00 4F 
01 00 00 50 
01 00 00 51 
01 00 00 52