In [8]:
int("0xb0fd12ed",16)

Out[8]:
2969375469
In [9]:
import numpy as np

_a = ord('a')
_z = ord('z')
_A = ord('A')
_Z = ord('Z')

def encipher(s, n):
arr = np.fromstring(s, np.uint8)
rawcipher(arr, n)
return arr.tostring()

def rawcipher(arr, n):
lower = (arr >= _a) & (arr <= _z)
upper = (arr >= _A) & (arr <= _Z)
arr[lower | upper] += n
arr[lower & (arr > _z)] -= 26
arr[upper & (arr > _Z)] -= 26

letters = np.ones(128, dtype=np.float32)
letters[ord(' ')] = 0.1904
letters[ord('e')] = 0.1017
letters[ord('t')] = 0.0737
letters[ord('a')] = 0.0661
letters[ord('o')] = 0.0610
letters[ord('i')] = 0.0562
letters[ord('n')] = 0.0557
letters[ord('h')] = 0.0542
letters[ord('s')] = 0.0508
letters[ord('r')] = 0.0458
letters[ord('d')] = 0.0369
letters[ord('l')] = 0.0325
letters[ord('u')] = 0.0228
letters[ord('m')] = 0.0205
letters[ord('c')] = 0.0192
letters[ord('w')] = 0.0190
letters[ord('f')] = 0.0175
letters[ord('y')] = 0.0165
letters[ord('g')] = 0.0161
letters[ord('p')] = 0.0131
letters[ord('b')] = 0.0115
letters[ord('v')] = 0.0088
letters[ord('k')] = 0.0066
letters[ord('x')] = 0.0014
letters[ord('j')] = 0.0008
letters[ord('q')] = 0.0008
letters[ord('z')] = 0.0005
letters[_A:_Z+1] = letters[_a:_z+1]

def score(arr):
return letters[arr].sum()

def decipher(s):
arr = np.fromstring(s, np.uint8)
bestStr = None
bestScore = 0
for n in range(0, 26):
rawcipher(arr, 1)
thisScore = score(arr)
if thisScore > bestScore:
bestScore = thisScore
bestStr = arr.tostring()

return bestStr

decipher("ftqeqodqfbmeebtdmequecuuylfnnjprnxqpxqrxhudtrbbdgpq")

Out[9]:
b'thesecretpassphraseisqiimztbbxdfbledleflvirhfpprude'
In [14]:
string = """
It might have been expected that the attempt to trace to their origin
in the past the institutions and customs in common use upon the sea
would from an early date occupy the attention of a seafaring people,
but for some obscure reason the British nation has always been
indifferent to the history of its activities upon that element on which
its greatness was founded, and to which it has become more and more
dependent for its daily bread and its very existence. To those who
are alive to this fact it will hardly come as a surprise, therefore,
to learn that the first sustained attempt at a detailed investigation
into the history of the flag at sea was made under the patronage
_Die Flagge_, published in 1912, was the first book to deal with the
development of the flag at sea in a scientific spirit, and although
the earlier chapters contain some mistakes due to his employment of
translations of early works instead of original texts, and the accounts
of the British flags in the later chapters suffer because he had no

The present book is an attempt to remove the reproach to the British
nation which this implies. Its plan is somewhat different from that
of the work referred to above. Instead of dealing with the flags of
all maritime nations of the world--a task that (if it was to be more
than a mere copying or compilation) would entail much work in foreign
archives--it seemed more profitable to concentrate upon the history
of British Naval Flags, for researches made so far back as 1908 had
acceptance. But first it seemed necessary to devote some time and
space to the inquiry into the origin of the flag and how it became the
honoured symbol of nationality that it now is, and for this a general
view had to be taken in order that a firm foundation might be laid for
the early history of our own flags.

In the first chapter the ground worked over by Admiral Siegel has been
solidified by examination of the original authorities, with the result
that a few errors have been detected and some new facts brought to
light, and the investigation has also been extended further; the most
important of the additions being those relating to the standards in
the Phoenician and Greek ships of war, forms of the early "standard"
and "gonfanon," and the Genoese Standard of St George and the Dragon.
For the deduction that the use of a national flag arose in the Italian
city states I take the entire responsibility, well aware that further
investigations may possibly bring to light fresh facts which will
overthrow it.

The chapter on early English, Scottish and Irish flags serves as an
introduction to the history of our national flag, which was invented
for the use of the mercantile marine, though it was very soon
appropriated by the Royal Navy for its sole use. It is very improbable
that further research will enable the gap left by the unfortunate
destruction of the early 17th century records to be filled, so that the
story of the Union Flag may be taken as being substantially complete,
but there is still room for further work upon the history of its
component crosses. It will be seen that I have been unable to find any
solid ground for the common belief that the cross of St George was
introduced as the national emblem of England by Richard I, and am of
opinion that it did not begin to attain that position until the first
years of the reign of Edward I.

The chapters on the flags used to indicate distinctions of command and
service at sea give an account of the use (now obsolete) of the Royal
Standard at sea by naval commanders-in-chief; of the history of the
flags were evolved. The history of the ensigns from their first
adoption at sea about the end of Elizabeth's reign has been set out in
some detail, but further research may bring to light more details of
interest in the years between 1574 and 1653. The causes which led to
the adoption of a red ensign as the most important British ensign and
the steps which led to its appropriation to the Mercantile Marine, and
not the Royal Navy, are stated as far as the records availed, though
here again further research is needed in the late Elizabethan and
early Stuart periods among records that may still survive in private
ownership. These chapters may, perhaps, appeal rather to the seaman
and the student of naval history than to the general reader, but it is
hoped that they may also prove of service to artists who wish to avoid
the anachronisms into which some of their brethren have been betrayed.

In order that the development of flag signals may be properly
appreciated it has been necessary, when dealing with the earlier years,
to take into account what had happened outside the narrow circuit of
British waters. The earlier matter, though here examined solely from
the point of view of the flags used, offers considerable interest to
the student of naval tactics, with which indeed the art of signalling
is inseparably connected.

The last chapter, on Ceremonial and other usages, is, from the author's
point of view, the least satisfactory. From the nature of the subject,
the official records contain very little information about it. It
is only by the slow and laborious process of examining contemporary
journals, diaries, accounts of voyages, and similar material that facts
can be found for any exhaustive treatment of these matters. Something
of this has been done, but more remains to do.

In concluding the work which has occupied a large portion of the
leisure hours of many years, it is my pleasant duty to express my
gratitude to the numerous friends whose encouragement and assistance
have enabled me to persevere in what has proved a somewhat arduous
task; especially to Sir Julian Corbett, who has read the proofs and
given me the benefit of his criticisms; to the officials of the
Pepysian Library, Public Record Office, British Museum and London
Library for the facilities afforded me; and not least to my friend Mr
Vaughan who has spared no pains in the preparation of the coloured
plates.
"""
tups = ((1, 9, 4), (4, 2, 8), (4, 8, 3), (7, 1, 5), (8, 10, 1))
d = list(map(lambda l: l.split(' '),string.split('\n')))

for tup in tups:
print(d

Out[14]:
<map at 0x7fdd95bd8828>
In [15]:


Out[15]:
[[''],
['It',
'might',
'have',
'been',
'expected',
'that',
'the',
'attempt',
'to',
'trace',
'to',
'their',
'origin'],
['in',
'the',
'past',
'the',
'institutions',
'and',
'customs',
'in',
'common',
'use',
'upon',
'the',
'sea'],
['would',
'from',
'an',
'early',
'date',
'occupy',
'the',
'attention',
'of',
'a',
'seafaring',
'people,'],
['but',
'for',
'some',
'obscure',
'reason',
'the',
'British',
'nation',
'has',
'always',
'been'],
['indifferent',
'to',
'the',
'history',
'of',
'its',
'activities',
'upon',
'that',
'element',
'on',
'which'],
['its',
'greatness',
'was',
'founded,',
'and',
'to',
'which',
'it',
'has',
'become',
'more',
'and',
'more'],
['dependent',
'for',
'its',
'daily',
'and',
'its',
'very',
'existence.',
'To',
'those',
'who'],
['are',
'alive',
'to',
'this',
'fact',
'it',
'will',
'hardly',
'come',
'as',
'a',
'surprise,',
'therefore,'],
['to',
'learn',
'that',
'the',
'first',
'sustained',
'attempt',
'at',
'a',
'detailed',
'investigation'],
['into',
'the',
'history',
'of',
'the',
'flag',
'at',
'sea',
'was',
'under',
'the',
'patronage'],
['of',
'the',
'German',
'by',
'a',
'German',
"Siegel's"],
['_Die',
'Flagge_,',
'published',
'in',
'1912,',
'was',
'the',
'first',
'book',
'to',
'deal',
'with',
'the'],
['development',
'of',
'the',
'flag',
'at',
'sea',
'in',
'a',
'scientific',
'spirit,',
'and',
'although'],
['the',
'earlier',
'chapters',
'contain',
'some',
'mistakes',
'due',
'to',
'his',
'employment',
'of'],
['translations',
'of',
'early',
'works',
'of',
'original',
'texts,',
'and',
'the',
'accounts'],
['of',
'the',
'British',
'flags',
'in',
'the',
'later',
'chapters',
'suffer',
'because',
'he',
'no'],
['access',
'to',
'original',
'records,',
'it',
'is',
'a',
'worthy',
'piece',
'of',
'work.'],
[''],
['The',
'present',
'book',
'is',
'an',
'attempt',
'to',
'remove',
'the',
'reproach',
'to',
'the',
'British'],
['nation',
'which',
'this',
'implies.',
'Its',
'plan',
'is',
'somewhat',
'different',
'from',
'that'],
['of',
'the',
'work',
'referred',
'to',
'above.',
'of',
'dealing',
'with',
'the',
'flags',
'of'],
['all',
'maritime',
'nations',
'of',
'the',
'world--a',
'that',
'(if',
'it',
'was',
'to',
'be',
'more'],
['than',
'a',
'mere',
'copying',
'or',
'compilation)',
'would',
'entail',
'much',
'work',
'in',
'foreign'],
['archives--it',
'seemed',
'more',
'profitable',
'to',
'concentrate',
'upon',
'the',
'history'],
['of',
'British',
'Naval',
'Flags,',
'for',
'researches',
'so',
'far',
'back',
'as',
'1908',
['taught',
'me',
'how',
'much',
'that',
'is',
'inaccurate',
'their',
'history',
['acceptance.',
'But',
'first',
'it',
'seemed',
'necessary',
'to',
'devote',
'some',
'time',
'and'],
['space',
'to',
'the',
'inquiry',
'into',
'the',
'origin',
'of',
'the',
'flag',
'and',
'how',
'it',
'became',
'the'],
['honoured',
'symbol',
'of',
'nationality',
'that',
'it',
'now',
'is,',
'and',
'for',
'this',
'a',
'general'],
['view',
'to',
'be',
'taken',
'in',
'order',
'that',
'a',
'firm',
'foundation',
'might',
'be',
'laid',
'for'],
['the', 'early', 'history', 'of', 'our', 'own', 'flags.'],
[''],
['In',
'the',
'first',
'chapter',
'the',
'ground',
'worked',
'over',
'by',
'Siegel',
'has',
'been'],
['solidified',
'by',
'examination',
'of',
'the',
'original',
'authorities,',
'with',
'the',
'result'],
['that',
'a',
'few',
'errors',
'have',
'been',
'detected',
'and',
'some',
'new',
'facts',
'brought',
'to'],
['light,',
'and',
'the',
'investigation',
'has',
'also',
'been',
'extended',
'further;',
'the',
'most'],
['important',
'of',
'the',
'being',
'those',
'relating',
'to',
'the',
'standards',
'in'],
['the',
'Phoenician',
'and',
'Greek',
'ships',
'of',
'war,',
'forms',
'of',
'the',
'early',
'"standard"'],
['and',
'"gonfanon,"',
'and',
'the',
'Genoese',
'Standard',
'of',
'St',
'George',
'and',
'the',
'Dragon.'],
['For',
'the',
'deduction',
'that',
'the',
'use',
'of',
'a',
'national',
'flag',
'arose',
'in',
'the',
'Italian'],
['city',
'states',
'I',
'take',
'the',
'entire',
'responsibility,',
'well',
'aware',
'that',
'further'],
['investigations',
'may',
'possibly',
'bring',
'to',
'light',
'fresh',
'facts',
'which',
'will'],
['overthrow', 'it.'],
[''],
['The',
'chapter',
'on',
'early',
'English,',
'Scottish',
'and',
'Irish',
'flags',
'serves',
'as',
'an'],
['introduction',
'to',
'the',
'history',
'of',
'our',
'national',
'flag,',
'which',
'was',
'invented'],
['for',
'the',
'use',
'of',
'the',
'mercantile',
'marine,',
'though',
'it',
'was',
'very',
'soon'],
['appropriated',
'by',
'the',
'Royal',
'Navy',
'for',
'its',
'sole',
'use.',
'It',
'is',
'very',
'improbable'],
['that',
'further',
'research',
'will',
'enable',
'the',
'gap',
'left',
'by',
'the',
'unfortunate'],
['destruction',
'of',
'the',
'early',
'17th',
'century',
'records',
'to',
'be',
'filled,',
'so',
'that',
'the'],
['story',
'of',
'the',
'Union',
'Flag',
'may',
'be',
'taken',
'as',
'being',
'substantially',
'complete,'],
['but',
'there',
'is',
'still',
'room',
'for',
'further',
'work',
'upon',
'the',
'history',
'of',
'its'],
['component',
'crosses.',
'It',
'will',
'be',
'seen',
'that',
'I',
'have',
'been',
'unable',
'to',
'find',
'any'],
['solid',
'ground',
'for',
'the',
'common',
'belief',
'that',
'the',
'cross',
'of',
'St',
'George',
'was'],
['introduced',
'as',
'the',
'national',
'emblem',
'of',
'England',
'by',
'Richard',
'I,',
'and',
'am',
'of'],
['opinion',
'that',
'it',
'did',
'not',
'begin',
'to',
'attain',
'that',
'position',
'until',
'the',
'first'],
['years', 'of', 'the', 'reign', 'of', 'Edward', 'I.'],
[''],
['The',
'chapters',
'on',
'the',
'flags',
'used',
'to',
'indicate',
'distinctions',
'of',
'command',
'and'],
['service',
'at',
'sea',
'give',
'an',
'account',
'of',
'the',
'use',
'(now',
'obsolete)',
'of',
'the',
'Royal'],
['Standard',
'at',
'sea',
'by',
'naval',
'commanders-in-chief;',
'of',
'the',
'history',
'of',
'the'],
'anchor-flag;',
'and',
'of',
'the',
'steps',
'by',
'which',
'the',
'present',
['flags',
'were',
'evolved.',
'The',
'history',
'of',
'the',
'ensigns',
'from',
'their',
'first'],
'at',
'sea',
'the',
'end',
'of',
"Elizabeth's",
'reign',
'has',
'been',
'set',
'out',
'in'],
['some',
'detail,',
'but',
'further',
'research',
'may',
'bring',
'to',
'light',
'more',
'details',
'of'],
['interest',
'in',
'the',
'years',
'between',
'1574',
'and',
'1653.',
'The',
'causes',
'which',
'led',
'to'],
['the',
'of',
'a',
'red',
'ensign',
'as',
'the',
'most',
'important',
'British',
'ensign',
'and'],
['the',
'steps',
'which',
'led',
'to',
'its',
'appropriation',
'to',
'the',
'Mercantile',
'Marine,',
'and'],
['not',
'the',
'Royal',
'Navy,',
'are',
'stated',
'as',
'far',
'as',
'the',
'records',
'availed,',
'though'],
['here',
'again',
'further',
'research',
'is',
'needed',
'in',
'the',
'late',
'Elizabethan',
'and'],
['early',
'Stuart',
'periods',
'among',
'records',
'that',
'may',
'still',
'survive',
'in',
'private'],
['ownership.',
'These',
'chapters',
'may,',
'perhaps,',
'appeal',
'rather',
'to',
'the',
'seaman'],
['and',
'the',
'student',
'of',
'naval',
'history',
'than',
'to',
'the',
'general',
'but',
'it',
'is'],
['hoped',
'that',
'they',
'may',
'also',
'prove',
'of',
'service',
'to',
'artists',
'who',
'wish',
'to',
'avoid'],
['the',
'anachronisms',
'into',
'which',
'some',
'of',
'their',
'brethren',
'have',
'been',
'betrayed.'],
[''],
['In',
'order',
'that',
'the',
'development',
'of',
'flag',
'signals',
'may',
'be',
'properly'],
['appreciated',
'it',
'has',
'been',
'necessary,',
'when',
'dealing',
'with',
'the',
'earlier',
'years,'],
['to',
'take',
'into',
'account',
'what',
'happened',
'outside',
'the',
'narrow',
'circuit',
'of'],
['British',
'waters.',
'The',
'earlier',
'matter,',
'though',
'here',
'examined',
'solely',
'from'],
['the',
'point',
'of',
'view',
'of',
'the',
'flags',
'used,',
'offers',
'considerable',
'interest',
'to'],
['the',
'student',
'of',
'naval',
'tactics,',
'with',
'which',
'indeed',
'the',
'art',
'of',
'signalling'],
['is', 'inseparably', 'connected.'],
[''],
['The',
'last',
'chapter,',
'on',
'Ceremonial',
'and',
'other',
'usages,',
'is,',
'from',
'the',
"author's"],
['point',
'of',
'view,',
'the',
'least',
'satisfactory.',
'From',
'the',
'nature',
'of',
'the',
'subject,'],
['the',
'official',
'records',
'contain',
'very',
'little',
'information',
'it.',
'It'],
['is',
'only',
'by',
'the',
'slow',
'and',
'laborious',
'process',
'of',
'examining',
'contemporary'],
['journals,',
'diaries,',
'accounts',
'of',
'voyages,',
'and',
'similar',
'material',
'that',
'facts'],
['can',
'be',
'found',
'for',
'any',
'exhaustive',
'treatment',
'of',
'these',
'matters.',
'Something'],
['of', 'this', 'has', 'been', 'done,', 'but', 'more', 'remains', 'to', 'do.'],
[''],
['In',
'concluding',
'the',
'work',
'which',
'has',
'occupied',
'a',
'large',
'portion',
'of',
'the'],
['leisure',
'hours',
'of',
'many',
'years,',
'it',
'is',
'my',
'pleasant',
'duty',
'to',
'express',
'my'],
['gratitude',
'to',
'the',
'numerous',
'friends',
'whose',
'encouragement',
'and',
'assistance'],
['have',
'enabled',
'me',
'to',
'persevere',
'in',
'what',
'has',
'proved',
'a',
'somewhat',
'arduous'],
'especially',
'to',
'Sir',
'Julian',
'Corbett,',
'who',
'has',
'the',
'proofs',
'and'],
['given',
'me',
'the',
'benefit',
'of',
'his',
'criticisms;',
'to',
'the',
'officials',
'of',
'the'],
['Pepysian',
'Library,',
'Public',
'Record',
'Office,',
'British',
'Museum',
'and',
'London'],
['Library',
'for',
'the',
'facilities',
'afforded',
'me;',
'and',
'not',
'least',
'to',
'my',
'friend',
'Mr'],
['Vaughan',
'who',
'has',
'spared',
'no',
'pains',
'in',
'the',
'preparation',
'of',
'the',
'coloured'],
['plates.'],
['']]
In [ ]: