Shell Script: genPassword.sh


This shell script generates a printable password “sheet”.  Passwords on the sheet can be referenced by row.column or row.column.subcolumn.  This password sheet must be distributed in a secure manner; however, once two or more parties have the same password sheet they can specify passwords openly without an adversary knowing the password values.  Each sheet is unique, generated by data from /dev/urandom, and the script automatically generates hashes of the file for ease of identification.

Sample output is included below the script.

#! /bin/sh

NOW=`date +'%Y-%m-%d_%H-%M-%S'`
sleep 1
Title="File Generated ${NOW}"
rm -f DataFile_${NOW}.txt

dd if=/dev/urandom skip=`date +'%M%H%S'` \
    | strings \
    | tr -dc '[:punct:][:alnum:]\n' \
    | awk 'BEGIN{Line="";Ctr=0;}
{
  Line=$0""Line;
  Ctr = Ctr + length($0);
  if (Ctr > 16) {
    print substr(Line, 1,16);
    Line="";
    Ctr=0;
  }
}
' \
    | awk -vTitle="${Title}" '
BEGIN{
  irow=-100;
  icol=1;
  srow="";
  printLine();
  printHeader1(1);
}
END{
  printHeader1(-1);
  printLine();
  print "|                                       Reference Character Set                                 |";
  printf("|");
  for (i=32;i<127;i++) {
    printf("%c",i);
  }
  print "|";
  printLine();
  print "|Method for specifying an entry:  Odd Rows:..  Even Rows:.|";
  printLine();
}
function printLine() {
  printf("+");
  for (i=32;i<127;i++) {
    printf("-",i);
  }
  print "+";
}
function printHeader1Line(item) {
  switch(item) {
  case 1:
    printf("| %-93s |\n", Title);
    break;
  case 2:
    printf("|     ");
    for (i=1;i<6;i++) {
      if ((i % 2) == 0) {
        printf("column.subcolumn ");
      } else {
        printf("     column      ");
      }
    }
    print "     |";
    break;
  case 3:
    printf("|     ");
    for (i=1;i<6;i++) {
      printf("---------------- ");
    }
    print "     |";
    break;
  case 4:
    printf("|     ");
    for (i=1;i<6;i++) {
      printf("      %2d         ",i);
    }
    print "     |";
    break;
  case 5:
    printf("| row ");
    for (i=1;i<6;i++) {
      printf("%2d.1  %2d.2  %2d.3 ",i,i,i);
    }
    print "row  |";
    break;
  default:
    printf("| --- ");
    for (i=1;i<6;i++) { printf("================ "); } print "--- |"; } } function printHeader1(direction) { phimax=6; if (direction > 0) {
    for (phi1=1;phi1<=phimax;phi1++) { printHeader1Line(phi1); } } else { for (phi1=phimax;phi1>=3;phi1--) {
      printHeader1Line(phi1);
    }
    printHeader1Line(1);
  }
}
function getChar(idx) {
  return sprintf("%c",(idx % 26) + 97);
}
{ 
  if (irow > 25) {
    iData="";
    for (i=1;i<=16;i++) { oneChar=substr($0,i,1); if (!((oneChar >= "A" && oneChar <= "Z") || (oneChar >= "a" && oneChar <= "z") || (oneChar >= "0" && oneChar <= "9") || (oneChar == " "))) { oneChar = getChar(i+NR); } iData=iData""oneChar; } } else { iData=$0; } if (irow % 2 == 1) { srow = substr(iData,1,4)" "substr(iData,5,4)" "substr(iData,11,4)" "srow; } else { srow = iData" "srow; } ++icol; if (icol >= 6) {
    if (irow > 0) {
      printf("| %2d  %s %2d  |\n",irow,srow,irow);
    }    srow="";
    icol=1;
    ++irow;
    if (irow > 50) {
      exit;
    }
  }
}' \
    | unix2dos \
    >> DataFile_${NOW}.txt

md5sum < DataFile_${NOW}.txt > DataFile_${NOW}.txt.md5
sha1sum < DataFile_${NOW}.txt > DataFile_${NOW}.txt.sha1

ls -lt DataFile_${NOW}.txt*

Sample Output:

+-----------------------------------------------------------------------------------------------+
| File Generated 2016-03-08_00-32-54                                                            |
|          column      column.subcolumn      column      column.subcolumn      column           |
|     ---------------- ---------------- ---------------- ---------------- ----------------      |
|            1                2                3                4                5              |
| row  1.1   1.2   1.3  2.1   2.2   2.3  3.1   3.2   3.3  4.1   4.2   4.3  5.1   5.2   5.3 row  |
| --- ================ ================ ================ ================ ================ ---  |
|  1  tO"@  U$;q  maVY Z$a4  !N[Q  \'$< _*T1  $*8r  tn:V ,[;1  Iyug  Wu6C /YI(  ~Miq  D=!\   1  |
|  2  *lImy#8XOa"QNM|z AA!3TumCi|U&YH'[ |I*g6D-}j]eqoUK5 hZN7;n7vKU>1['Kn pVq:n1lE#V0s//au   2  |
|  3  $U67  {R*V  b3Q~ ]wy)  L.#,  }W4% hdRD  Nln&  U({9 &>V-  7@Q]  J8@W S~k-  "y\<  5lB1   3  |
|  4  >vDZ0Va}7Ro^cRVM IN9m7/.z4B(H@qUA ;iIS!-'_O&2-rWqh a}vfugqa#YV_,8y0 R''8DhkdoI'V!B1P   4  |
|  5  4~F0  }Yz=  ;AK5 =kcx  @\_e  vYpe `>KY  _U@d  n6?n 1d/z  @Hjk  *f#T eWhc  9`NP  8]"J   5  |
|  6  T>v-*I?!M]:y5;+! b0`wg_4[},r*EnEG 5T[W1e};k3suG,GP ]XY|"_;%S_x}Yt]w 4_`yM#(4Qev*G@Tg   6  |
|  7  A6fq  &m`K  }\'d A^Z;  >Dq$  SmTt *,cH  ^K(m  g04I X-n,  $sK4  =9C5 `w79  6UbC  N3XS   7  |
|  8  8cy-H#Hfq__y9"3b >PjSt&+@EODha<7u 6Ij9nI2X_NpJAKML @m^O{\#@W','7C}O l]HL%cs?yxwfCtQ^   8  |
|  9  nQ\]  -LWQ  ;Rjl ky6.  IZ~<  Qer$ G$u+  '~hy  }y=y Ac6T  #Icn  |?if yEEi  0Vxb  /x,c   9  |
| 10  +MM&#;aR1S]v,5&| 0JtS4b}{Wm^eXwd6 *`~a]p11/TYAljL# E^b"i4Z`PFp;1;17 FQR}iVuT.7.Z_;uw  10  |
| 11  %Q.x  {~Ty  MN+u 5y,T  !E`8  ;\8m J~'l  Ncl`  /M%e ]3Ir  %%iw  `95I C5Sm  `k+2  Y5ic  11  |
| 12  UT:e#^k(D*aV.$D+ aCBXcvd!xTDN^6c9 l'}WjMVC0oaH='ky 2$DHT||4JBr0Xxv, aBP#*SL+v^j_X_kl  12  |
| 13  ]He+  xI(d  g,y> 1fJ/  7nct  0{x} DAI7  (d8[  e)]= f;;=  x[uN  .v8Q pBny  =l}N  :^c^  13  |
| 14  @{;.V%p'C)c`gKZV -DZi:Zx?I!D{)i9- `zuJ~tYA}u7C/Xck ~'l;J]Qri_$oBSX\ C|E;?\eL4~UndR-y  14  |
| 15  ;=#O  S[;q  vM}o f^i;  _/s"  drvP QF|_  <:YJ  ;o5z #+7n  me>%  kG`7 W.it  PJ-E  N5X<  15  |
| 16  TiuE?u.9i#]F/5.( F29D=}ug$ApJU&Od -8~dtqVz~@:NSG{0 xqbAkSQvfO^RK4yM \^pJPoVjmd_p@C#,  16  |
| 17  \BR%  9u}<  @6Z[ 6T".  P$qR  @Rt* ~"4>  az&G  XHXr yqq!  gb4H  eGIx wApA  .0G`  0wu9  17  |
| 18  WLdjBhq}!`.rRwZV U~?`n^HZ=Abx2:cp cAk&u0RzlXD->iM| ^~De28Md8WC$}=l0 cXPw4hLG*yI:-wLN  18  |
| 19  |)G}  kl4,  4{5P 18!X  ./$0  zAoH `8mw  ~q$m  g}x9 2Lsa  XOql  Rd6& :!r$  )/(\  "o}3  19  |
| 20  \u.$UyWH.aI,KJk% %&ODy`nrky\cHMs* MP.{#yrf%c36;>Mx %E5~R%qKLSxs/fX9 A~J$i/*\Qk,59d}8  20  |
| 21  &CF.  Mt!s  |#3y wgtt  wgli  3PYQ TMdC  \9~!  c9c, +fH7  2wc/  Y^Wj K7D`  H|=l  $Vct  21  |
| 22  T%q+vsxq#w9wbhMS Bi8LF28^u(8ckhGk ArZK~D.q|Q|"'y"u oJ6%F""Ix*hn|z]` VRbo':!??/8_Pstv  22  |
| 23  ZMlv  Rp:3  20^l RoVC  D'A*  ayT$ X36&  )p6/  YDin ny<=  :,_+  0lRM `}X=  [aN)  d$~S  23  |
| 24  2mr!--,){>//[fW. 4Z;-YaM;+a-erqT8 -\kZK?{M9FZ/W~[) jnLO+HMbXqv5Pf*l Seb}Xv2*APs[&cyZ  24  |
| 25  ;;Ne  i>EJ  7aiW P{E<  ^hI?  A{3e @[QK  4Fm`  H*@2 EKX\  {T;`  gfc^ P.!1  Y>wP  #>bv  25  |
| 26  mnopD6syuVdx3NTL UmnoEqr0PuvG2yza xlanopqSWtuvuhTQ ytD55o4qrX6bvcxy ijRvmndp6MsWlvBo  26  |
| 27  r1tu  vA3y  UcdR grmt  EdwH  ubcB pKas  FuBw  o07c lZI1  stjZ  v9cp nopU  rMso  IyzF  27  |
| 28  wxNzabdJ9Wq4iWkl zwPkQHOcdnfZu98k QMTxetabFdWVJDKj wu0r7yz2gSdeUgUE stBvwxUzanfGZogK  28  |
| 29  tode  fOhi  vmfo MbcT  efgB  5lMM aDba  eeY8  cmDm 2xyH  cdew  Olnl Gyzl  bsLh  gK0H  29  |
| 30  zsLy0lESovq8Stgv YTrbaklmnobea4tY efgzi7RHRlH4NrjA FPkRx61RSmnop6rs OH93ghTRkl2n0sd3  30  |
| 31  emfo  nqXN  vIaS lhJf  o5qr  uAwi kkMl  5Rpc  37Sw wiQl  lsoC  CUuv hijt  rm0i  WZbx  31  |
| 32  qqstRvSxDzagTdeG OqrsCpv8x8iabkEg G9tTstuvQUihWbDr 9opqrIuuvbkjzJXc s1kpqrLRuIRx3GQb  32  |
| 33  1wxY  GJtO  fDzi opwd  orEz  txJm tmqN  xSfb  BeOP qWnv  wbGG  ZdeG rsdu  vwxj  bc3O  33  |
| 34  wobyJV1hijkY7Zog Gmb3dTtgKijklmbo yv400dmhqhGZWlJg OypFbSUAFhKe3kcD TOkz0k3dAut2lUkK  34  |
| 35  rghi  jhFC  oq7s 0qoS  3rR9  dBqF VrVF  0ijE  tupY EdZY  Ihss  mSqp Ild3  OZ4G  GmBo  35  |
| 36  Cll5o95r30uIPPbz jlMsKycGVlkuvqJV ioilFnjFqpTtu78d Xcj6Mnpopqy3nWva Ghijknm9AfqkdMuF  36  |
| 37  OElE  FSvE  zubc oY1y  sJXB  qznp TiYq  KE5u  xySa mnoN  q5At  OEQ0 7mTm  3TCs  FwSy  37  |
| 38  ovwxyeaM9de4vA2L tH9w0yBNbpdXfphF uofvwuVaabGcGfp1 zfouJwxyPVTccefe kwote8wx46NbXdeM  38  |
| 39  Zab2  Ye5W  jklj yRal  iqXf  TXkl 1IDa  uide  hiji Psyz  5RlB  LnVa h0xM  zWbT  cghb  39  |
| 40  jDChktkvcWoShrLS rffgh1j6lmco3ErO 2dewthi5kdmnYpDr Dc9e7rJijkO116Rq aPLMmjShTjql9hoo  40  |
| 41  GkZB  nhJq  kuhw APkl  M5bI  lttR hmCC  O5n0  gntS gWij  6lmv  trKJ fohS  jklm  8qLU  41  |
| 42  GEqrf5u0w9ozunw0 UrUT4tglvwxIPanM mSo1qrEtm2wtIEv6 Zm4oYqHQXgw8Pyza Sl0i7sqDsthKRcyJ  42  |
| 43  auKw  2Xzz  sebk 4Euq  MFyd  cv9f r906  YA12  N4de z6sZ  3owW  fccL L00U  tukl  zfx5  43  |
| 44  kzh6Z1eYgZPjPlWY xuVab5weaAhiCbnz Cxyza5FVefOAijOe rexh5kFNGifgQDjW uHK1yzuucAlfgh5k  44  |
| 45  K7fo  GGjk  3MXm qder  wcbF  XIop Mk9y  6ghJ  lmnx Dbcx  rffh  elEn zFbA  9sYd  zQDS  45  |
| 46  ivVlopoNiusWdTw6 ht0HUFMoL1UsQuvw ghoXqlMlpIq9whWn iPKijklmnoFyDAtu el5hEWllDno8iFs6  46  |
| 47  ZPpL  SjtZ  xOS9 bTTp  nrsm  wYht 0dn4  ZVEq  VsfA UmmY  3KO3  5eYa jk3m  yMpq  auTp  47  |
| 48  sDuv2wyPUUsdef0A tcYumRkkLu3v9efg yoskovwxWzaxcdjw psrytT3wOuXxTjIm rpLSs1uvZxAvHJcc  48  |
| 49  xlzP  b3eI  d4j4 wxyz  2xXd  ghvj vbzy  zXbc  fchi Z0hs  yza3  ergB cRZk  SyEg  lspg  49  |
| 50  VdGfgx7Qk6m1Cpq2 Mcdefle7c3lHTqoq x3cOofgwiysannnp iarc9efphMXiCmnt 8zab9AfigLgBpcFL  50  |
| --- ================ ================ ================ ================ ================ ---  |
| row  1.1   1.2   1.3  2.1   2.2   2.3  3.1   3.2   3.3  4.1   4.2   4.3  5.1   5.2   5.3 row  |
|            1                2                3                4                5              |
|     ---------------- ---------------- ---------------- ---------------- ----------------      |
| File Generated 2016-03-08_00-32-54                                                            |
+-----------------------------------------------------------------------------------------------+
|                                       Reference Character Set                                 |
| !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~|
+-----------------------------------------------------------------------------------------------+
|Method for specifying an entry:  Odd Rows:<row>.<column>.<sub-column>  Even Rows:<row>.<column>|
+-----------------------------------------------------------------------------------------------+