Skip to content

Instantly share code, notes, and snippets.

@martani
martani / gist:944422
Created April 27, 2011 15:11
A simple Vigenere Decoder
//MARTANI Fakhrou 2011
//Vigenere Decoder
//http://martani.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace codebook
@martani
martani / gist:944949
Created April 27, 2011 19:07
Splitting Vigenere cipher into Caesar groups
static List<string> SplitTextWithKeyLen(string text, int keyLen)
{
List<string> result = new List<string>();
StringBuilder[] sb = new StringBuilder[keyLen];
for (int i = 0; i < keyLen; i++)
sb[i] = new StringBuilder();
for (int i = 0; i < text.Length; i++)
sb[i % keyLen].Append(text[i]);
@martani
martani / gist:944963
Created April 27, 2011 19:15
Frequency Analysis on a text (Caesar cipher + key search)
static Dictionary<char, double> AnalyseFrequency(string text)
{
if (text == null)
return null;
Dictionary<char, double> frequencies = new Dictionary<char, double>();
int textLength = text.Length;
for (int i = 0; i < textLength; i++)
{
@martani
martani / gist:944969
Created April 27, 2011 19:18
Vegenere Decipher
static string DecipherVeginere(string text, string key)
{
StringBuilder result = new StringBuilder();
int keyLength = key.Length;
int diff;
char decoded;
for (int i = 0; i < text.Length; i++)
{
diff = text[i] - key[i%keyLength];
@martani
martani / gist:1107330
Created July 26, 2011 17:44
nanosleep, usleep, sleep benchmark
void nsleep(long us)
{
struct timespec wait;
//printf("Will sleep for is %ld\n", diff); //This will take extra ~70 microseconds
wait.tv_sec = us / (1000 * 1000);
wait.tv_nsec = (us % (1000 * 1000)) * 1000;
nanosleep(&wait, NULL);
}
@martani
martani / gist:1107347
Created July 26, 2011 17:49
nanosleep(), usleep() and sleep() benchmark
$ ./time
Call to nsleep(970000) took 970149
Call to usleep(970000) took 970143
Call to sleep(1) took 1000154
$ ./time
Call to nsleep(970000) took 970105
Call to usleep(970000) took 970169
Call to sleep(1) took 1000142
@martani
martani / gist:1107371
Created July 26, 2011 17:56
gettimeofday_benchmark
void gettimeofday_benchmark()
{
int i;
struct timespec tv_start, tv_end;
struct timeval tv_tmp;
int count = 1 * 1000 * 1000 * 50;
clockid_t clockid;
int rv = clock_getcpuclockid(0, &clockid);
let a = 14
List.fold_left a i
qdfsdf
@martani
martani / pollard-rho.c
Created December 21, 2011 00:22
Pollard's rho factoring method
/*
* pollard-rho.c
* Created on: Dec 20, 2011
* Author: martani
*/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>