Thursday, August 17, 2017

How to Be a Good Codebreaker : Wolf (William) Friedman

Under mental equipment he would also include the faculty of being able to concentrate on a problem for rather long periods of time, without distraction, nervous irritability, and impatience. The strain under which cryptanalytic studies are necessarily conducted is quite severe and too long-continued application has the effect of draining nervous energy to an unwholesome degree, so that a word or two of caution may not here be out of place. One should continue at work only so long as a peaceful, calm spirit prevails, whether the work is fruitful or not. 'But just as soon as the mind becomes wearied with the exertion, or just as soon as a feeling of hopelessness or mental fatigue intervenes, it is better to stop completely and turn to other activities, rest, or play. It is essential to remark that systematization and orderliness of work are aids in reducing nervous tension and irritability. On this account it is better to take the time to prepare the data carefully, rewrite the text if necessary, and so on, rather than work with slipshod, incomplete, or improperly arranged material.

https://www.nsa.gov/portals/75/documents/news-features/declassified-documents/military-cryptanalysis/mil_crypt_I.pdf

How Will You Find the Longest Words Shakespeare Used (Perl)

  1. Get them text from : https://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt
  2. vi ./shakesp.txt    # get rid of the obviously easy stuff - a look through tells you up to what point (sonnets start) you can safely delete :)
  3. perl -n -000 -e 'print unless /^\s*\d+\s*$|ELECTRONIC|^\s*the\s+end\s*$|project\s+gutenberg|etext/i;' ./shakesp.txt > shakeclean.txt
  4. perl -p -e 's/[^a-zA-Z\047]/\n/g; s/(.)/\L$1/g;' shakeclean.txt | perl -nl -e 'chomp; print if length > 13;' | sort | uniq | perl -n -0'' -e '@words = split( "\n" ); @sorted = sort { length $b <=> length $a } @words; $longest = join "\n", @sorted; print "$longest";'
honorificabilitudinitatibus (Love's Labour Lost)
anthropophaginian
indistinguishable
undistinguishable
incomprehensible
superserviceable
circumscription
disproportioned
distemperatures
distinguishment
enfranchisement
excommunication
extraordinarily
flibbertigibbet
impossibilities
indistinguish'd
interchangeably
interchangement
interrogatories
misconstruction
notwithstanding
particularities
perpendicularly
portotartarossa
praeclarissimus
prognostication
superstitiously
transformations
uncompassionate
uncomprehensive
undistinguished
unreconciliable
accommodations
accomplishment
acknowledgment
administration
affectionately
apprenticehood
carnarvonshire
circumstantial
consanguineous
considerations
conspectuities
constantinople
contemptuously
contumeliously
correspondence
counterfeiting
determinations
discomfortable
discontentedly
disparagements
distemperature
entertainments
fortifications
halfpennyworth
handicraftsmen
imperceiverant
inconveniences
insurrection's
intelligencing
inter'gatories
interpretation
leicestershire
mephostophilus
nebuchadnezzar
northumberland
oscorbidulchos
preposterously
principalities
proportionable
reconciliation
sovereignvours
superscription
transformation
unaccommodated
understandings
unpremeditated
unproportion'd
unquestionable
unthankfulness
voluptuousness

Saturday, August 12, 2017

Oh For a Better Python Debugger

Are there any debuggers that, when they tell you they run into an issue when you did "continue" can also tell you what steps to take to get the line before you get the problem?

Someone should make one and upgrade the pdb likewise.

Wednesday, August 09, 2017

The Underwhelming Genius of Guido van Rossum's Underlings

$ pip install XlsxWriter
Requirement already satisfied: XlsxWriter in c:\users\USERNAME\appdata\local\programs\python\python35-32\lib\site-packages

$ python -m XlsxWriter
/usr/bin/python: No module named XlsxWriter

Why can't python or even pip for that matter put out a warning about PYTHONPATH? What single mom with three kids and a mortgage needs to find out she has cancer before they put this in?

Das mensch suggests python -m pip install is a panacea. Really?

 $ python -m pip install XlsxWriter
Collecting XlsxWriter
  Using cached XlsxWriter-0.9.8-py2.py3-none-any.whl
Installing collected packages: XlsxWriter
Successfully installed XlsxWriter-0.9.8
 $ python -m !$
python -m XlsxWriter
C:\Users\USER\AppData\Local\Continuum\Anaconda3\envs\aind\python.exe: No module named XlsxWriter

WT*!!??

Okay, reading and reading and reading (for all the protesting CS folks do about user experience, when it comes to free stuff, unless you're the product (think GOOG)) you get what you pay for. Why can't they issue a warning saying (say) "importing usually uses the name in lowercase completely". Why not ease the pain?

So, if I set my PYTHONPATH and then do python -m xlsxwriter.worksheet, I actually do get something.. 

Getting Windows and Cygwin to Behave and then Using du for Disk Space Accounting

One use of Cygwin Windows can't match (I mean a unix feature Redmond hasn't heard of) is du

Your disk space is running low and of course Windows gives you accounting info - accurate but useless info - it doesn't tell you who the culprits are..

Unix - via Cygwin can help

But...

user@host /cygdrive/c
$ echo  `ls -d */ | grep ocumen | perl -p -e 's%/.*$%%;  s/\h/\134 /g;'`
Documents\ and\ Settings

user@host /cygdrive/c
$ du -ks  `ls -d */ | grep ocumen | perl -p -e 's%/.*$%%;  s/\h/\134 /g;'`
du: cannot access 'Documents\': No such file or directory
du: cannot access 'and\': No such file or directory
du: cannot access 'Settings': No such file or directory

Smell a rat? It's been bugging me for too long..

The ultimate goal is to be able to do $ for dir in `asdfdas` ; do ; du -ks $dir ; done ... But, it's turning out to be harder than I thought..

Here's the other problem. You do

$ for dir in `ls -d */` ; do ; echo $dir ; done
you get

Documents
and
Settings

which will make du curse you. Here's my workaround : 

for dir in `ls -1 -d */ | perl -p -e 's@/.*@@; s/\h/\%20/g; '`
do
tdir=`echo $dir | perl -p -e 's/%20/ /g;'`
du -ks "$tdir"
done

You're first giving bash's for loop a list with spaces in filenames substituted with %20. This is just so the for loop behaves (yes, you can mess with the IFS variable)
Then, you create a variable with the filename restored.
Then you call du on this new variable