adapap

Bit by Bit Tool Kit

Dec 26th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. Tib's original code came from a radio transmission which he received in base 64 format. In order to learn how to find the value that Tib needs for his bit kit, we will parse the base 64 input and follow a series of steps involving ascii values and bitwise manipulation. Let's walk through an example together:
  2.  
  3. Suppose you are given the input b64 string: 'Y3Rmfnw='
  4.  
  5. The decoded version of this string is: 'ctf~|'
  6. You may notice that the first part of the string begins with lowercase letters and has a series of bitwise operations (1 less than the amount of letters). This holds true for any transmission.
  7.  
  8. First, we need to take the ascii values of each letter and cube it. This gives us our number sequence which will be used later. In our example (^ means exponent, not XOR): c = 99^3 = 970299, t = 116^3 = 1560896, and f = 102^3 = 1061208.
  9.  
  10. Next, we set our starting value to the first number in the sequence (970299 in this case). Using that value as the first operand, we will each bitwise operation on subsequent numbers in our number set. If the bitwise operation is unary (~), it is applied to the current value, and the next number is skipped. Once we go through all of the bitwise operations, we use the result as the next starting value, and the starting position for both the numbers and bitwise operations increases by 1. This is how the tool kit is used in our example:
  11. (v: the value as a result of the operation)
  12. initial v = 970299
  13. v = ~970299 = -970300 (skip t because ~ is unary)
  14. v = -970300 | 1061208 = -970276
  15. (starting position increases, keep resulting value)
  16. v = -970276 | 1061208 = -970276
  17. (all operations complete in sequence)
  18. Result: -970276
  19.  
  20. Here is another example using a longer input. The variables have a number appended to them which represents the corresponding number, operation, or value.
  21. Input: 'bGVtb24mJn4+Pg==' --> 'lemon>>^|&'
  22. Letter values: l = 1259712, e = 1030301, m = 1295029, o = 1367631, n = 1331000
  23. Operations: >>, ^, |, &
  24.  
  25. V0 = l
  26. V1 = V0 >> e
  27. V2 = V1 ^ m
  28. V3 = V2 | o
  29. V4 = V3 & n
  30. New starting value: V0 = V4 (1330744)
  31. V1 = V0 ^ m
  32. V2 = V1 | o
  33. V3 = V2 & n
  34. New starting value: V0 = V3 (1330696)
  35. V1 = V0 | o
  36. V2 = V1 & n
  37. New starting value: V0 = V2 (1330696)
  38. V1 = V0 & n (final operation)
  39. Result: 1330696
  40.  
  41. Now go and help Tib, he's about to lose it!
  42.  
  43. [Additional Test Cases]
  44. Base64 --> Value
  45. =====================
  46. YWxiYXRyb3Nzfl4mfH58Xnw= --> -1
  47. Y3RmbGVhcm5ePj5+Pj5+Pj58 --> 1331000
  48. c3BhZ2hldHRpJj4+fn58fl4m --> 10393
  49. aWJldHlvdWp1c3R0cmllZHRoaXNiZWNhdXNleW91d2FudGVkdG9rbm93d2hhdHRoZW1lc3NhZ2V3YXNeXj4+Xl4mfD4+fCZ8Pj4+PiZePj5+Pj5ePj5ePj4+Pj4+fj4+Pj58fiZ8fCZ8fH4+Pn4+Pn5efH5efl58fCZ8Pj5+Pj5+Pj58JiY= --> 74785
Add Comment
Please, Sign In to add comment