Skip to content

Instantly share code, notes, and snippets.

View vlofgren's full-sized avatar
📈

Viktor vlofgren

📈
View GitHub Profile
// end range is the first number that shouldn't be included (to be in line with problem formulation)
constexpr int projecteuler1(int endRange) {
return (3*((endRange-1)/3)*((endRange-1)/3+1)
+ 5*((endRange-1)/5)*((endRange-1)/5+1)
- 15*((endRange-1)/15)*((endRange-1)/15+1))/2;
}
struct A {
uint8_t data[80];
};
struct B {
uint8_t data[80];
};
struct C {
uint8_t data[160];
@vlofgren
vlofgren / test-33.s
Last active August 29, 2015 14:24
132 byte payload
.L2:
subq $144, %rsp
.cfi_def_cfa_offset 320
movq %r12, %rsi
movq %rbx, %rcx
movq %rsp, %rdi
rep movsq
movl (%rsi), %eax
movl %eax, (%rdi)
call _Z8consumer7payloadILi33EE
@vlofgren
vlofgren / test-31.s
Last active August 29, 2015 14:24
124 byte payload
addq $-128, %rsp
.cfi_def_cfa_offset 288
movq 128(%rsp), %rax
movq %rax, (%rsp)
movq 136(%rsp), %rax
movq %rax, 8(%rsp)
movq 144(%rsp), %rax
movq %rax, 16(%rsp)
movq 152(%rsp), %rax
movq %rax, 24(%rsp)
double carrier_phase[2];
double carrier_strength = fourier1p(dbuffer, (float) length * carrier / (float)rate, length, &carrier_phase[0], &carrier_phase[1]);
if(carrier_strength < threshold) continue;
double delta_re = carrier_phase[0] * old_carrier_phase[0] + carrier_phase[1]*old_carrier_phase[1];
double delta_im = -carrier_phase[1]*old_carrier_phase[0] + carrier_phase[0] * old_carrier_phase[1];
double fourier1p(double x_in[], double n, int length, double* phase_r, double* phase_i) {
double x_complex[2] = { 0, 0 };
int i;
for(i = 0; i < length; i++) {
x_complex[0] += x_in[i] * cos(M_PI * 2 * i * n / (double) length);
x_complex[1] += x_in[i] * sin(M_PI * 2 * i * n / (double) length);
}
double norm = sqrt(x_complex[0]*x_complex[0] + x_complex[1]*x_complex[1]);
if(sum < threshold) {
if(signal_length) {
if(signal_length > 10) {
if(bit != 0) printf("(?)");
bit = 0;
signal_length = 0;
} else {
bit_data = 2 * bit_data + (signal_length < 6);
if(++bit == 8) {
printf("%c", bit_data);
if(sum > threshold) {
/* Signal is present in data block */
} else {
/* Signal isn't present */
}
double sum = 0;
for(harmonic = 1; 2*harmonic < length / frq; harmonic++) {
sum += fourier1(data, frq * harmonic, length);
}
double fourier1(double x_in[], double n, int length) {
double x_complex[2] = { 0, 0 };
int i;
for(i = 0; i < length; i++) {
x_complex[0] += x_in[i] * cos(M_PI * 2 * i * n / (double) length);
x_complex[1] += x_in[i] * sin(M_PI * 2 * i * n / (double) length);
}
return sqrt(x_complex[0]*x_complex[0] + x_complex[1]*x_complex[1]) / (double) length;
}