Skip to content

Instantly share code, notes, and snippets.

@ScratchyCode
ScratchyCode / Brute force.c
Last active December 28, 2017 15:51
Known the password length generates an exhaustive dictionary.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// number of characters into charset
#define CHARACTERS 62
// charset
static const char charset[] =
"abcdefghijklmnopqrstuvwxyz"
@ScratchyCode
ScratchyCode / [Math] - PrimesVect.c
Last active January 15, 2018 16:48
An N number is prime if it is not divided by any prime number less than N. This program performs the least number of primality checks possible.
// Coded by ScratchyCode
// Compile in gcc with option -lm
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int even(unsigned long long int num);
int prime(unsigned long long int num, unsigned long long int vect[], unsigned long long int index);
int main(){
@ScratchyCode
ScratchyCode / [Statistics] - RealRand.c
Last active January 15, 2018 16:48
This is a random number generator for demonstrative purpose. To obtain acceptable results, one must choose as a source of the signal a random physical phenomenon, such as ambient temperature changes, electronic or environmental noise or natural radioactivity.
// Coded by ScratchyCode
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
long long int var=0;
void sighandler1(int);
int main(){
@ScratchyCode
ScratchyCode / [Statistics] - Poisson.c
Last active May 4, 2018 22:47
The poissonian probability for N events with average A.
// Coded by ScratchyCode
// Compile in gcc with option -lm
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double factorial(long long int N);
int main(void){
long long int N;
@ScratchyCode
ScratchyCode / [Statistics] - Gauss.c
Last active January 15, 2018 16:46
Generate N events that follow the gaussian distribution and print statistics.
// Coded by ScratchyCode
// Compile in gcc with option -lm
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SUBSAMPLES 10
int control(void);
@ScratchyCode
ScratchyCode / [Statistics] - Chi square.c
Last active June 14, 2018 21:48
Evaluate the Chi square of observed dataset respect to a expected dataset.
// Coded by ScratchyCode
// Compile in gcc with option -lm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
// maximum size for file name
#define LEN 100
@ScratchyCode
ScratchyCode / Spectre.c
Last active January 5, 2018 06:23 — forked from ErikAugust/spectre.c
Code to test machine's vulnerability behind spectre exploitation.
// From the academic paper "Spectre Attacks: Exploiting Speculative Execution"
/*
We're putting text "The Magic Words are Squeamish Ossifrage." in memory and then we're trying to read it using exploit.
If system is vulnerable, you'll see same text in output, readed from memory.
In this code, if the compiled instructions in victim_function() were executed in strict program order, the function would only read from array1[0..15] since array1 size = 16.
However, when executed speculatively, out-of-bounds reads are possible.
The read memory byte() function makes several training calls to victim_function() to make the branch predictor expect valid values for x, then calls with an out-of-bounds x.
The conditional branch mispredicts, and the ensuing speculative execution reads a secret byte using the out-of-bounds x.
The speculative code then reads from array2[array1[x] * 512], leaking the value of array1[x] into the cache state.
@ScratchyCode
ScratchyCode / [Physics] - Brownian motion.c
Last active January 15, 2018 16:42
Simulates a particle's trajectory that is moving with brownian motion, defining an infinitesimal change of position with a random angle.
// Coded by ScratchyCode
// Compile with -lm
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
// radiant degree
#define BROWNIAN_THETA (2*M_PI)
@ScratchyCode
ScratchyCode / [Math] - Base converter.c
Last active January 15, 2018 16:41
Convert inserted base 10 numbers in any other base < 16.
// Coded by ScratchyCode
// Compile with -lm
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define BITS 64
int main(void){
long long int n, i=0, j=0;
@ScratchyCode
ScratchyCode / [Math] - Bailey-Borwein-Plouffe.c
Last active January 15, 2018 16:50
Some programs that implement algorithms wich approximate the pi value.
// Coded by ScratchyCode
/*
This program approximates the value of Pi with a rapid decimal expansion thanks to a summation,
that converges to the pi value very quickly, called Bailey-Borwein-Plouffe, discovered in 1995.
*/
#include <stdio.h>
#include <math.h>
long double BBPpigreco(long long int i);