Skip to content

Instantly share code, notes, and snippets.

@martani
martani / qs.sh
Created February 8, 2012 23:27
Distributed Quadratic Sieve running time
<<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
@martani
martani / AES_Decrypt_block
Created September 23, 2012 16:03
AES single block decryption/encryption
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 / gist:4471399
Last active December 10, 2015 17:58
Online padding oracle
//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 / gist:4471394
Created January 7, 2013 00:44
padding oracle attacker
//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);
//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 / AES_Decrypt_block.cs
Created September 23, 2012 22:53
AES single block decryption/encryption _
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 / 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: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 / afterSignHook.ts
Created May 25, 2019 03:12
electron-builder after sign hook to notarize Mac OS apps using electron-notarize
// 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: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