Simple C Hello world
because why not
#include <stdint.h>
#include <stdio.h>
uint64_t thingies[8] = {6067222560, -14845362264, 13980265334, -6589377431, 1710792125, -248465651, 18919901, -588254};
uint64_t extraction(int);
int main() {
for(int i = 1; i <= 8; i++) {
for(int j = 0; j < 2; j++) {
putchar((extraction(i) >> (8*(1-j))) & 0xFF);
}
}
return 0;
}
uint64_t extraction(int point) {
uint64_t output=0;
uint64_t input=1;
const uint64_t stable_input = point;
for(int i = 0; i < 8; i++) {
output += thingies[i]*input;
input *= stable_input;
}
return output/5040;
}
When you run it, you get
`Hello, besties!`
---
I was inspired by [this tsoding video](
https://www.youtube.com/watch?v=hmMtQe_mYr0)
Ok so I want to just display the text `Hello, besties!`, now I actually started with the standard `Hello world!`, but I settled on a string that's 15 characters long so that I get a nice round number (I also add a line feed at the end)
So if I convert the string `Hello, besties!` to hex, I get `48 65 6C 6C 6F 2C 20 62 65 73 74 69 65 73 21`, now to make it a nice round 16 characters, we can append a line feed `0A`.
Now how do I represent it in some funky way to obfuscate it? I was playing with the idea of splitting this into two halfs, reinterpreting them as `int`s or `double`s, but both of those options resulted in absurdly large numbers.
I ended up splitting the string into eight parts and reinterpreting them as 16bit `int`s. This results in: `18533, 27756, 28460, 8290, 25971, 29801, 25971, 8458`
Now what do I do with that?
I ended up just placing those numbers on a graph as `y` values for `x` values running from 1 to 8 and fitting a polynomial through that.
I get the following polynomial:
-(294127 x^7)/2520 + (2702843 x^6)/720 - (35495093 x^5)/720 + (48879775 x^4)/144 - (941339633 x^3)/720 + (998590381 x^2)/360 - (206185587 x)/70 + 1203814
Now I can recover the values by plugging in numbers from 1 to 8. To get around doing division on `int`s, I can multiply through with the `lcm` of all denominators and I just need to remember to divide with it at the end. I can confidently do that, because I built the polynomial in such a way, to get an `int` from it at the end.
The `lcm` is 5040, and when I multiply through I get my modified polynomial:
-588254 x^7 + 18919901 x^6 - 248465651 x^5 + 1710792125 x^4 - 6589377431 x^3 + 13980265334 x^2 - 14845362264 x + 6067222560
Now I can just store the coefficients in an array, placing them from lowest to highest power to make evaluation a bit simpler for me
uint64_t thingies[8] = {6067222560, -14845362264, 13980265334, -6589377431, 1710792125, -248465651, 18919901, -588254};
So to recover my eight starting numbers I can just successively plug numbers from 1 to 8 into the polynomial, remembering I need to divide by 5040 at the end
uint64_t extraction(int point) {
uint64_t output=0;
uint64_t input=1;
const uint64_t stable_input = point;
for(int i = 0; i < 8; i++) {
output += thingies[i]*input;
input *= stable_input;
}
return output/5040;
}
And then in `main` I read off the numbers one byte at a time, piping the result into putchar
int main() {
for(int i = 1; i <= 8; i++) {
for(int j = 0; j < 2; j++) {
putchar((extraction(i) >> (8*(1-j))) & 0xFF);
}
}
return 0;
}