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CZHAGDQGJMMZARMUVFGJXKDIKQGYYFYEVVSYZWXDQMHNMMZGYVDSKWSHQPSNOGYNUOBFVPAKIEDEIRCEBFDCYYEMLZIGOEVLFEVLVXGXXJVTKGTPGDMLAFAJZGAQGYFVQTFVQARWLAKXCEGX"
def stringShift(str,n):
   slen=len(str)
   return str[n:slen+1]+str[0:n]

def countCoincidences(str1,str2):
   slen=len(str1)
   coin=0
   for j in [0..slen-1]:
        if str1[j]==str2[j]:
            coin=coin+1
   return coin

def breakStringMod(str,m):
    cts=['']*m
    slen=len(str)
    for i in range(slen):
       cts[i%m]=cts[i%m]+str[i]
    return cts

def countLetterFrequencies(str):
    alph='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    for i in alph:
       print i, str.count(i)
stringShift("EXAMPLE",3)
'MPLEEXA'
countCoincidences("DAD","MAD")
2
#Examples of these functions:
stringShift("EXAMPLE",2)
breakStringMod("HIMYNAMEISDRMCNEW",5)
['HADE', 'IMRW', 'MEM', 'YIC', 'NSN']
countCoincidences("AASQ","HAMQ")
countLetterFrequencies("AAABBC")
A 3 B 2 C 1 D 0 E 0 F 0 G 0 H 0 I 0 J 0 K 0 L 0 M 0 N 0 O 0 P 0 Q 0 R 0 S 0 T 0 U 0 V 0 W 0 X 0 Y 0 Z 0
for i in [1..25]:
    shiftedCiphertext=stringShift(ciphertext,i)
    print i, countCoincidences(ciphertext,shiftedCiphertext)
1 457 2 345 3 403 4 382 5 340 6 418 7 625 8 435 9 397 10 393 11 429 12 356 13 426 14 608 15 404 16 377 17 388 18 392 19 313 20 419 21 636 22 388 23 362 24 366 25 386
#Guess key length is 7
strings=breakStringMod(ciphertext,7)
countLetterFrequencies(strings[6])
A 121 B 0 C 10 D 60 E 39 F 100 G 123 H 19 I 0 J 74 K 87 L 119 M 35 N 8 O 30 P 2 Q 27 R 0 S 135 T 26 U 47 V 47 W 140 X 24 Y 29 Z 78
#We use this to decipher the text:
alphabet = AlphabeticStrings()
ciphertextEncoded = alphabet.encoding(ciphertext)
system = VigenereCryptosystem(alphabet,7)
key = alphabet("SECRETS")

plaintext = system.deciphering(key, ciphertextEncoded)
plaintext
MRSHERLOCKHOLMESWHOWASUSUALLYVERYLATEINTHEMORNINGSSAVEUPONTHOSENOTINFREQUENTOCCASIONSWHENHESTAYEDUPALLNIGHTWASSEATEDATTHEBREAKFASTTABLEISTOODUPONTHEHEARTHRUGANDPICKEDUPTHESTICKWHICHOURVISITORHADLEFTBEHINDHIMTHENIGHTBEFOREITWASAFINETHICKPIECEOFWOODBULBOUSHEADEDOFTHESORTWHICHISKNOWNASAPENANGLAWYERJUSTUNDERTHEHEADWASABROADSILVERBANDNEARLYANINCHACROSSTOJAMESMORTIMERMRCSFROMHISFRIENDSOFTHECCHWASENGRAVEDUPONITWITHTHEDATEITWASJUSTSUCHASTICKASTHEOLDFASHIONEDFAMILYPRACTITIONERUSEDTOCARRYDIGNIFIEDSOLIDANDREASSURINGWELLWATSONWHATDOYOUMAKEOFITHOLMESWASSITTINGWITHHISBACKTOMEANDIHADGIVENHIMNOSIGNOFMYOCCUPATIONHOWDIDYOUKNOWWHATIWASDOINGIBELIEVEYOUHAVEEYESINTHEBACKOFYOURHEADIHAVEATLEASTAWELLPOLISHEDSILVERPLATEDCOFFEEPOTINFRONTOFMESAIDHEBUTTELLMEWATSONWHATDOYOUMAKEOFOURVISITORSSTICKSINCEWEHAVEBEENSOUNFORTUNATEASTOMISSHIMANDHAVENONOTIONOFHISERRANDTHISACCIDENTALSOUVENIRBECOMESOFIMPORTANCELETMEHEARYOURECONSTRUCTTHEMANBYANEXAMINATIONOFITITHINKSAIDIFOLLOWINGSOFARASICOULDTHEMETHODSOFMYCOMPANIONTHATDRMORTIMERISASUCCESSFULELDERLYMEDICALMANWELLESTEEMEDSINCETHOSEWHOKNOWHIMGIVEHIMTHISMARKOFTHEIRAPPRECIATIONGOODSAIDHOLMESEXCELLENTITHINKALSOTHATTHEPROBABILITYISINFAVOUROFHISBEINGACOUNTRYPRACTITIONERWHODOESAGREATDEALOFHISVISITINGONFOOTWHYSOBECAUSETHISSTICKTHOUGHORIGINALLYAVERYHANDSOMEONEHASBEENSOKNOCKEDABOUTTHATICANHARDLYIMAGINEATOWNPRACTITIONERCARRYINGITTHETHICKIRONFERRULEISWORNDOWNSOITISEVIDENTTHATHEHASDONEAGREATAMOUNTOFWALKINGWITHITPERFECTLYSOUNDSAIDHOLMESANDTHENAGAINTHEREISTHEFRIENDSOFTHECCHISHOULDGUESSTHATTOBETHESOMETHINGHUNTTHELOCALHUNTTOWHOSEMEMBERSHEHASPOSSIBLYGIVENSOMESURGICALASSISTANCEANDWHICHHASMADEHIMASMALLPRESENTATIONINRETURNREALLYWATSONYOUEXCELYOURSELFSAIDHOLMESPUSHINGBACKHISCHAIRANDLIGHTINGACIGARETTEIAMBOUNDTOSAYTHATINALLTHEACCOUNTSWHICHYOUHAVEBEENSOGOODASTOGIVEOFMYOWNSMALLACHIEVEMENTSYOUHAVEHABITUALLYUNDERRATEDYOUROWNABILITIESITMAYBETHATYOUARENOTYOURSELFLUMINOUSBUTYOUAREACONDUCTOROFLIGHTSOMEPEOPLEWITHOUTPOSSESSINGGENIUSHAVEAREMARKABLEPOWEROFSTIMULATINGITICONFESSMYDEARFELLOWTHATIAMVERYMUCHINYOURDEBTHEHADNEVERSAIDASMUCHBEFOREANDIMUSTADMITTHATHISWORDSGAVEMEKEENPLEASUREFORIHADOFTENBEENPIQUEDBYHISINDIFFERENCETOMYADMIRATIONANDTOTHEATTEMPTSWHICHIHADMADETOGIVEPUBLICITYTOHISMETHODSIWASPROUDTOOTOTHINKTHATIHADSOFARMASTEREDHISSYSTEMASTOAPPLYITINAWAYWHICHEARNEDHISAPPROVALHENOWTOOKTHESTICKFROMMYHANDSANDEXAMINEDITFORAFEWMINUTESWITHHISNAKEDEYESTHENWITHANEXPRESSIONOFINTERESTHELAIDDOWNHISCIGARETTEANDCARRYINGTHECANETOTHEWINDOWHELOOKEDOVERITAGAINWITHACONVEXLENSINTERESTINGTHOUGHELEMENTARYSAIDHEASHERETURNEDTOHISFAVOURITECORNEROFTHESETTEETHEREARECERTAINLYONEORTWOINDICATIONSUPONTHESTICKITGIVESUSTHEBASISFORSEVERALDEDUCTIONSHASANYTHINGESCAPEDMEIASKEDWITHSOMESELFIMPORTANCEITRUSTTHATTHEREISNOTHINGOFCONSEQUENCEWHICHIHAVEOVERLOOKEDIAMAFRAIDMYDEARWATSONTHATMOSTOFYOURCONCLUSIONSWEREERRONEOUSWHENISAIDTHATYOUSTIMULATEDMEIMEANTTOBEFRANKTHATINNOTINGYOURFALLACIESIWASOCCASIONALLYGUIDEDTOWARDSTHETRUTHNOTTHATYOUAREENTIRELYWRONGINTHISINSTANCETHEMANISCERTAINLYACOUNTRYPRACTITIONERANDHEWALKSAGOODDEALTHENIWASRIGHTTOTHATEXTENTBUTTHATWASALLNONOMYDEARWATSONNOTALLBYNOMEANSALLIWOULDSUGGESTFOREXAMPLETHATAPRESENTATIONTOADOCTORISMORELIKELYTOCOMEFROMAHOSPITALTHANFROMAHUNTANDTHATWHENTHEINITIALSCCAREPLACEDBEFORETHATHOSPITALTHEWORDSCHARINGCROSSVERYNATURALLYSUGGESTTHEMSELVESYOUMAYBERIGHTTHEPROBABILITYLIESINTHATDIRECTIONANDIFWETAKETHISASAWORKINGHYPOTHESISWEHAVEAFRESHBASISFROMWHICHTOSTARTOURCONSTRUCTIONOFTHISUNKNOWNVISITORWELLTHENSUPPOSINGTHATCCHDOESSTANDFORCHARINGCROSSHOSPITALWHATFURTHERINFERENCESMAYWEDRAWDONONESUGGESTTHEMSELVESYOUKNOWMYMETHODSAPPLYTHEMICANONLYTHINKOFTHEOBVIOUSCONCLUSIONTHATTHEMANHASPRACTISEDINTOWNBEFOREGOINGTOTHECOUNTRYITHINKTHATWEMIGHTVENTUREALITTLEFARTHERTHANTHISLOOKATITINTHISLIGHTONWHATOCCASIONWOULDITBEMOSTPROBABLETHATSUCHAPRESENTATIONWOULDBEMADEWHENWOULDHISFRIENDSUNITETOGIVEHIMAPLEDGEOFTHEIRGOODWILLOBVIOUSLYATTHEMOMENTWHENDRMORTIMERWITHDREWFROMTHESERVICEOFTHEHOSPITALINORDERTOSTARTAPRACTICEFORHIMSELFWEKNOWTHEREHASBEENAPRESENTATIONWEBELIEVETHEREHASBEENACHANGEFROMATOWNHOSPITALTOACOUNTRYPRACTICEISITTHENSTRETCHINGOURINFERENCETOOFARTOSAYTHATTHEPRESENTATIONWASONTHEOCCASIONOFTHECHANGEITCERTAINLYSEEMSPROBABLENOWYOUWILLOBSERVETHATHECOULDNOTHAVEBEENONTHESTAFFOFTHEHOSPITALSINCEONLYAMANWELLESTABLISHEDINALONDONPRACTICECOULDHOLDSUCHAPOSITIONANDSUCHAONEWOULDNOTDRIFTINTOTHECOUNTRYWHATWASHETHENIFHEWASINTHEHOSPITALANDYETNOTONTHESTAFFHECOULDONLYHAVEBEENAHOUSESURGEONORAHOUSEPHYSICIANLITTLEMORETHANASENIORSTUDENTANDHELEFTFIVEYEARSAGOTHEDATEISONTHESTICKSOYOURGRAVEMIDDLEAGEDFAMILYPRACTITIONERVANISHESINTOTHINAIRMYDEARWATSONANDTHEREEMERGESAYOUNGFELLOWUNDERTHIRTYAMIABLEUNAMBITIOUSABSENTMINDEDANDTHEPOSSESSOROFAFAVOURITEDOGWHICHISHOULDDESCRIBEROUGHLYASBEINGLARGERTHANATERRIERANDSMALLERTHANAMASTIFFILAUGHEDINCREDULOUSLYASSHERLOCKHOLMESLEANEDBACKINHISSETTEEANDBLEWLITTLEWAVERINGRINGSOFSMOKEUPTOTHECEILINGASTOTHELATTERPARTIHAVENOMEANSOFCHECKINGYOUSAIDIBUTATLEASTITISNOTDIFFICULTTOFINDOUTAFEWPARTICULARSABOUTTHEMANSAGEANDPROFESSIONALCAREERFROMMYSMALLMEDICALSHELFITOOKDOWNTHEMEDICALDIRECTORYANDTURNEDUPTHENAMETHEREWERESEVERALMORTIMERSBUTONLYONEWHOCOULDBEOURVISITORIREADHISRECORDALOUDMORTIMERJAMESMRCSGRIMPENDARTMOORDEVONHOUSESURGEONFROMTOATCHARINGCROSSHOSPITALWINNEROFTHEJACKSONPRIZEFORCOMPARATIVEPATHOLOGYWITHESSAYENTITLEDISDISEASEAREVERSIONCORRESPONDINGMEMBEROFTHESWEDISHPATHOLOGICALSOCIETYAUTHOROFSOMEFREAKSOFATAVISMLANCETDOWEPROGRESSJOURNALOFPSYCHOLOGYMARCHMEDICALOFFICERFORTHEPARISHESOFGRIMPENTHORSLEYANDHIGHBARROWNOMENTIONOFTHATLOCALHUNTWATSONSAIDHOLMESWITHAMISCHIEVOUSSMILEBUTACOUNTRYDOCTORASYOUVERYASTUTELYOBSERVEDITHINKTHATIAMFAIRLYJUSTIFIEDINMYINFERENCESASTOTHEADJECTIVESISAIDIFIREMEMBERRIGHTAMIABLEUNAMBITIOUSANDABSENTMINDEDITISMYEXPERIENCETHATITISONLYANAMIABLEMANINTHISWORLDWHORECEIVESTESTIMONIALSONLYANUNAMBITIOUSONEWHOABANDONSALONDONCAREERFORTHECOUNTRYANDONLYANABSENTMINDEDONEWHOLEAVESHISSTICKANDNOTHISVISITINGCARDAFTERWAITINGANHOURINYOURROOMANDTHEDOGHASBEENINTHEHABITOFCARRYINGTHISSTICKBEHINDHISMASTERBEINGAHEAVYSTICKTHEDOGHASHELDITTIGHTLYBYTHEMIDDLEANDTHEMARKSOFHISTEETHAREVERYPLAINLYVISIBLETHEDOGSJAWASSHOWNINTHESPACEBETWEENTHESEMARKSISTOOBROADINMYOPINIONFORATERRIERANDNOTBROADENOUGHFORAMASTIFFITMAYHAVEBEENYESBYJOVEITISACURLYHAIREDSPANIELHEHADRISENANDPACEDTHEROOMASHESPOKENOWHEHALTEDINTHERECESSOFTHEWINDOWTHEREWASSUCHARINGOFCONVICTIONINHISVOICETHATIGLANCEDUPINSURPRISEMYDEARFELLOWHOWCANYOUPOSSIBLYBESOSUREOFTHATFORTHEVERYSIMPLEREASONTHATISEETHEDOGHIMSELFONOURVERYDOORSTEPANDTHEREISTHERINGOFITSOWNERDONTMOVEIBEGYOUWATSONHEISAPROFESSIONALBROTHEROFYOURSANDYOURPRESENCEMAYBEOFASSISTANCETOMENOWISTHEDRAMATICMOMENTOFFATEWATSONWHENYOUHEARASTEPUPONTHESTAIRWHICHISWALKINGINTOYOURLIFEANDYOUKNOWNOTWHETHERFORGOODORILLWHATDOESDRJAMESMORTIMERTHEMANOFSCIENCEASKOFSHERLOCKHOLMESTHESPECIALISTINCRIMECOMEINTHEAPPEARANCEOFOURVISITORWASASURPRISETOMESINCEIHADEXPECTEDATYPICALCOUNTRYPRACTITIONERHEWASAVERYTALLTHINMANWITHALONGNOSELIKEABEAKWHICHSHOTOUTBETWEENTWOKEENGREYEYESSETCLOSELYTOGETHERANDSPARKLINGBRIGHTLYFROMBEHINDAPAIROFGOLDRIMMEDGLASSESHEWASCLADINAPROFESSIONALBUTRATHERSLOVENLYFASHIONFORHISFROCKCOATWASDINGYANDHISTROUSERSFRAYEDTHOUGHYOUNGHISLONGBACKWASALREADYBOWEDANDHEWALKEDWITHAFORWARDTHRUSTOFHISHEADANDAGENERALAIROFPEERINGBENEVOLENCEASHEENTEREDHISEYESFELLUPONTHESTICKINHOLMESSHANDANDHERANTOWARDSITWITHANEXCLAMATIONOFJOYIAMSOVERYGLADSAIDHEIWASNOTSUREWHETHERIHADLEFTITHEREORINTHESHIPPINGOFFICEIWOULDNOTLOSETHATSTICKFORTHEWORLDAPRESENTATIONISEESAIDHOLMESYESSIRFROMCHARINGCROSSHOSPITALFROMONEORTWOFRIENDSTHEREONTHEOCCASIONOFMYMARRIAGEDEARDEARTHATSBADSAIDHOLMESSHAKINGHISHEADDRMORTIMERBLINKEDTHROUGHHISGLASSESINMILDASTONISHMENTWHYWASITBADONLYTHATYOUHAVEDISARRANGEDOURLITTLEDEDUCTIONSYOURMARRIAGEYOUSAYYESSIRIMARRIEDANDSOLEFTTHEHOSPITALANDWITHITALLHOPESOFACONSULTINGPRACTICEITWASNECESSARYTOMAKEAHOMEOFMYOWNCOMECOMEWEARENOTSOFARWRONGAFTERALLSAIDHOLMESANDNOWDRJAMESMORTIMERMISTERSIRMISTERAHUMBLEMRCSANDAMANOFPRECISEMINDEVIDENTLYADABBLERINSCIENCEMRHOLMESAPICKERUPOFSHELLSONTHESHORESOFTHEGREATUNKNOWNOCEANIPRESUMETHATITISMRSHERLOCKHOLMESWHOMIAMADDRESSINGANDNOTNOTHISISMYFRIENDDRWATSONGLADTOMEETYOUSIRIHAVEHEARDYOURNAMEMENTIONEDINCONNECTIONWITHTHATOFYOURFRIENDYOUINTERESTMEVERYMUCHMRHOLMESIHADHARDLYEXPECTEDSODOLICHOCEPHALICASKULLORSUCHWELLMARKEDSUPRAORBITALDEVELOPMENTWOULDYOUHAVEANYOBJECTIONTOMYRUNNINGMYFINGERALONGYOURPARIETALFISSUREACASTOFYOURSKULLSIRUNTILTHEORIGINALISAVAILABLEWOULDBEANORNAMENTTOANYANTHROPOLOGICALMUSEUMITISNOTMYINTENTIONTOBEFULSOMEBUTICONFESSTHATICOVETYOURSKULLSHERLOCKHOLMESWAVEDOURSTRANGEVISITORINTOACHAIRYOUAREANENTHUSIASTINYOURLINEOFTHOUGHTIPERCEIVESIRASIAMINMINESAIDHEIOBSERVEFROMYOURFOREFINGERTHATYOUMAKEYOUROWNCIGARETTESHAVENOHESITATIONINLIGHTINGONETHEMANDREWOUTPAPERANDTOBACCOANDTWIRLEDTHEONEUPINTHEOTHERWITHSURPRISINGDEXTERITYHEHADLONGQUIVERINGFINGERSASAGILEANDRESTLESSASTHEANTENNAEOFANINSECTHOLMESWASSILENTBUTHISLITTLEDARTINGGLANCESSHOWEDMETHEINTERESTWHICHHETOOKINOURCURIOUSCOMPANIONIPRESUMESIRSAIDHEATLASTTHATITWASNOTMERELYFORTHEPURPOSEOFEXAMININGMYSKULLTHATYOUHAVEDONEMETHEHONOURTOCALLHERELASTNIGHTANDAGAINTODAYNOSIRNOTHOUGHIAMHAPPYTOHAVEHADTHEOPPORTUNITYOFDOINGTHATASWELLICAMETOYOUMRHOLMESBECAUSEIRECOGNISETHATIAMMYSELFANUNPRACTICALMANANDBECAUSEIAMSUDDENLYCONFRONTEDWITHAMOSTSERIOUSANDEXTRAORDINARYPROBLEMRECOGNISINGASIDOTHATYOUARETHESECONDHIGHESTEXPERTINEUROPEINDEEDSIRMAYIINQUIREWHOHASTHEHONOURTOBETHEFIRSTASKEDHOLMESWITHSOMEASPERITYTOTHEMANOFPRECISELYSCIENTIFICMINDTHEWORKOFMONSIEURBERTILLONMUSTALWAYSAPPEALSTRONGLYTHENHADYOUNOTBETTERCONSULTHIMISAIDSIRTOTHEPRECISELYSCIENTIFICMINDBUTASAPRACTICALMANOFAFFAIRSITISACKNOWLEDGEDTHATYOUSTANDALONEITRUSTSIRTHATIHAVENOTINADVERTENTLYJUSTALITTLESAIDHOLMESITHINKDRMORTIMERYOUWOULDDOWISELYIFWITHOUTMOREADOYOUWOULDKINDLYTELLMEPLAINLYWHATTHEEXACTNATUREOFTHEPROBLEMISINWHICHYOUDEMANDMYASSISTANCE