MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Recover lost PGP passphrase with Mathematica! (Done)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127341] Recover lost PGP passphrase with Mathematica! (Done)
  • From: Murta <rodrigomurtax at gmail.com>
  • Date: Wed, 18 Jul 2012 01:39:12 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

Hi all!
Long time ago, I have made one PGP key with one big passphrase that I have 
forgot. I just know some words of it, and could remember that I have mixed 
some Portuguese with German and English in it.
Just for hobby, I tried to break up it using Mathematica, and I get a positive result!..
To do it you'll need to use a Mac with the free GPG installed (GnuPG).
You will need just to save the testFile.gpg (cryptographed with the lost passphase key) in your notebook directory and create a possibility list with some clues of your lost passphrase.
I find my in almost 50.000 combinations!.. (10 minutes)

Don't forget that is necessary to save the notebook before run, it need you r notebook directory (copy and paste do not work)
There is the code,

(*------------------------------------------------------------------------*)
(*Function to create combinations of words*)
phrase[possibilidades_]:=Module[{$frases},
	$frases=Distribute[possibilidades,List];
	$frases=StringJoin@@Riffle[#," "]&/@$frases
]

(*Testing 1 Phrase*)
test1Phrase[pass_,fileName_]:=Module[{test,string,path=NotebookDirectory[],count},
		count:=Length@ReadList["!ls  '"<>path<>"'",Record];
		test=count;
		string="! /usr/local/bin/gpg --batch -q -o '@path/outputRand.txt' --passphrase '@pass' --decrypt  '@path/@fileName'";
		string=StringReplace[string,{"@pass"-> pass,"@path/"-> path,"@fileName" -> fileName,"outputRand"-> ToString@RandomInteger[10^6]}];
		Run[string];
		If[count==test,False,True]
	];

(*Tests each combination*)
testPhraseList[listFrases_,fileName_]:=Module[{return},
	i=1;qtd=Length[listFrases];
	return=Catch[(i++;If[test1Phrase[#,fileName],Throw[#]])&/@listFrases];
	If[Length[return]==0,return,"passphrase not found"]
]
(*Nice progress bar*)
pBar=Dynamic[Row[{ProgressIndicator[i,{0,qtd}]," ",NumberForm[100. i/qtd,{\[Infinity],2}],"% "}]];


(*Using the code*)
(*list of possible words*)
possibleList={{"Minha","Mein","Meine","meine"},
{"Terra","terra","grund","Grund","Land","land"},
{"tem","habe","have"},
{"Palms","palms","palmeiras","Palmeiras"},
{"onde","where"},
{"sing","canta","singt"},
{"der","o","the","die","das","a"},
{"sabia","Sabia","sabi=E1","Sabi=E1"}
};

(*creating list of combinations*)
(listaFrases=phrase[possibleList])//Length

(*testing it!*)
pBar
testPhraseList[listaFrases,"testFile.gpg"]

(*the function will print the file if it find it..*)

(*------------------------------------------------------------------------*)
Good luck if you need it!



  • Prev by Date: Re: Differential Equation: Not getting result
  • Next by Date: Re: Differential Equation: Not getting result
  • Previous by thread: Evaluating complicated integral numerically
  • Next by thread: NDSolve with NIntegrate where Integral is a function of x