This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MARTANI Fakhrou 2011 | |
//Vigenere Decoder | |
//http://martani.net | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace codebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = 14 | |
List.fold_left a i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qdfsdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* pollard-rho.c | |
* Created on: Dec 20, 2011 | |
* Author: martani | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <gmp.h> |
OlderNewer