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.. 

Sunday, July 30, 2017

Inspire Your Co-Workers with a Screensaver

So you want to display quotes on your computer's locked screen when you're not at your desk. There's one way I know. Looking for a powerpoint that will sequence through slides like in kiosk mode? Sorry, that's not an option (yet) in Windows 10 for the lock screen.

Save your ppt as JPEG images (File > Save As > change the format - the name you provide will be a folder containing each slide)

That done, click on the Window (Start button) on the left of your taskbar and then on the Gear (settings). You'll launch Windows Settings.

Here, in the search box, type "lock" (it might suggest "add a folder to your lock screen slideshow", but don't jump the gun.

At the new menu, change the "Background" option from "Windows Spotlight" to "Slideshow" (drop down)

Then, under "Choose albums for your slideshow", add your new folder.

Then, click on "Advanced slideshow settings" and adjust "When my PC is inactive, show lock .." and "Turn off screen after slideshow has played for".. to your choice.

And that's it. Hit WIN-L and see the result!

Yes, the slides will be displayed in random order - nothing you can do about that :(

Thursday, July 27, 2017

Perl Insert Contents of One File Into Another at Line Matching Regex

Nice to have something I think is better than stackexchange - how often does that happen :) ?

To insert after a line matching the regex

perl -n -i -e 'print; print `cat FILE_TO_INSERT` if m#REGEX_TO_MATCH#; ' FILE_TO_MODIFY

To insert before :

perl -n -i -e 'print `cat FILE_TO_INSERT` if m#REGEX_TO_MATCH#; print;' FILE_TO_MODIFY

If you want the insertion to happen at the first match ONLY :

perl -n -i -e 'print `cat FILE_TO_INSERT` if m?REGEX_TO_MATCH?; print;' FILE_TO_MODIFY

A very valid question is, what do you do if your match pattern has the question-mark character? :)

https://unix.stackexchange.com/questions/32908/how-to-insert-the-content-of-a-file-into-another-file-before-a-pattern-marker

Wednesday, June 28, 2017

Jordan Sissel Kennt Nicht Seine Eigene Tool

he says :

Example: Send ctrl+c to all windows matching title 'gdb' (See COMMAND CHAINING) xdotool search --name gdb key ctrl+c

But that doesn't work - no sir.

Fortunately, 

xdotool windowactivate `xdotool search --name gdb` ; xdotool key ctrl+c

Works, by the power of G!!

Kudos :

Saturday, June 17, 2017

Schooled in Efficient Code - by Udacity

Take a sudoku grid and implement the only-choice - that is, when you have multiple choices for numbers to put in a square - when one of those choices occurs only in this square, you know what to do..

My answer :

    for box in unit :
        for choice in grid[box] :
            others = ''.join( [ grid[x] for x in unit if not x == box ] )
            if not re.search( choice , others ) :
                grid[box] = choice

And U :

    for digit in '123456789':
         dplaces = [box for box in unit if digit in values[box]]
         if len(dplaces) == 1:
             values[dplaces[0]] = digit

For each number in 1..9, they get the boxes that contain that number and then, when there's only one box for a particular number, they assign that number to that box - yes, you'll be doing some redundant work, but ain't the code short and sweet?

Look at me - I first get a string made up of the contents of all the other boxes and then I check if this box's contents (one number at a time) occur in that string..