<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-284535265796527955</id><updated>2011-04-21T12:24:07.323-07:00</updated><category term='sudoku password bash shell script unix linux perl sed awk sort cut paste'/><title type='text'>Script Maven</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://scriptmaven.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/284535265796527955/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://scriptmaven.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Script Maven</name><uri>http://www.blogger.com/profile/15298055747984752174</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-284535265796527955.post-3279067267447915826</id><published>2008-05-07T15:03:00.000-07:00</published><updated>2008-05-07T16:06:11.976-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sudoku password bash shell script unix linux perl sed awk sort cut paste'/><title type='text'>Combining two obsessions:  Sudoku and safe passwords</title><content type='html'>In grade school, Encyclopedia Brown was my hero.  I had a brain like a sponge and could recite factoids &lt;span style="font-style: italic;"&gt;ad nauseum&lt;/span&gt;.  But eventually even someone with a prodigious memory can be overwhelmed by the vast numbers of passwords required for all the different accounts and services we use these days.&lt;br /&gt;&lt;br /&gt;Yes, there's software and browser add-ons that can keep track of your passwords for you, but I distrust saving anything that sensitive in electric media.  That makes it accessible to crackers, in a relatively easily accessible form.&lt;a href="http://www.schneier.com/blog/archives/2005/06/write_down_your.html"&gt;&lt;br /&gt;&lt;br /&gt;Bruce Schneier&lt;/a&gt; recommends writing down your passwords, and I agree.  But I still get a little uncomfortable that someone might find my list or read over my shoulder.&lt;br /&gt;&lt;br /&gt;There's a nice little Perl module, &lt;a href="http://search.cpan.org/%7Ecgrau/String-MkPasswd-0.02/bin/mkpasswd.pl"&gt;mkpasswd.pl&lt;/a&gt;, that can be used to generate strong random passwords.  This is good, but then you have to write them down somewhere.  For a while, I had a little card with 12 rows of 3 passwords each.  I printed this out, kept no electronic records, and used various patterns from the card.  For variety, I would sometimes make a password out of a column of characters, but it irritated me that the initial pattern of mkpasswd.pl was broken  sometimes there would be several symbols in a column, and sometimes lots of digits.&lt;br /&gt;&lt;br /&gt;I started thinking, How could I constrain 9 rows and columns so that you had the same pattern (for example, 1 symbol and 2 digits) in each row or column?  Then it occurred to me, this is nearly the same set of constraints as in a Sudoku puzzle!  A solved puzzle has digits 1 through 9 uniquely in each row or column, and in each 3x3 sub-grid as well.&lt;br /&gt;&lt;br /&gt;I put this in the back of my mind for about a year and a half, since I wasn't sure how to do it.  To start with, how would I make sure that the sudoku digits corresponded to the same pattern of characters?   Then suddenly, it came to me.&lt;br /&gt;&lt;br /&gt;Here is the script, &lt;span style="font-family:courier new;"&gt;sudoku_passwd_card&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;#&lt;br /&gt;#  Sudoku-constrained password card generator&lt;br /&gt;#&lt;br /&gt;#  Use a randomly generated solved sudoku grid plus mkpasswd.pl&lt;br /&gt;#  to print a grid like this:&lt;br /&gt;#&lt;br /&gt;#    +-------+-------+-------++-------+-------+-------+&lt;br /&gt;#    | x F B | w N 7 | 2 , o || H l a | 0 8 V | o , W |&lt;br /&gt;#    | g 1 % | y m s | 9 t L || 1 u 4 | { g s | i h w |&lt;br /&gt;#    | K 1 h | 0 : L | d Q u || t v } | X Z f | G 6 1 |&lt;br /&gt;#    +-------+-------+-------++-------+-------+-------+&lt;br /&gt;#    | c F 8 | | T 0 | u r m || } 0 z | h X l | 5 Q c |&lt;br /&gt;#    | J - 8 | Y o L | x c 5 || 3 r g | X 6 u | s e &gt; |&lt;br /&gt;#    | j y p | 5 o j | L 3 ^ || w C F | 8 z ? | 2 n E |&lt;br /&gt;#    +-------+-------+-------++-------+-------+-------+&lt;br /&gt;#    | * t d | i 2 v | s 9 a || x F m | x v F | $ 2 7 |&lt;br /&gt;#    | 0 t c | c r ^ | M x 1 || G 9 Z | x - 4 | n f g |&lt;br /&gt;#    | 0 b Q | W 5 p | = X E || q ~ 1 | x h 6 | R R c |&lt;br /&gt;#    +-------+-------+-------++-------+-------+-------+&lt;br /&gt;#&lt;br /&gt;#  Each 9-character row, column or 3x3 square contains&lt;br /&gt;#  1 symbol, 2 digits, and some lower and upper case.&lt;br /&gt;#&lt;br /&gt;#  Reading forward, backward, up, down,&lt;br /&gt;#  in rows, columns and squares, gives you at least 144 combinations.&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;umask 077&lt;br /&gt;tmpdir=/tmp/sudoku_passwd.$USER.$$&lt;br /&gt;MKPASSWD="mkpasswd.pl -d 2 -s 1 | sed -e 's/\([^ ]\)/\1\n/g' | grep -v '^ *$' | sed -e 's/^ *//'"&lt;br /&gt;&lt;br /&gt;j=0&lt;br /&gt;while [[ $j -lt 2 ]] ; do&lt;br /&gt;&lt;br /&gt;j=$((j+1))&lt;br /&gt;TMPDIR=${tmpdir}.$j&lt;br /&gt;&lt;br /&gt;mkdir -p $TMPDIR/&lt;br /&gt;&lt;br /&gt;# Use mkpasswd.pl to make a random permutation from sorted&lt;br /&gt;# Symbol, 2x digit, 2x Upper, 4x lower to something else.&lt;br /&gt;#&lt;br /&gt;eval $MKPASSWD | \&lt;br /&gt;nl | \&lt;br /&gt;awk '{print $2 " " $1}' | \&lt;br /&gt;sort -fd | \&lt;br /&gt;awk '{print $2}' &gt; $TMPDIR/file0&lt;br /&gt;&lt;br /&gt;# Create a random sudoku puzzle,&lt;br /&gt;# solve it,&lt;br /&gt;# then print it out as a 9x9 space-separated grid:&lt;br /&gt;sudoku-generator $seed | head -$((seed % 16)) | tail -1 | tr '.' '0' | \&lt;br /&gt;sudoku.pl 2&gt;&amp;amp;1 | \&lt;br /&gt;sed -e 's/\([^ ]\)/\1 /g' | xargs -n9 echo &gt; $TMPDIR/puzzle&lt;br /&gt;&lt;br /&gt;i=0&lt;br /&gt;while [[ $i -lt 9 ]] ; do&lt;br /&gt;   i=$((i+1))&lt;br /&gt;&lt;br /&gt;   # Make a password, sort it to standard order,&lt;br /&gt;   # then permute it using file0 above to get it into same&lt;br /&gt;   # sequence as template password&lt;br /&gt;   eval $MKPASSWD | \&lt;br /&gt;   sort -fd | \&lt;br /&gt;   paste $TMPDIR/file0 - | \&lt;br /&gt;   sort -n | \&lt;br /&gt;   awk '{print $2}' | \&lt;br /&gt;   nl | \&lt;br /&gt;   awk '{print $2 " " $1}' &gt; $TMPDIR/pair$i&lt;br /&gt;&lt;br /&gt;   # Cut the i-th column from the puzzle, and figure out the permutation&lt;br /&gt;   # needed to create that ordering&lt;br /&gt;   cut -f$i -d' ' $TMPDIR/puzzle | \&lt;br /&gt;   nl | \&lt;br /&gt;   awk '{print $2 " " $1}' |  \&lt;br /&gt;   sort -n | \&lt;br /&gt;   awk '{print $2}' &gt; $TMPDIR/perm$i&lt;br /&gt;&lt;br /&gt;   # Now apply the puzzle-column permutation to the password column&lt;br /&gt;   paste $TMPDIR/perm$i $TMPDIR/pair$i | \&lt;br /&gt;   sort -n | \&lt;br /&gt;   awk '{print $2}' &gt; $TMPDIR/col$i&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;# Print out the two sudoku password squares side by side.&lt;br /&gt;# Perl one-liner:&lt;br /&gt;#   set counter, print initial line.&lt;br /&gt;#   print formatted set of 18 fields,&lt;br /&gt;#   increment counter,&lt;br /&gt;#   print line separator if counter mod 3 is zero.&lt;br /&gt;paste ${tmpdir}.{1,2}/col[1-9] |&lt;br /&gt;perl -wlna -e \&lt;br /&gt;'BEGIN { $i=0;&lt;br /&gt;         print "+-------+-------+-------++-------+-------+-------+";&lt;br /&gt;       };&lt;br /&gt; print "| @F[0..2] | @F[3..5] | @F[6..8] || @F[9..11] | @F[12..14] | @F[15..17] |"&lt;br /&gt; and ($i += 1)&lt;br /&gt; and ( $i % 3 == 0 )&lt;br /&gt; and print "+-------+-------+-------++-------+-------+-------+";'&lt;br /&gt;&lt;br /&gt;/bin/rm -rf $tmpdir&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Besides mkpasswd.pl, I use two other utilities I scarfed from the net.  The first was a &lt;a href="http://magictour.free.fr/suexg.exe"&gt;sudoku puzzle generator in C&lt;/a&gt;, and the second was a &lt;a href="http://www.ecclestoad.co.uk/blog/2005/06/02/sudoku_solver_in_three_lines_explained.html"&gt;3 line perl script&lt;/a&gt; that solves a sudoku puzzle using brute force.&lt;br /&gt;&lt;br /&gt;Here's what I do:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Generate a random password and print out one character per line&lt;/li&gt;&lt;li&gt;Number the lines, reverse columns so the password is in front, then sort in dictionary order.  Trim off the password, we're done with it.&lt;/li&gt;&lt;/ul&gt;This creates a permuted column of the digits 1 through 9, the pattern that we will use for all our generated passwords.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Generate a solved sudoku puzzle using the 9 digit sequence as our seed.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;For each column of the puzzle,&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Generate a random password as a column, sort to dictionary order, then permute using the template pattern to get our standard password order.&lt;/li&gt;&lt;li&gt;Cut a column from the puzzle, and figure out the permutation that takes an ordered list into the column ordering.&lt;/li&gt;&lt;li&gt;Apply that permutation to the password column&lt;/li&gt;&lt;/ul&gt;When you've created enough columns, print them out in a Sudoku type grid.  I like to print this out in a credit-card-size, so I print two grids next to each other.&lt;br /&gt;&lt;br /&gt;Every time you run this, you get a new grid.  To ensure that the information isn't saved anywhere, I send the output directly to the printer:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sudoku_passwd_card | enscript&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Isn't this cute?  You get at least 144 passwords out of this card without much work, and even more if you want to get devious.&lt;br /&gt;&lt;br /&gt;You're probably thinking, why do all that work?  If you've found this blog, you probably don't need this yourself.  You have a good system and know how to create strong passwords.  But you may be blessed with some friends or customers who need a little help, and if you can make things easier for them, your system will be that much more secure.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/284535265796527955-3279067267447915826?l=scriptmaven.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptmaven.blogspot.com/feeds/3279067267447915826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=284535265796527955&amp;postID=3279067267447915826' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/284535265796527955/posts/default/3279067267447915826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/284535265796527955/posts/default/3279067267447915826'/><link rel='alternate' type='text/html' href='http://scriptmaven.blogspot.com/2008/05/combining-two-obsessions-sudoku-and.html' title='Combining two obsessions:  Sudoku and safe passwords'/><author><name>Script Maven</name><uri>http://www.blogger.com/profile/15298055747984752174</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
