You are not logged in.

#1 2017-07-26 05:31:52

RankoKohime
Member
Registered: 2014-01-08
Posts: 87
Website

[SOLVED] Making a password dictionary

Well, I did an oops.  I created a new EncFS folder, put my documents in it, and promptly forgot the passphrase.  roll

Fortunately though, I followed my usual passPHRASE format, and so I've built a list of potential words I would have used in it.

I have the script necessary to try the various passphrases through EncFS, but I'm coming up a bit blank on how to construct the list of passphrases.  I've added all the potential words I would have used to a file, one word per line.  Some words contain apostrophes, or commas.  How can I take these individual words, and make combinations (I'm thinking it was 4 words, but I'll try 3 and 5 word combos to be sure), such as the following, with spaces between the words?

Word List

Word1
Word2
Word3

Passphrase List

Word1 Word2 Word3
Word2 Word1 Word3
Word3 Word2 Word1

For those curious, yes I have backups, so at worst I lose about 2 weeks worth of documents.

Last edited by RankoKohime (2017-07-27 02:48:33)

Offline

#2 2017-07-26 06:45:35

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [SOLVED] Making a password dictionary

Why don't you use some secure password store like pass? You will need to remember only one master password.

Offline

#3 2017-07-26 12:20:41

RankoKohime
Member
Registered: 2014-01-08
Posts: 87
Website

Re: [SOLVED] Making a password dictionary

Docbroke wrote:

Why don't you use some secure password store like pass? You will need to remember only one master password.

I do, actually.  And I just so happened to have recorded the password for this encrypted folder.  Problem being, that for backup simplicity, I had placed the password store IN the documents folder.  neutral

Last edited by RankoKohime (2017-07-26 12:21:08)

Offline

#4 2017-07-26 12:35:54

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [SOLVED] Making a password dictionary

RankoKohime wrote:
Docbroke wrote:

Why don't you use some secure password store like pass? You will need to remember only one master password.

I do, actually.  And I just so happened to have recorded the password for this encrypted folder.  Problem being, that for backup simplicity, I had placed the password store IN the documents folder.  neutral

That's nice example of circular dependancies.

Offline

#5 2017-07-26 12:42:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED] Making a password dictionary

echo $(shuf -n3 list)

For most uses you wouldn't need the echo, that just "flattens" the lines.  Generally you could just use the subshell in place of where the string would be needed:

command-that-needs-string $(shuf -n3 list)

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#6 2017-07-26 12:51:40

RankoKohime
Member
Registered: 2014-01-08
Posts: 87
Website

Re: [SOLVED] Making a password dictionary

Docbroke wrote:
RankoKohime wrote:
Docbroke wrote:

Why don't you use some secure password store like pass? You will need to remember only one master password.

I do, actually.  And I just so happened to have recorded the password for this encrypted folder.  Problem being, that for backup simplicity, I had placed the password store IN the documents folder.  neutral

That's nice example of circular dependancies.

Definitely.  That goes on the list of "Things not to do again"

Trilby wrote:
echo $(shuf -n3 list)

For most uses you wouldn't need the echo, that just "flattens" the lines.  Generally you could just use the subshell in place of where the string would be needed:

command-that-needs-string $(shuf -n3 list)

Well, you did introduce me to a unix command I had heretofore not known about, but I'm afraid it doesn't generate the output I would need.  It shuffles around the words just fine, but I'm trying to build phrases from a list of words.

Offline

#7 2017-07-26 12:59:54

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED] Making a password dictionary

Did you actually try the command.  It generates a phrase from 3 random lines of the input list.  If that's not what you want, you'll have to be more clear.

If you want to generate a list of phrases, then use a loop:

for i in {1..10}; do echo $(shuf -n3 list); done

Or do you just want every possible permutation of words?  That's even easier (but a bit more code)...

readarray list < list
n=${#list[@]}
for ((i = 0; i < n; i++)); do for ((j = 0; j < n; j++)); do for ((k = 0; k < n; k++)); do
        [[ $i -ne $j && $i -ne $k && $j -ne $k ]] && echo ${list[$i]} ${list[$j]} ${list[$k]};
done; done; done

This assumes you want random without replacement samples.  Random with replacement (meaning the same word can be used more than once in a phrase) would be the same just without the [[ ]] conditional inside the loops.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#8 2017-07-26 13:37:51

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [SOLVED] Making a password dictionary

I think it was quite clear. He has an unknown password created from known chunks, now he wants all possible combinations.

Here are some versions with python:

# newline separated 
printf "%s\n" "11" "22" "33" | python -c "import sys;import itertools;print('\n'.join([''.join(x) for x in itertools.permutations(sys.stdin.read().splitlines())]))"

# newline separated on stdin
# parameter: number of items per permutation
printf "%s\n" "11" "22" "33" | python -c "import sys;import itertools;print('\n'.join([''.join(x) for x in itertools.permutations(sys.stdin.read().splitlines(), int(sys.argv[1]))]))" 2

# parameters: 
# - list of items
python -c "import sys;import itertools;print('\n'.join([''.join(x) for x in itertools.permutations(sys.argv[1:])]))" 111 222 333

# parameters: 
# - number of items per permutation
# - list of items
python -c "import sys;import itertools;print('\n'.join([''.join(x) for x in itertools.permutations(sys.argv[2:], int(sys.argv[1]))]))" 2 111 222 333

Last edited by progandy (2017-07-26 13:45:51)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Online

#9 2017-07-26 13:59:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED] Making a password dictionary

Yes progandy it seems quite clear, but then why is a solution that does exactly that disregarded as not matching the goal?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#10 2017-07-26 17:49:39

RankoKohime
Member
Registered: 2014-01-08
Posts: 87
Website

Re: [SOLVED] Making a password dictionary

Trilby wrote:

Did you actually try the command.  It generates a phrase from 3 random lines of the input list.  If that's not what you want, you'll have to be more clear.

If you want to generate a list of phrases, then use a loop:

for i in {1..10}; do echo $(shuf -n3 list); done

Or do you just want every possible permutation of words?  That's even easier (but a bit more code)...

readarray list < list
n=${#list[@]}
for ((i = 0; i < n; i++)); do for ((j = 0; j < n; j++)); do for ((k = 0; k < n; k++)); do
        [[ $i -ne $j && $i -ne $k && $j -ne $k ]] && echo ${list[$i]} ${list[$j]} ${list[$k]};
done; done; done

This assumes you want random without replacement samples.  Random with replacement (meaning the same word can be used more than once in a phrase) would be the same just without the [[ ]] conditional inside the loops.

Ahh, my reading comprehension (or lack thereof) struck again.  My brain deleted the echo bit.  yikes

The arrayed code you posted worked perfectly for generating the list.  It's not something I would have thought of on my own, as I haven't delved into arrays as of yet.  So thank you for that.  smile

I now have a dictionary file.  That's only 48 MB.  big_smile

Offline

#11 2017-07-26 20:24:21

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: [SOLVED] Making a password dictionary

Trilby wrote:

Yes progandy it seems quite clear, but then why is a solution that does exactly that disregarded as not matching the goal?

The example given in the first post shows that he was looking for a way to systematically try all permutations. Randomly shuffling the words might never generate all permutations (and it is very unlikely to generate them all without repetition) so that isn't a practical solution. Your nested loop script will do the trick, but that wasn't posted yet when the shuffle was rejected.

edit:
Python script to read a file passed as an argument and generate all the permutations:

#!/usr/bin/env python3
import itertools
import sys
with open(sys.argv[1], 'r') as f:
  words = tuple(w for w in (l.strip('\n') for l in f) if w)
for perm in itertools.permutations(words):
  print(''.join(perm))

This avoid repetition of words in the same phrase.

Last edited by Xyne (2017-07-26 20:30:52)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#12 2017-07-27 04:38:00

RankoKohime
Member
Registered: 2014-01-08
Posts: 87
Website

Re: [SOLVED] Making a password dictionary

I marked the topic as solved.  After running the script while I was away at work, I came home to the folder being unlocked, so this worked out.  smile

Strange thing is, that the passphrase I had stored in pass for this folder was the one I had tried before I thought I had forgotten my passphrase and on testing, it still would not unlock.  So I'm going to be moving these files out of this folder and into a new one to be safe.

Offline

Board footer

Powered by FluxBB