#!/usr/bin/env python plaintext = \ '"I hesitated\r' \ 'before untying the bow\r' \ 'that bound this book together.\r' \ '\r' \ 'A black book:\r' \ ' ALBUMS\r' \ 'CA. AGRIPPA\r' \ ' Order Extra Leaves\r' \ ' By Letter and Name\r' \ '\r' \ 'A Kodak album of time-burned\r' \ 'black construction paper\r' \ '\r' \ 'The string he tied\r' \ 'Has been unravelled by years\r' \ 'and the dry weather of trunks\r' \ "Like a lady's shoestring from the First World War\r" \ 'Its metal ferrules eaten by oxygen\r' \ 'Until they resemble cigarette-ash\r' \ '\r' \ 'Inside the cover he inscribed something in soft graphite\r' \ 'Now lost\r' \ 'Then his name\r' \ 'W.F. Gibson Jr.\r' \ 'and something, comma,\r' \ '1924\r' \ '\r' \ 'Then he glued his Kodak prints down\r' \ 'And wrote under them\r' \ 'in chalk-like white pencil:\r' \ '"Papa\'s saw mill, Aug. 1919."\r' \ '\r' \ 'A flat-roofed shack\r' \ 'Against a mountain ridge\r' \ 'In the foreground are tumbled boards and offcuts\r' \ 'He must have smelled the pitch, in August\r' \ 'The sweet hot reek\r' \ 'Of the electric saw\r' \ 'Biting into decades\r' \ '\r' \ '\r' \ 'Next the spaniel Moko\r' \ '"Moko 1919"\r' \ 'Poses on small bench or table\r' \ 'Before a backyard tree\r' \ 'His coat is lustrous \r' \ 'The grass needs cutting\r' \ 'Beyond the tree,\r' \ 'In eerie Kodak clarity,\r' \ 'Are the summer backstairs of Wheeling,\r' \ ' West Virginia\r' \ "Someone's left a wooden stepladder out\r" \ '\r' \ '"Aunt Fran and [obscured]"\r' \ "Although he isn't, this gent\r" \ 'He has a "G" belt-buckle\r' \ 'A lapel-device of Masonic origin\r' \ 'A patent propelling-pencil\r' \ 'A fountain-pen\r' \ 'And the flowers they pose behind so solidly\r' \ 'Are rooted in an upright length of whitewashed\r' \ ' concrete sewer-pipe.\r' \ '\r' \ 'Daddy had a horse named Dixie\r' \ '"Ford on Dixie 1917"\r' \ 'A saddle-blanket marked with a single star\r' \ 'Corduroy jodpurs\r' \ 'A western saddle\r' \ 'And a cloth cap\r' \ 'Proud and happy\r' \ 'As any boy could be\r' \ '\r' \ '"Arthur and Ford fishing 1919"\r' \ 'Shot by an adult\r' \ '(Witness the steady hand\r' \ 'that captures the wildflowers\r' \ 'the shadows on their broad straw hats\r' \ 'reflections of a split-rail fence)\r' \ 'standing opposite them,\r' \ 'on the far side of the pond,\r' \ 'amid the snake-doctors and the mud,\r' \ 'Kodak in hand,\r' \ 'Ford Sr.?\r' \ '\r' \ 'And "Moma July, 1919"\r' \ 'strolls beside the pond,\r' \ 'in white big city shoes,\r' \ 'Purse tucked behind her,\r' \ 'While either Ford or Arthur, still straw-hatted,\r' \ 'approaches a canvas-topped touring car.\r' \ '\r' \ '"Moma and Mrs. Graham at fish hatchery 1919"\r' \ ' Moma and Mrs. G. sit atop a graceful concrete\r' \ ' arch.\r' \ '\r' \ '"Arthur on Dixie", likewise 1919,\r' \ ' rather ill at ease.\r' \ 'On the roof behind the barn, behind him,\r' \ 'can be made out this cryptic mark:\r' \ 'H.V.J.M.[?]\r' \ '\r' \ '"Papa\'s Mill 1919", my grandfather most regal amid a wrack of\r' \ 'cut lumber,\r' \ 'might as easily be the record\r' \ 'of some later demolition, and\r' \ 'His cotton sleeves are rolled\r' \ 'to but not past the elbow,\r' \ 'striped, with a white neckband\r' \ 'for the attachment of a collar.\r' \ 'Behind him stands a cone of sawdust some thirty feet in height.\r' \ '(How that feels to tumble down,\r' \ 'or smells when it is wet)\r' \ '\r' \ '\r' \ ' II.\r' \ '\r' \ 'The mechanism: stamped black tin,\r' \ 'Leatherette over cardboard, bits of boxwood,\r' \ 'A lens\r' \ 'The shutter falls\r' \ 'Forever\r' \ 'Dividing that from this.\r' \ '\r' \ 'Now in high-ceiling bedrooms,\r' \ 'unoccupied, unvisited,\r' \ 'in the bottom drawers of veneered bureaus\r' \ 'in cool chemical darkness curl commemorative\r' \ "montages of the country's World War dead,\r" \ '\r' \ 'just as I myself discovered\r' \ 'one other summer in an attic trunk,\r' \ "and beneath that every boy's best treasure\r" \ 'of tarnished actual ammunition\r' \ 'real little bits of war\r' \ 'but also\r' \ 'the mechanism\r' \ 'itself.\r' \ '\r' \ 'The blued finish of firearms\r' \ 'is a process, controlled, derived from common\r' \ ' rust, but there\r' \ 'under so rare and uncommon a patina\r' \ 'that many years untouched\r' \ 'until I took it up\r' \ 'and turning, entranced, down the unpainted\r' \ ' stair,\r' \ 'to the hallway where I swear\r' \ 'I never heard the first shot.\r' \ '\r' \ 'The copper-jacketed slug recovered\r' \ "from the bathroom's cardboard cylinder of\r" \ " Morton's Salt\r" \ 'was undeformed\r' \ 'save for the faint bright marks of lands\r' \ ' and grooves\r' \ 'so hot, stilled energy,\r' \ 'it blistered my hand.\r' \ '\r' \ 'The gun lay on the dusty carpet.\r' \ 'Returning in utter awe I took it so carefully up\r' \ 'That the second shot, equally unintended,\r' \ ' notched the hardwood bannister and brought\r' \ ' a strange bright smell of ancient sap to life\r' \ ' in a beam of dusty sunlight.\r' \ ' Absolutely alone\r' \ ' in awareness of the mechanism.\r' \ '\r' \ 'Like the first time you put your mouth\r' \ ' on a woman.\r' \ '\r' \ '\r' \ ' III.\r' \ '\r' \ '"Ice Gorge at Wheeling\r' \ ' 1917"\r' \ '\r' \ 'Iron bridge in the distance,\r' \ 'Beyond it a city.\r' \ 'Hotels where pimps went about their business\r' \ 'on the sidewalks of a lost world.\r' \ 'But the foreground is in focus,\r' \ "this corner of carpenter's Gothic,\r" \ 'these backyards running down to the freeze.\r' \ '\r' \ '"Steamboat on Ohio River",\r' \ 'its smoke foul and dark,\r' \ 'its year unknown,\r' \ 'beyond it the far bank\r' \ 'overgrown with factories.\r' \ '\r' \ '"Our Wytheville\r' \ 'House Sept 1921"\r' \ '\r' \ 'They have moved down from Wheeling and my father wears his\r' \ 'city clothes. Main Street is unpaved and an electric streetlamp is\r' \ 'slung high in the frame, centered above the tracked dust on a\r' \ 'slack wire, suggesting the way it might pitch in a strong wind,\r' \ 'the shadows that might throw.\r' \ '\r' \ 'The house is heavy, unattractive, sheathed in stucco, not native\r' \ 'to the region. My grandfather, who sold supplies to contractors,\r' \ 'was prone to modern materials, which he used with\r' \ "wholesaler's enthusiasm. In 1921 he replaced the section of brick\r" \ 'sidewalk in front of his house with the broad smooth slab of poured\r' \ 'concrete, signing this improvement with a flourish, "W.F.\r' \ 'Gibson 1921". He believed in concrete and plywood\r' \ 'particularly. Seventy years later his signature remains, the slab\r' \ 'floating perfectly level and charmless between mossy stretches of\r' \ 'sweet uneven brick that knew the iron shoes of Yankee horses.\r' \ '\r' \ '"Mama Jan. 1922" has come out to sweep the concrete with a \r' \ 'broom. Her boots are fastened with buttons requiring a special instrument.\r' \ '\r' \ 'Ice gorge again, the Ohio, 1917. The mechanism closes. A\r' \ 'torn clipping offers a 1957 DeSOTO FIREDOME, 4-door Sedan,\r' \ 'torqueflite radio, heater and power steering and brakes, new\r' \ 'w.s.w. premium tires. One owner. $1,595.\r' \ '\r' \ '\r' \ ' IV.\r' \ '\r' \ 'He made it to the age of torqueflite radio\r' \ 'but not much past that, and never in that town.\r' \ 'That was mine to know, Main Street lined with\r' \ 'Rocket Eighty-eights,\r' \ 'the dimestore floored with wooden planks\r' \ 'pies under plastic in the Soda Shop,\r' \ 'and the mystery untold, the other thing,\r' \ 'sensed in the creaking of a sign after midnight\r' \ 'when nobody else was there.\r' \ '\r' \ 'In the talc-fine dust beneath the platform of the\r' \ ' Norfolk & Western\r' \ 'lay indian-head pennies undisturbed since\r' \ ' the dawn of man.\r' \ '\r' \ 'In the banks and courthouse, a fossil time\r' \ ' prevailed, limestone centuries.\r' \ '\r' \ 'When I went up to Toronto\r' \ ' in the draft,\r' \ 'my Local Board was there on Main Street,\r' \ 'above a store that bought and sold pistols.\r' \ "I'd once traded that man a derringer for a\r" \ ' Walther P-38.\r' \ 'The pistols were in the window\r' \ 'behind an amber roller-blind\r' \ ' like sunglasses.\r' \ 'I was seventeen or so but basically I guess\r' \ 'you just had to be a white boy.\r' \ "I'd hike out to a shale pit and run\r" \ 'ten dollars worth of 9mm\r' \ 'through it, so worn you hardly\r' \ 'had to pull the trigger.\r' \ 'Bored, tried shooting \r' \ 'down into a distant stream but\r' \ 'one of them came back at me\r' \ 'off a round of river rock\r' \ 'clipping walnut twigs from a branch\r' \ 'two feet above my head.\r' \ 'So that I remembered the mechanism.\r' \ '\r' \ '\r' \ ' V.\r' \ '\r' \ 'In the all night bus station\r' \ 'they sold scrambled eggs to state troopers\r' \ 'the long skinny clasp-knives called fruit knives\r' \ 'which were pearl handled watermelon-slicers\r' \ 'and hillbilly novelties in brown varnished wood\r' \ 'which were made in Japan.\r' \ '\r' \ "First I'd be sent there at night only\r" \ "if Mom's carton of Camels ran out,\r" \ 'but gradually I came to value\r' \ 'the submarine light, the alien reek\r' \ 'of the long human haul, the strangers\r' \ 'straight down from Port Authority\r' \ 'headed for Nashville, Memphis, Miami.\r' \ 'Sometimes the Sheriff watched them get off\r' \ 'making sure they got back on.\r' \ '\r' \ 'When the colored restroom\r' \ 'was no longer required\r' \ 'they knocked open the cinderblock\r' \ 'and extended the magazine rack\r' \ 'to new dimensions,\r' \ 'a cool fluorescent cave of dreams\r' \ 'smelling faintly and forever of disinfectant,\r' \ 'perhaps as well of the travelled fears\r' \ 'of those dark uncounted others who,\r' \ 'moving as through contours of hot iron,\r' \ 'were made thus to dance\r' \ 'or not to dance\r' \ 'as the law saw fit.\r' \ '\r' \ 'There it was that I was marked out as a writer, \r' \ 'having discovered in that alcove\r' \ 'copies of certain magazines\r' \ 'esoteric and precious, and, yes,\r' \ 'I knew then, knew utterly,\r' \ 'the deal done in my heart forever,\r' \ 'though how I knew not,\r' \ 'nor ever have.\r' \ '\r' \ 'Walking home\r' \ 'through all the streets unmoving\r' \ 'so quiet I could hear the timers of the traffic lights a block away:\r' \ ' the mechanism.\r' \ 'Nobody else, just the silence\r' \ ' spreading out\r' \ 'to where the long trucks groaned\r' \ ' on the highway\r' \ 'their vast brute souls in want.\r' \ '\r' \ '\r' \ ' VI.\r' \ '\r' \ 'There must have been a true last time\r' \ "I saw the station but I don't remember\r" \ 'I remember the stiff black horsehide coat\r' \ 'gift in Tucson of a kid named Natkin\r' \ 'I remember the cold\r' \ 'I remember the Army duffle\r' \ 'that was lost and the black man in Buffalo\r' \ 'trying to sell me a fine diamond ring,\r' \ 'and in the coffee shop in Washington\r' \ "I'd eavesdropped on a man wearing a black tie\r" \ 'embroidered with red roses\r' \ 'that I have looked for ever since.\r' \ '\r' \ 'They must have asked me something\r' \ 'at the border\r' \ 'I was admitted\r' \ 'somehow\r' \ 'and behind me swung the stamped tin shutter\r' \ 'across the very sky\r' \ 'and I went free\r' \ 'to find myself\r' \ 'mazed in Victorian brick\r' \ 'amid sweet tea with milk\r' \ 'and smoke from a cigarette called a Black Cat\r' \ 'and every unknown brand of chocolate\r' \ 'and girls with blunt-cut bangs\r' \ 'not even Americans\r' \ 'looking down from high narrow windows\r' \ 'on the melting snow\r' \ 'of the city undreamed\r' \ 'and on the revealed grace\r' \ 'of the mechanism;\r' \ 'no round trip.\r' \ '\r' \ 'They tore down the bus station\r' \ "there's chainlink there\r" \ 'no buses stop at all\r' \ "and I'm walking through Chiyoda-ku\r" \ 'in a typhoon\r' \ 'the fine rain horizontal\r' \ "umbrella everted in the storm's Pacific breath\r" \ 'tonight red lanterns are battered,\r' \ '\r' \ 'laughing,\r' \ 'in the mechanism. ' # First permutation. Generated sequence is: # [ 5, 0, 3, 6, 1, 4, 7, 2 ] InvPermutation_A = [ (((pos * 3) + 5) % 8) for pos in range(8) ] # # Second permutation. Generated sequence is: # [ 6, 3, 0, 5, 2, 7, 4, 1 ] InvPermutation_B = [ (((pos * 5) + 6) % 8) for pos in range(8) ] def Permute(byte, table): val = 0 for pos in range(8): if byte & (1 << pos): val |= (1 << table[pos]) return val def EncryptBlock(block): if len(block) != 3: raise ValueError("Bad block size. Must be three bytes") # Convert bytes to numbers (d, e, f) = [ ord(byte) for byte in block ] # Inverse permute every byte d = Permute(d, InvPermutation_B) e = Permute(e, InvPermutation_B) f = Permute(f, InvPermutation_B) # Pack the three 8-bit bytes into two 12-bit messages plaintext_msg1 = ((e & 0x0f) << 8) | ((d & 0xff) ) plaintext_msg2 = ((f & 0xff) << 4) | ((e & 0xf0) >> 4) # RSA encrypt the two 12-bit messages ciphertext_msg1 = pow(plaintext_msg1, 3491, 4097) ciphertext_msg2 = pow(plaintext_msg2, 3491, 4097) # Unpack the two 12-bit messages into three 8-bit bytes a = ((ciphertext_msg1 & 0xff) ) b = ((ciphertext_msg1 & 0xf00) >> 8) | ((ciphertext_msg2 & 0x00f) << 4) c = ((ciphertext_msg2 & 0xff0) >> 4) # Inverse permute the middle byte b = Permute(b, InvPermutation_A) # Convert the bytes into characters return ''.join([chr(c) for c in (a, b, c)]) ciphertext = '' for i in range(0,len(plaintext),3): block = plaintext[i:i+3] ciphertext += EncryptBlock(block) # Print the ciphertext as hexadecimal characters because it contains # unprintable characters. print ciphertext.encode('hex')