Skip to content

Instantly share code, notes, and snippets.

@sdamashek
Last active May 15, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdamashek/56254c311381fb3ae96edb964fd6c58a to your computer and use it in GitHub Desktop.
Save sdamashek/56254c311381fb3ae96edb964fd6c58a to your computer and use it in GitHub Desktop.
TJ CSL Writeup for Point-Slope Encryption (PACTF 2016)

Point-Slope Encryption

For this challenge we were given a pretty basic python script. The script contained two functions: s, which approximates the derivative of the function f at point x, and encrypt, which calculates the value of f(a) and f(m), as well as the approximate derivative of f at both a and m. It then does some manipulation of these numbers to return a tuple.

Essentially what we had to do was figure out what secret_func (f) was, so that we could calculate encrypt for all possible ascii values, then map the resulting encrypted tuples to the given encrypted message to find the decrypted flag.

We're given:

  • a = -9 Pi/4
  • f(a) = -65.50409525102073
  • df/dx = 1651/(12pi * cosx + 5pi * sinx)

So, let's separate variables and integrate df/dx to find f(x), since we're given an initial point we can use to calculate c. Breaking out our good old friend, Mathematica:

> Integrate[1651/(12 Pi*Cos[x] + 5 Pi*Sin[x]), x]
> 1651 (-(Log[3 Cos[x/2] - 2 Sin[x/2]]/(13 \[Pi])) + 
   Log[2 Cos[x/2] + 3 Sin[x/2]]/(13 \[Pi]))

Evaluating at a:

> N[f[-9/4*Pi]]
> -65.5041 + 0. I

So, our c is zero. So we have the correct secret_func, and now all that's left to do is calculate ascii value -> tuple pairs:

First, we define a function encrypt which replicates the functionality of the Python program's encrypt:

> s[x_] := (f[x + 10^(-3)] - f[x])/(10^(-3))
> encrypt[m_] :=
 Module[{a, y0, y1, s0, s1, x},
  
  a = -9/4*Pi;
  y0 = f[a];
  y1 = f[m];
  s0 = s[a];
  s1 = s[m];
  x = (y1 - y0 + s0*a - s1*m)/(s0 - s1);
  
  {FromCharacterCode[m], N[Re[x]], N[Re[s1*(x - m) + y1]]}
  ]

And then map this function over ascii values 40 to 130 for good measure:

> Map[encrypt, Range[40, 130]]
> {{"(", 18.7776, 2675.33}, {")", 6.97647, 1423.89}, {"*", 10.0881, 
1753.86}, {"+", 94.6144, 
10717.4}, {",", -41.7507, -3743.34}, {"-", -51.5124, -4778.52}, \
{".", 39.81, 4905.7}, {"/", 9.99491, 1743.98}, {"0", 9.79389, 
1722.67}, {"1", 38.2941, 
4744.95}, {"2", -59.6029, -5636.47}, {"3", -45.2358, -4112.92}, \
{"4", 138.261, 15345.8}, {"5", 14.8162, 2255.26}, {"6", 10.4197, 
1789.02}, {"7", 24.6893, 
3302.24}, {"8", -123.139, -12374.1}, {"9", -45.6087, -4152.46}, \
{":", -227.055, -23393.8}, {";", 23.2469, 3149.28}, {"<", 11.9605, 
1952.42}, {"=", 19.2521, 2725.66}, {">", 600.793, 
64394.8}, {"?", -51.2162, -4747.11}, {"@", -86.1523, -8451.89}, \
{"A", 40.5807, 4987.43}, {"B", 14.6646, 2239.17}, {"C", 16.9447, 
2480.97}, {"D", 82.5567, 
9438.75}, {"E", -65.2895, -6239.5}, {"F", -64.302, -6134.78}, {"G", 
91.2579, 10361.5}, {"H", 19.145, 2714.3}, {"I", 16.3821, 
2421.31}, {"J", 44.2629, 
5377.91}, {"K", -103.971, -10341.5}, {"L", -58.9394, -5566.11}, \
{"M", 1215.76, 129609.}, {"N", 26.801, 3526.17}, {"O", 17.1525, 
2503.}, {"P", 31.3629, 
4009.93}, {"Q", -364.12, -37928.7}, {"R", -61.2426, -5810.35}, \
{"S", -159.487, -16228.6}, {"T", 41.265, 5060.}, {"U", 19.2867, 
2729.33}, {"V", 25.6586, 3405.03}, {"W", 203.074, 
22218.9}, {"X", -71.5534, -6903.76}, {"Y", -92.5404, -9129.31}, \
{"Z", 75.1891, 8657.45}, {"[", 23.2055, 3144.89}, {"\\", 23.2199, 
3146.42}, {"]", 77.1465, 
8865.03}, {"^", -98.2053, -9730.04}, {"_", -75.8477, -7359.14}, \
{"`", 222.297, 24257.4}, {"a", 29.9627, 3861.46}, {"b", 22.8126, 
3103.22}, {"c", 48.4331, 
5820.14}, {"d", -191.698, -19644.4}, {"e", -72.9015, -7046.71}, \
{"f", -440.179, -45994.4}, {"g", 42.1246, 5151.15}, {"h", 24.1013, 
3239.89}, {"i", 36.7998, 4586.49}, {"j", 1605.57, 
170946.}, {"k", -79.0086, -7694.34}, {"l", -141.407, -14311.3}, \
{"m", 67.1849, 7808.65}, {"n", 27.2622, 3575.09}, {"o", 31.3988, 
4013.74}, {"p", 143.329, 
15883.3}, {"q", -97.8033, -9687.41}, {"r", -99.3577, -9852.24}, \
{"s", 138.505, 15371.7}, {"t", 33.04, 4187.78}, {"u", 29.2437, 
3785.21}, {"v", 74.5103, 
8585.47}, {"w", -150.626, -15289.}, {"x", -87.5244, -8597.38}, {"y",
 1132.97, 120829.}, {"z", 43.2698, 5272.6}, {"{", 29.3449, 
3795.94}, {"|", 51.8057, 
6177.78}, {"}", -466.765, -48813.7}, {"~", -88.3073, -8680.4}, \
{"�", -251.049, -25938.2}, {"�", 62.7549, 7338.88}, {"�", 31.5338, 
4028.05}, {"�", 41.5967, 5095.17}}

This is a list of lists with the letter, and then the two encrypted values corresponding to that letter. I then just manually mapped each encrypted pair to the given encrypted message, to obtain the flag:

flag{c4lC_1z_fuN}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment