Skip to content

Instantly share code, notes, and snippets.

@martani
martani / gist:944422
Created Apr 27, 2011
A simple Vigenere Decoder
View gist:944422
//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 Apr 27, 2011
Splitting Vigenere cipher into Caesar groups
View gist:944949
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 Apr 27, 2011
Frequency Analysis on a text (Caesar cipher + key search)
View gist:944963
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 Apr 27, 2011
Vegenere Decipher
View gist:944969
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 Jul 26, 2011
nanosleep, usleep, sleep benchmark
View gist:1107330
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 Jul 26, 2011
nanosleep(), usleep() and sleep() benchmark
View gist:1107347
$ ./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 Jul 26, 2011
gettimeofday_benchmark
View gist:1107371
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);
View gist:1139493
let a = 14
List.fold_left a i
@martani
martani / pollard-rho.c
Created Dec 21, 2011
Pollard's rho factoring method
View pollard-rho.c
/*
* pollard-rho.c
* Created on: Dec 20, 2011
* Author: martani
*/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>