Last active
          October 8, 2015 01:49 
        
      - 
      
- 
        Save dunhamsteve/3259075 to your computer and use it in GitHub Desktop. 
    A python script to generate a wallet-sized "table recta" for passwords
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/python | |
| # This code is public domain, share and enjoy. | |
| import random, re, sys, os | |
| seed = None | |
| if len(sys.argv) > 1: | |
| seed = int(sys.argv[1]) | |
| # Output not redirected | |
| if os.fstat(0) == os.fstat(1): | |
| print >>sys.stderr, """ | |
| Tabla Recta generator. Outputs PS to stdout. | |
| Usage: %s [seed] > table.ps | |
| """ % sys.argv[0] | |
| exit() | |
| if seed: | |
| print >>sys.stderr, "\nGenerating table with seed:", seed, "\n" | |
| r = random.Random(seed) | |
| else: | |
| print >>sys.stderr, "\nGenerating table with random seed.\n" | |
| r = random.Random() | |
| head = [chr(65+i) for i in range(26)] | |
| lines = [] | |
| lines.append(' '.join(['.', ' '.join(head), '.'])) | |
| for i in range(13): | |
| row = [ chr(r.randint(33,117)) for j in range(26)] | |
| lines.append(' '.join([chr(65+i), ' '.join(row), chr(78+i)])) | |
| print """%!PS | |
| /Courier 7 selectfont | |
| /nl { 9 sub dup 72 exch moveto } def | |
| 720""" | |
| for line in lines: | |
| line = re.sub(r'([()\\])',r'\\\1', line) | |
| line = re.sub(r'`', r'\\301', line) | |
| print "nl (%s) show" % line | |
| print "showpage" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment