larsupilami73

dfp

Dec 12th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.81 KB | None | 0 0
  1. #!/usr/bin/python3
  2. #delay-filter-permute hashing
  3. #larsupilami73
  4.  
  5. import numpy as np
  6.  
  7. #the secret...good luck!
  8. #the_secret = b'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  9.  
  10.  
  11. #hints
  12. print(len(the_secret)) #returns 40
  13. print(the_secret.isascii()) # returns True
  14.  
  15.  
  16. #a 256-entry permutation table
  17. permlookuptable = np.array([228,   6,  79, 206, 117, 185, 242, 167,   9,  30, 180, 222, 230,
  18.        217, 136,  68, 199,  15,  96,  24, 235,  19, 120, 152,  33, 124,
  19.        253, 208,  10, 164, 184,  97, 148, 190, 223,  25,  86,  18,  75,
  20.        137, 196, 176, 239, 181,  45,  66,  16,  67, 215, 201, 177,  38,
  21.        143,  84,  55, 220, 104, 139, 127,  60, 101, 172, 245, 126, 225,
  22.        144, 108, 178,  73, 114, 158,  69, 141, 109, 115, 246, 113, 243,
  23.         90,  29, 170,  82, 111,   5,  56, 132, 154, 162,  65, 186,  85,
  24.        219, 237,  31,  12,  35,  28,  42, 112,  22, 125,  93, 173, 251,
  25.         51, 240,  95, 146, 204,  76,  41, 119, 155,  78, 150,  26, 247,
  26.        168, 118, 193, 140,   0,   2,  77,  46, 100, 205, 159, 183, 254,
  27.         98,  36,  61, 200, 142,  11, 250, 224,  27, 231,   4, 122,  32,
  28.        147, 182, 138,  62, 135, 128, 232, 194,  70, 197,  64,  44, 165,
  29.        156,  40, 123, 153,  23, 192, 249,  81,  39, 244,  47,  94, 195,
  30.        161,  43, 145, 175,   3, 105,  53, 133, 233, 198, 238,  49, 163,
  31.         80,  34, 211,   7, 171, 216, 110,  91,  83, 229, 234,  89,   8,
  32.         13,  59, 221, 131,  17, 166,  72, 226, 134, 209, 236,  63,  54,
  33.        107,  50, 212, 174, 213, 189, 252, 207, 227, 169,  58, 218,  48,
  34.         88,  21,  57, 203, 160, 248, 187, 191, 129,  37, 157, 241,   1,
  35.         52, 149, 130, 151, 103,  99, 116,  87, 202,  74, 214, 210, 121,
  36.        255,  20, 188,  71, 106,  14,  92, 179, 102])
  37.  
  38.  
  39. #a simple delay line class
  40. class Delay:
  41.     def __init__(self, n=512, dtype='uint16'):
  42.         self.d = np.zeros(n, dtype=dtype)
  43.         self.index = 0
  44.         self.n = n
  45.        
  46.     def advance(self, x):
  47.         self.d[self.index] = x
  48.         self.index += 1
  49.         if self.index >= self.n:
  50.             self.index = 0
  51.         return self.d[self.index]
  52.        
  53.     def clear(self):
  54.         self.d = self.d * 0
  55.         self.index = 0
  56.    
  57.     def get(self):
  58.         return self.d[self.index]
  59.  
  60.  
  61. #make a delay line
  62. N = 512
  63. delay = Delay(N)   
  64.  
  65. #shift the ascii values of the secret in the delay line
  66. for c in the_secret:
  67.     delay.advance(c)
  68.  
  69. #delay-filter-permute
  70. state, perm = 0,0
  71. for k in range(N*20):  
  72.     state = state - (state>>4) + (perm<<4)
  73.     perm = permlookuptable[delay.advance((state>>3)  & 0x00FF)]
  74.    
  75. #the output
  76. print('State: {}'.format(state))
  77. print()
  78. print('Delay line:\n', delay.d)
  79.  
  80. """
  81. The challenge: the short Python code found here produces this as output:
  82.  
  83. State: 27466
  84.  
  85. Delay line:
  86. [ 94 204 211 244 109 120 235  34 176  65 155 165 247 210 177 232  35  15
  87.  44  43 253 117  34 106 251 145 188 165  30 112  81 208  43  11  60 228
  88. 252 138 176 105 244  45 244 159 253  92  64 126 142 191  49 168  64  22
  89. 166 234 113 164 248 131 142  82 106   2  46  21 104 139 124 135 152 133
  90. 223 195  11 144  73  36 186 205  26 230 174  87 212 104 252 184  55 221
  91. 237  45 234  63  53   2 190 254   2  32 154 217 109 204  38  15 232 116
  92. 169  58 122 159 115 132   8 147  94  50   9  80 191  46  69 118 217  56
  93. 250 114 241 212 209  86 227 177 106  23  26 218 230 252 252 174 214  36
  94.  20 173  10   5  13 170 190  28 130 110 185   0 204 153 223  47  81 106
  95. 223 137 225  47 152 132 222  64 118  21 165  61 189 192   6 239  30 115
  96.  77  51  26 204  87  14 155  33  41  13  36 210  65 231   6  24  26 171
  97. 238  65 219 220  10  91 226  58  46  23  40 235  73  88 127 141   6 158
  98. 196 127 118  12 189 214 158  26 221  19 174 219 239 101 148  99 187  87
  99.   2  50   1 221 181  76  33  89 221 218 156 148 157 241 172  34  85 130
  100. 174 247 198 215 188  16 253  82  96   0  80  13 205 186  58 195  53  29
  101. 226 139 103 242 155 212  50  87 144 149  34  78  35 211  87 174 223  49
  102. 240 175  28 173  64 252 146   9  11 176 157  89   0 100 167 159  63  65
  103. 101 111 224  86  51  22 142  81 124  51 204 145 102 255  38  79   6  76
  104. 239  68 228  40 125  60 106 169 165 202 126 136 159  96 174 103 214 189
  105. 189 121 140 159 231 149 148  90 173  28  18 239  20 157   9  63  47 126
  106. 196  28 128  28 214 117   8 171  31 151 245  62 118  23 196 177 152   7
  107. 188 239 204  63 227 205 152  85 132 169  85  58  12  59  88 134 158 236
  108.  69 155 183 172  57  60 118  56 131 185  81 248   7 234 178 165 120   9
  109. 110   8 137 177 100 195  85 142  93 231  19 198  15  71 254 244  89   6
  110.  39 147 116 234 232 247  24 146 151 206 245 146 113  66 136 157 139 133
  111.  94 147 103 199 249 237 254 201 194 142 223 179  76 179 186 121   5 195
  112. 155 141 216 201  88 199 234  48  63 133  93 247 236 151 209 206 230 191
  113. 167  39 235  92 154 163 196  26  25  13 168  54  22 251  73 117 150 220
  114. 243 229   5 221  61  95 154  32]
  115.  
  116. ...given the correct (hint) 40-byte ascii secret sentence. Can you find what it is?
  117.  
  118. """
Advertisement
Add Comment
Please, Sign In to add comment