Posted By

adino on 06/02/11


Tagged

c job puzzler


Versions (?)

C puzzler for software developer role


 / Published in: C
 

  1. /** This program should be compiled using following command:
  2.  
  3.  $ cc -g -o test_hr_test test_hr_test.c
  4.  
  5.  Original developer Malvin left company to pursue his dream and went
  6.  to live with wild ligers. No-one ever heard any word about him since
  7.  he left. We've managed to recover source code from his source repo.,
  8.  but program seems to be broken. Strangely Malvin used iso-8859-1 as
  9.  his console encoding.
  10.  
  11.  Hints:
  12.  - program does not compile
  13.  - we were not able to recover whole function permutateBlockRev()
  14.  - program crashes on our X86 solaris 10 matchine (not on linux)
  15.  
  16.  Are you the one which can help us recover the password ?
  17.  Send it to: [email protected]
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. /** bit manipulation macros */
  24. #define CLRBIT( STR, IDX ) ( (STR)[(IDX)/8] &= ~(0x01 << (7 - ((IDX)%8))) )
  25. #define SETBIT( STR, IDX ) ( (STR)[(IDX)/8] |= (0x01 << (7 - ((IDX)%8))) )
  26. #define GETBIT( STR, IDX ) (( ((STR)[(IDX)/8]) >> (7 - ((IDX)%8)) ) & 0x01)
  27.  
  28. /** permutation works on unsigned char blocks of size 8 */
  29. #define BLOCK_SIZE 8
  30. typedef unsigned char[BLOCK_SIZE] block;
  31.  
  32. /** Function does reverse permutation to DES initial block permutation as described at
  33.  http://en.wikipedia.org/wiki/DES_supplementary_material
  34.  @param b - block which will be permutated in-place
  35.  @note indexes start from 0 contrary to wikipedia initialization vector - C like index
  36.  */
  37. void permutateBlockRev(block b)
  38. {
  39. int i;
  40. static const int initialPermuteMap[64] =
  41. {
  42. 57, 49, 41, 33, 25, 17, 9, 1,
  43. 59, 51, 43, 35, 27, 19, 11, 3,
  44. 61, 53, 45, 37, 29, 21, 13, 5,
  45. 63, 55, 47, 39, 31, 23, 15, 7,
  46. 56, 48, 40, 32, 24, 16, 8, 0,
  47. 58, 50, 42, 34, 26, 18, 10, 2,
  48. 60, 52, 44, 36, 28, 20, 12, 4,
  49. 62, 54, 46, 38, 30, 22, 14, 6
  50. };
  51.  
  52. /* There are few lines of code missing */
  53. }
  54.  
  55. int main (void)
  56. {
  57. unsigned char str[BLOCK_SIZE + 1] = "DummyStr";
  58. block permutated = { 0x7a, 0xd2, 0x21, 0x3c, 0x05, 0x85, 0x8d, 0x71 };
  59.  
  60. permutateBlockRev(permutated);
  61. strcpy(str, permutated);
  62. printf("Password is: %s\n", str);
  63. }

Report this snippet  

You need to login to post a comment.