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 / afterSignHook.ts
Created May 25, 2019
electron-builder after sign hook to notarize Mac OS apps using electron-notarize
View afterSignHook.ts
// See: https://medium.com/@TwitterArchiveEraser/notarize-electron-apps-7a5f988406db
const fs = require('fs');
const path = require('path');
var electron_notarize = require('electron-notarize');
module.exports = async function (params) {
// Only notarize the app on Mac OS only.
if (process.platform !== 'darwin') {
return;
@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: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 / AES_Decrypt_block.cs
Created Sep 23, 2012
AES single block decryption/encryption _
View AES_Decrypt_block.cs
private static byte[] AES_Decrypt_block(byte[] cipherText, byte[] Key)
{
// Declare the string used to hold the decrypted text.
byte[] output_buffer = new byte[cipherText.Length];
using (AesManaged aesAlg = new AesManaged())
{
//If CBC, must initialize IV = O_{128}
//aesAlg.Mode = CipherMode.CBC;
//aesAlg.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
View indexer_patch.h
//Append this function to class Indexer.
template <typename Matrix>
void spliceToAB(Matrix& M, Matrix& A, Matrix& B)
{
typename Matrix::Row::const_iterator it;
// Splice M into two submatrices A and B, A contains pivot columns, B contains non pivot colums.
uint32 curr_piv = 0;
@martani
martani / gist:4471394
Created Jan 7, 2013
padding oracle attacker
View gist:4471394
//The Oracle
ICBCOracle cbcOracle = new Oracles.OnlineCBCOracle();
//The attacker, passing the Oracle to constructor
PaddingOracleAttacker attacker = new PaddingOracleAttacker(cbcOracle);
//Prepare the ciphertext
string cipherHex = "f20bdba6ff29eed7b046d1df9fb7000058b1ffb4210a580f748";
byte[] cipher = Helpers.ConvertHexStringToByteArray(cipherHex);
@martani
martani / gist:4471399
Last active Dec 10, 2015
Online padding oracle
View gist:4471399
//Class implements ICBCOracle
public class OnlineCBCOracle : ICBCOracle
{
public bool RequestOracle(byte[] cipher)
{
const string BASE_URL = "ORACLE_URL?er=";
string urlData = Helpers.ConvertByteArrayToHexString(cipher);
WebClient wc = new WebClient();
try
@martani
martani / AES_Decrypt_block
Created Sep 23, 2012
AES single block decryption/encryption
View AES_Decrypt_block
private static byte[] AES_Decrypt_block(byte[] cipherText, byte[] Key)
{
// Declare the string used to hold the decrypted text.
byte[] output_buffer = new byte[cipherText.Length];
using (AesManaged aesAlg = new AesManaged())
{
//If CBC, must initialize IV = O_{128}
//aesAlg.Mode = CipherMode.CBC;
//aesAlg.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@martani
martani / qs.sh
Created Feb 8, 2012
Distributed Quadratic Sieve running time
View qs.sh
<<intel i7 for all tests>>
N = 676292275716558246502605230897191366469551764092181362779759 (60 digits | 199 bits)
Time = 16.76 minutes (~ 17 hours on centralized version)
N = 1522666296953962938975648266957818297826962898780435311 (55 digits | 180 bits)
Time = 7.178 minutes
N = 5705979550618670446308578858542675373983 (40 digits | 133 bis)
Time = 5 seconds