home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pytexdoc / ext / lib / lib2 / rotor / tex
LaTeX Document  |  1996-11-08  |  4.4 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000010| 6e 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n Module| \sectco|
|00000020| 64 65 7b 72 6f 74 6f 72 | 7d 7d 0a 5c 62 69 6d 6f |de{rotor|}}.\bimo|
|00000030| 64 69 6e 64 65 78 7b 72 | 6f 74 6f 72 7d 0a 0a 54 |dindex{r|otor}..T|
|00000040| 68 69 73 20 6d 6f 64 75 | 6c 65 20 69 6d 70 6c 65 |his modu|le imple|
|00000050| 6d 65 6e 74 73 20 61 20 | 72 6f 74 6f 72 2d 62 61 |ments a |rotor-ba|
|00000060| 73 65 64 20 65 6e 63 72 | 79 70 74 69 6f 6e 20 61 |sed encr|yption a|
|00000070| 6c 67 6f 72 69 74 68 6d | 2c 20 63 6f 6e 74 72 69 |lgorithm|, contri|
|00000080| 62 75 74 65 64 20 62 79 | 0a 4c 61 6e 63 65 20 45 |buted by|.Lance E|
|00000090| 6c 6c 69 6e 67 68 6f 75 | 73 65 2e 20 20 54 68 65 |llinghou|se. The|
|000000a0| 20 64 65 73 69 67 6e 20 | 69 73 20 64 65 72 69 76 | design |is deriv|
|000000b0| 65 64 20 66 72 6f 6d 20 | 74 68 65 20 45 6e 69 67 |ed from |the Enig|
|000000c0| 6d 61 20 64 65 76 69 63 | 65 2c 20 61 20 6d 61 63 |ma devic|e, a mac|
|000000d0| 68 69 6e 65 0a 75 73 65 | 64 20 64 75 72 69 6e 67 |hine.use|d during|
|000000e0| 20 57 6f 72 6c 64 20 57 | 61 72 20 49 49 20 74 6f | World W|ar II to|
|000000f0| 20 65 6e 63 69 70 68 65 | 72 20 6d 65 73 73 61 67 | enciphe|r messag|
|00000100| 65 73 2e 20 20 41 20 72 | 6f 74 6f 72 20 69 73 20 |es. A r|otor is |
|00000110| 73 69 6d 70 6c 79 20 61 | 0a 70 65 72 6d 75 74 61 |simply a|.permuta|
|00000120| 74 69 6f 6e 2e 20 20 46 | 6f 72 20 65 78 61 6d 70 |tion. F|or examp|
|00000130| 6c 65 2c 20 69 66 20 74 | 68 65 20 63 68 61 72 61 |le, if t|he chara|
|00000140| 63 74 65 72 20 60 41 27 | 20 69 73 20 74 68 65 20 |cter `A'| is the |
|00000150| 6f 72 69 67 69 6e 20 6f | 66 20 74 68 65 20 72 6f |origin o|f the ro|
|00000160| 74 6f 72 2c 0a 74 68 65 | 6e 20 61 20 67 69 76 65 |tor,.the|n a give|
|00000170| 6e 20 72 6f 74 6f 72 20 | 6d 69 67 68 74 20 6d 61 |n rotor |might ma|
|00000180| 70 20 60 41 27 20 74 6f | 20 60 4c 27 2c 20 60 42 |p `A' to| `L', `B|
|00000190| 27 20 74 6f 20 60 5a 27 | 2c 20 60 43 27 20 74 6f |' to `Z'|, `C' to|
|000001a0| 20 60 47 27 2c 20 61 6e | 64 20 73 6f 20 6f 6e 2e | `G', an|d so on.|
|000001b0| 0a 54 6f 20 65 6e 63 72 | 79 70 74 2c 20 77 65 20 |.To encr|ypt, we |
|000001c0| 63 68 6f 6f 73 65 20 73 | 65 76 65 72 61 6c 20 64 |choose s|everal d|
|000001d0| 69 66 66 65 72 65 6e 74 | 20 72 6f 74 6f 72 73 2c |ifferent| rotors,|
|000001e0| 20 61 6e 64 20 73 65 74 | 20 74 68 65 20 6f 72 69 | and set| the ori|
|000001f0| 67 69 6e 73 20 6f 66 20 | 74 68 65 0a 72 6f 74 6f |gins of |the.roto|
|00000200| 72 73 20 74 6f 20 6b 6e | 6f 77 6e 20 70 6f 73 69 |rs to kn|own posi|
|00000210| 74 69 6f 6e 73 3b 20 74 | 68 65 69 72 20 69 6e 69 |tions; t|heir ini|
|00000220| 74 69 61 6c 20 70 6f 73 | 69 74 69 6f 6e 20 69 73 |tial pos|ition is|
|00000230| 20 74 68 65 20 63 69 70 | 68 65 72 69 6e 67 20 6b | the cip|hering k|
|00000240| 65 79 2e 20 20 54 6f 0a | 65 6e 63 69 70 68 65 72 |ey. To.|encipher|
|00000250| 20 61 20 63 68 61 72 61 | 63 74 65 72 2c 20 77 65 | a chara|cter, we|
|00000260| 20 70 65 72 6d 75 74 65 | 20 74 68 65 20 6f 72 69 | permute| the ori|
|00000270| 67 69 6e 61 6c 20 63 68 | 61 72 61 63 74 65 72 20 |ginal ch|aracter |
|00000280| 62 79 20 74 68 65 20 66 | 69 72 73 74 20 72 6f 74 |by the f|irst rot|
|00000290| 6f 72 2c 0a 61 6e 64 20 | 74 68 65 6e 20 61 70 70 |or,.and |then app|
|000002a0| 6c 79 20 74 68 65 20 73 | 65 63 6f 6e 64 20 72 6f |ly the s|econd ro|
|000002b0| 74 6f 72 27 73 20 70 65 | 72 6d 75 74 61 74 69 6f |tor's pe|rmutatio|
|000002c0| 6e 20 74 6f 20 74 68 65 | 20 72 65 73 75 6c 74 2e |n to the| result.|
|000002d0| 20 57 65 20 63 6f 6e 74 | 69 6e 75 65 0a 75 6e 74 | We cont|inue.unt|
|000002e0| 69 6c 20 77 65 27 76 65 | 20 61 70 70 6c 69 65 64 |il we've| applied|
|000002f0| 20 61 6c 6c 20 74 68 65 | 20 72 6f 74 6f 72 73 3b | all the| rotors;|
|00000300| 20 74 68 65 20 72 65 73 | 75 6c 74 69 6e 67 20 63 | the res|ulting c|
|00000310| 68 61 72 61 63 74 65 72 | 20 69 73 20 6f 75 72 0a |haracter| is our.|
|00000320| 63 69 70 68 65 72 74 65 | 78 74 2e 20 20 57 65 20 |cipherte|xt. We |
|00000330| 74 68 65 6e 20 63 68 61 | 6e 67 65 20 74 68 65 20 |then cha|nge the |
|00000340| 6f 72 69 67 69 6e 20 6f | 66 20 74 68 65 20 66 69 |origin o|f the fi|
|00000350| 6e 61 6c 20 72 6f 74 6f | 72 20 62 79 20 6f 6e 65 |nal roto|r by one|
|00000360| 20 70 6f 73 69 74 69 6f | 6e 2c 0a 66 72 6f 6d 20 | positio|n,.from |
|00000370| 60 41 27 20 74 6f 20 60 | 42 27 3b 20 69 66 20 74 |`A' to `|B'; if t|
|00000380| 68 65 20 66 69 6e 61 6c | 20 72 6f 74 6f 72 20 68 |he final| rotor h|
|00000390| 61 73 20 6d 61 64 65 20 | 61 20 63 6f 6d 70 6c 65 |as made |a comple|
|000003a0| 74 65 20 72 65 76 6f 6c | 75 74 69 6f 6e 2c 20 74 |te revol|ution, t|
|000003b0| 68 65 6e 20 77 65 0a 72 | 6f 74 61 74 65 20 74 68 |hen we.r|otate th|
|000003c0| 65 20 6e 65 78 74 2d 74 | 6f 2d 6c 61 73 74 20 72 |e next-t|o-last r|
|000003d0| 6f 74 6f 72 20 62 79 20 | 6f 6e 65 20 70 6f 73 69 |otor by |one posi|
|000003e0| 74 69 6f 6e 2c 20 61 6e | 64 20 61 70 70 6c 79 20 |tion, an|d apply |
|000003f0| 74 68 65 20 73 61 6d 65 | 20 70 72 6f 63 65 64 75 |the same| procedu|
|00000400| 72 65 0a 72 65 63 75 72 | 73 69 76 65 6c 79 2e 20 |re.recur|sively. |
|00000410| 20 49 6e 20 6f 74 68 65 | 72 20 77 6f 72 64 73 2c | In othe|r words,|
|00000420| 20 61 66 74 65 72 20 65 | 6e 63 69 70 68 65 72 69 | after e|ncipheri|
|00000430| 6e 67 20 6f 6e 65 20 63 | 68 61 72 61 63 74 65 72 |ng one c|haracter|
|00000440| 2c 20 77 65 20 61 64 76 | 61 6e 63 65 0a 74 68 65 |, we adv|ance.the|
|00000450| 20 72 6f 74 6f 72 73 20 | 69 6e 20 74 68 65 20 73 | rotors |in the s|
|00000460| 61 6d 65 20 66 61 73 68 | 69 6f 6e 20 61 73 20 61 |ame fash|ion as a|
|00000470| 20 63 61 72 27 73 20 6f | 64 6f 6d 65 74 65 72 2e | car's o|dometer.|
|00000480| 20 44 65 63 6f 64 69 6e | 67 20 77 6f 72 6b 73 20 | Decodin|g works |
|00000490| 69 6e 20 74 68 65 0a 73 | 61 6d 65 20 77 61 79 2c |in the.s|ame way,|
|000004a0| 20 65 78 63 65 70 74 20 | 77 65 20 72 65 76 65 72 | except |we rever|
|000004b0| 73 65 20 74 68 65 20 70 | 65 72 6d 75 74 61 74 69 |se the p|ermutati|
|000004c0| 6f 6e 73 20 61 6e 64 20 | 61 70 70 6c 79 20 74 68 |ons and |apply th|
|000004d0| 65 6d 20 69 6e 20 74 68 | 65 20 6f 70 70 6f 73 69 |em in th|e opposi|
|000004e0| 74 65 0a 6f 72 64 65 72 | 2e 0a 5c 69 6e 64 65 78 |te.order|..\index|
|000004f0| 7b 45 6c 6c 69 6e 67 68 | 6f 75 73 65 2c 20 4c 61 |{Ellingh|ouse, La|
|00000500| 6e 63 65 7d 0a 5c 69 6e | 64 65 78 69 69 7b 45 6e |nce}.\in|dexii{En|
|00000510| 69 67 6d 61 7d 7b 63 69 | 70 68 65 72 7d 0a 0a 54 |igma}{ci|pher}..T|
|00000520| 68 65 20 61 76 61 69 6c | 61 62 6c 65 20 66 75 6e |he avail|able fun|
|00000530| 63 74 69 6f 6e 73 20 69 | 6e 20 74 68 69 73 20 6d |ctions i|n this m|
|00000540| 6f 64 75 6c 65 20 61 72 | 65 3a 0a 0a 5c 72 65 6e |odule ar|e:..\ren|
|00000550| 65 77 63 6f 6d 6d 61 6e | 64 7b 5c 69 6e 64 65 78 |ewcomman|d{\index|
|00000560| 73 75 62 69 74 65 6d 7d | 7b 28 69 6e 20 6d 6f 64 |subitem}|{(in mod|
|00000570| 75 6c 65 20 72 6f 74 6f | 72 29 7d 0a 5c 62 65 67 |ule roto|r)}.\beg|
|00000580| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 6e 65 77 |in{funcd|esc}{new|
|00000590| 72 6f 74 6f 72 7d 7b 6b | 65 79 5c 6f 70 74 69 6f |rotor}{k|ey\optio|
|000005a0| 6e 61 6c 7b 5c 2c 20 6e | 75 6d 72 6f 74 6f 72 73 |nal{\, n|umrotors|
|000005b0| 7d 7d 0a 52 65 74 75 72 | 6e 20 61 20 72 6f 74 6f |}}.Retur|n a roto|
|000005c0| 72 20 6f 62 6a 65 63 74 | 2e 20 5c 76 61 72 7b 6b |r object|. \var{k|
|000005d0| 65 79 7d 20 69 73 20 61 | 20 73 74 72 69 6e 67 20 |ey} is a| string |
|000005e0| 63 6f 6e 74 61 69 6e 69 | 6e 67 20 74 68 65 20 65 |containi|ng the e|
|000005f0| 6e 63 72 79 70 74 69 6f | 6e 20 6b 65 79 0a 66 6f |ncryptio|n key.fo|
|00000600| 72 20 74 68 65 20 6f 62 | 6a 65 63 74 3b 20 69 74 |r the ob|ject; it|
|00000610| 20 63 61 6e 20 63 6f 6e | 74 61 69 6e 20 61 72 62 | can con|tain arb|
|00000620| 69 74 72 61 72 79 20 62 | 69 6e 61 72 79 20 64 61 |itrary b|inary da|
|00000630| 74 61 2e 20 54 68 65 20 | 6b 65 79 20 77 69 6c 6c |ta. The |key will|
|00000640| 20 62 65 20 75 73 65 64 | 0a 74 6f 20 72 61 6e 64 | be used|.to rand|
|00000650| 6f 6d 6c 79 20 67 65 6e | 65 72 61 74 65 20 74 68 |omly gen|erate th|
|00000660| 65 20 72 6f 74 6f 72 20 | 70 65 72 6d 75 74 61 74 |e rotor |permutat|
|00000670| 69 6f 6e 73 20 61 6e 64 | 20 74 68 65 69 72 20 69 |ions and| their i|
|00000680| 6e 69 74 69 61 6c 20 70 | 6f 73 69 74 69 6f 6e 73 |nitial p|ositions|
|00000690| 2e 0a 5c 76 61 72 7b 6e | 75 6d 72 6f 74 6f 72 73 |..\var{n|umrotors|
|000006a0| 7d 20 69 73 20 74 68 65 | 20 6e 75 6d 62 65 72 20 |} is the| number |
|000006b0| 6f 66 20 72 6f 74 6f 72 | 20 70 65 72 6d 75 74 61 |of rotor| permuta|
|000006c0| 74 69 6f 6e 73 20 69 6e | 20 74 68 65 20 72 65 74 |tions in| the ret|
|000006d0| 75 72 6e 65 64 20 6f 62 | 6a 65 63 74 3b 0a 69 66 |urned ob|ject;.if|
|000006e0| 20 69 74 20 69 73 20 6f | 6d 69 74 74 65 64 2c 20 | it is o|mitted, |
|000006f0| 61 20 64 65 66 61 75 6c | 74 20 76 61 6c 75 65 20 |a defaul|t value |
|00000700| 6f 66 20 36 20 77 69 6c | 6c 20 62 65 20 75 73 65 |of 6 wil|l be use|
|00000710| 64 2e 0a 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |d..\end{|funcdesc|
|00000720| 7d 0a 0a 52 6f 74 6f 72 | 20 6f 62 6a 65 63 74 73 |}..Rotor| objects|
|00000730| 20 68 61 76 65 20 74 68 | 65 20 66 6f 6c 6c 6f 77 | have th|e follow|
|00000740| 69 6e 67 20 6d 65 74 68 | 6f 64 73 3a 0a 0a 5c 72 |ing meth|ods:..\r|
|00000750| 65 6e 65 77 63 6f 6d 6d | 61 6e 64 7b 5c 69 6e 64 |enewcomm|and{\ind|
|00000760| 65 78 73 75 62 69 74 65 | 6d 7d 7b 28 72 6f 74 6f |exsubite|m}{(roto|
|00000770| 72 20 6d 65 74 68 6f 64 | 29 7d 0a 5c 62 65 67 69 |r method|)}.\begi|
|00000780| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 73 65 74 6b |n{funcde|sc}{setk|
|00000790| 65 79 7d 7b 7d 0a 52 65 | 73 65 74 20 74 68 65 20 |ey}{}.Re|set the |
|000007a0| 72 6f 74 6f 72 20 74 6f | 20 69 74 73 20 69 6e 69 |rotor to| its ini|
|000007b0| 74 69 61 6c 20 73 74 61 | 74 65 2e 0a 5c 65 6e 64 |tial sta|te..\end|
|000007c0| 7b 66 75 6e 63 64 65 73 | 63 7d 0a 0a 5c 62 65 67 |{funcdes|c}..\beg|
|000007d0| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 65 6e 63 |in{funcd|esc}{enc|
|000007e0| 72 79 70 74 7d 7b 70 6c | 61 69 6e 74 65 78 74 7d |rypt}{pl|aintext}|
|000007f0| 0a 52 65 73 65 74 20 74 | 68 65 20 72 6f 74 6f 72 |.Reset t|he rotor|
|00000800| 20 6f 62 6a 65 63 74 20 | 74 6f 20 69 74 73 20 69 | object |to its i|
|00000810| 6e 69 74 69 61 6c 20 73 | 74 61 74 65 20 61 6e 64 |nitial s|tate and|
|00000820| 20 65 6e 63 72 79 70 74 | 20 5c 76 61 72 7b 70 6c | encrypt| \var{pl|
|00000830| 61 69 6e 74 65 78 74 7d | 2c 0a 72 65 74 75 72 6e |aintext}|,.return|
|00000840| 69 6e 67 20 61 20 73 74 | 72 69 6e 67 20 63 6f 6e |ing a st|ring con|
|00000850| 74 61 69 6e 69 6e 67 20 | 74 68 65 20 63 69 70 68 |taining |the ciph|
|00000860| 65 72 74 65 78 74 2e 20 | 20 54 68 65 20 63 69 70 |ertext. | The cip|
|00000870| 68 65 72 74 65 78 74 20 | 69 73 20 61 6c 77 61 79 |hertext |is alway|
|00000880| 73 20 74 68 65 0a 73 61 | 6d 65 20 6c 65 6e 67 74 |s the.sa|me lengt|
|00000890| 68 20 61 73 20 74 68 65 | 20 6f 72 69 67 69 6e 61 |h as the| origina|
|000008a0| 6c 20 70 6c 61 69 6e 74 | 65 78 74 2e 0a 5c 65 6e |l plaint|ext..\en|
|000008b0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|000008c0| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 65 6e |gin{func|desc}{en|
|000008d0| 63 72 79 70 74 6d 6f 72 | 65 7d 7b 70 6c 61 69 6e |cryptmor|e}{plain|
|000008e0| 74 65 78 74 7d 0a 45 6e | 63 72 79 70 74 20 5c 76 |text}.En|crypt \v|
|000008f0| 61 72 7b 70 6c 61 69 6e | 74 65 78 74 7d 20 77 69 |ar{plain|text} wi|
|00000900| 74 68 6f 75 74 20 72 65 | 73 65 74 74 69 6e 67 20 |thout re|setting |
|00000910| 74 68 65 20 72 6f 74 6f | 72 20 6f 62 6a 65 63 74 |the roto|r object|
|00000920| 2c 20 61 6e 64 20 72 65 | 74 75 72 6e 20 61 0a 73 |, and re|turn a.s|
|00000930| 74 72 69 6e 67 20 63 6f | 6e 74 61 69 6e 69 6e 67 |tring co|ntaining|
|00000940| 20 74 68 65 20 63 69 70 | 68 65 72 74 65 78 74 2e | the cip|hertext.|
|00000950| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|00000960| 0a 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00000970| 7d 7b 64 65 63 72 79 70 | 74 7d 7b 63 69 70 68 65 |}{decryp|t}{ciphe|
|00000980| 72 74 65 78 74 7d 0a 52 | 65 73 65 74 20 74 68 65 |rtext}.R|eset the|
|00000990| 20 72 6f 74 6f 72 20 6f | 62 6a 65 63 74 20 74 6f | rotor o|bject to|
|000009a0| 20 69 74 73 20 69 6e 69 | 74 69 61 6c 20 73 74 61 | its ini|tial sta|
|000009b0| 74 65 20 61 6e 64 20 64 | 65 63 72 79 70 74 20 5c |te and d|ecrypt \|
|000009c0| 76 61 72 7b 63 69 70 68 | 65 72 74 65 78 74 7d 2c |var{ciph|ertext},|
|000009d0| 0a 72 65 74 75 72 6e 69 | 6e 67 20 61 20 73 74 72 |.returni|ng a str|
|000009e0| 69 6e 67 20 63 6f 6e 74 | 61 69 6e 69 6e 67 20 74 |ing cont|aining t|
|000009f0| 68 65 20 63 69 70 68 65 | 72 74 65 78 74 2e 20 20 |he ciphe|rtext. |
|00000a00| 54 68 65 20 70 6c 61 69 | 6e 74 65 78 74 20 73 74 |The plai|ntext st|
|00000a10| 72 69 6e 67 20 77 69 6c | 6c 0a 61 6c 77 61 79 73 |ring wil|l.always|
|00000a20| 20 62 65 20 74 68 65 20 | 73 61 6d 65 20 6c 65 6e | be the |same len|
|00000a30| 67 74 68 20 61 73 20 74 | 68 65 20 63 69 70 68 65 |gth as t|he ciphe|
|00000a40| 72 74 65 78 74 2e 0a 5c | 65 6e 64 7b 66 75 6e 63 |rtext..\|end{func|
|00000a50| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000a60| 6e 63 64 65 73 63 7d 7b | 64 65 63 72 79 70 74 6d |ncdesc}{|decryptm|
|00000a70| 6f 72 65 7d 7b 63 69 70 | 68 65 72 74 65 78 74 7d |ore}{cip|hertext}|
|00000a80| 0a 44 65 63 72 79 70 74 | 20 5c 76 61 72 7b 63 69 |.Decrypt| \var{ci|
|00000a90| 70 68 65 72 74 65 78 74 | 7d 20 77 69 74 68 6f 75 |phertext|} withou|
|00000aa0| 74 20 72 65 73 65 74 74 | 69 6e 67 20 74 68 65 20 |t resett|ing the |
|00000ab0| 72 6f 74 6f 72 20 6f 62 | 6a 65 63 74 2c 20 61 6e |rotor ob|ject, an|
|00000ac0| 64 20 72 65 74 75 72 6e | 20 61 0a 73 74 72 69 6e |d return| a.strin|
|00000ad0| 67 20 63 6f 6e 74 61 69 | 6e 69 6e 67 20 74 68 65 |g contai|ning the|
|00000ae0| 20 63 69 70 68 65 72 74 | 65 78 74 2e 0a 5c 65 6e | ciphert|ext..\en|
|00000af0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 41 6e 20 |d{funcde|sc}..An |
|00000b00| 65 78 61 6d 70 6c 65 20 | 75 73 61 67 65 3a 0a 5c |example |usage:.\|
|00000b10| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00000b20| 61 74 69 6d 7d 0a 3e 3e | 3e 20 69 6d 70 6f 72 74 |atim}.>>|> import|
|00000b30| 20 72 6f 74 6f 72 0a 3e | 3e 3e 20 72 74 20 3d 20 | rotor.>|>> rt = |
|00000b40| 72 6f 74 6f 72 2e 6e 65 | 77 72 6f 74 6f 72 28 27 |rotor.ne|wrotor('|
|00000b50| 6b 65 79 27 2c 20 31 32 | 29 0a 3e 3e 3e 20 72 74 |key', 12|).>>> rt|
|00000b60| 2e 65 6e 63 72 79 70 74 | 28 27 62 61 72 27 29 0a |.encrypt|('bar').|
|00000b70| 27 5c 32 35 33 34 5c 33 | 36 33 27 0a 3e 3e 3e 20 |'\2534\3|63'.>>> |
|00000b80| 72 74 2e 65 6e 63 72 79 | 70 74 6d 6f 72 65 28 27 |rt.encry|ptmore('|
|00000b90| 62 61 72 27 29 0a 27 5c | 33 35 37 5c 33 37 35 24 |bar').'\|357\375$|
|00000ba0| 27 0a 3e 3e 3e 20 72 74 | 2e 65 6e 63 72 79 70 74 |'.>>> rt|.encrypt|
|00000bb0| 28 27 62 61 72 27 29 0a | 27 5c 32 35 33 34 5c 33 |('bar').|'\2534\3|
|00000bc0| 36 33 27 0a 3e 3e 3e 20 | 72 74 2e 64 65 63 72 79 |63'.>>> |rt.decry|
|00000bd0| 70 74 28 27 5c 32 35 33 | 34 5c 33 36 33 27 29 0a |pt('\253|4\363').|
|00000be0| 27 62 61 72 27 0a 3e 3e | 3e 20 72 74 2e 64 65 63 |'bar'.>>|> rt.dec|
|00000bf0| 72 79 70 74 6d 6f 72 65 | 28 27 5c 33 35 37 5c 33 |ryptmore|('\357\3|
|00000c00| 37 35 24 27 29 0a 27 62 | 61 72 27 0a 3e 3e 3e 20 |75$').'b|ar'.>>> |
|00000c10| 72 74 2e 64 65 63 72 79 | 70 74 28 27 5c 33 35 37 |rt.decry|pt('\357|
|00000c20| 5c 33 37 35 24 27 29 0a | 27 6c 28 5c 33 31 35 27 |\375$').|'l(\315'|
|00000c30| 0a 3e 3e 3e 20 64 65 6c | 20 72 74 0a 5c 65 6e 64 |.>>> del| rt.\end|
|00000c40| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|00000c50| 0a 0a 54 68 65 20 6d 6f | 64 75 6c 65 27 73 20 63 |..The mo|dule's c|
|00000c60| 6f 64 65 20 69 73 20 6e | 6f 74 20 61 6e 20 65 78 |ode is n|ot an ex|
|00000c70| 61 63 74 20 73 69 6d 75 | 6c 61 74 69 6f 6e 20 6f |act simu|lation o|
|00000c80| 66 20 74 68 65 20 6f 72 | 69 67 69 6e 61 6c 20 45 |f the or|iginal E|
|00000c90| 6e 69 67 6d 61 20 64 65 | 76 69 63 65 3b 0a 69 74 |nigma de|vice;.it|
|00000ca0| 20 69 6d 70 6c 65 6d 65 | 6e 74 73 20 74 68 65 20 | impleme|nts the |
|00000cb0| 72 6f 74 6f 72 20 65 6e | 63 72 79 70 74 69 6f 6e |rotor en|cryption|
|00000cc0| 20 73 63 68 65 6d 65 20 | 64 69 66 66 65 72 65 6e | scheme |differen|
|00000cd0| 74 6c 79 20 66 72 6f 6d | 20 74 68 65 20 6f 72 69 |tly from| the ori|
|00000ce0| 67 69 6e 61 6c 2e 20 54 | 68 65 0a 6d 6f 73 74 20 |ginal. T|he.most |
|00000cf0| 69 6d 70 6f 72 74 61 6e | 74 20 64 69 66 66 65 72 |importan|t differ|
|00000d00| 65 6e 63 65 20 69 73 20 | 74 68 61 74 20 69 6e 20 |ence is |that in |
|00000d10| 74 68 65 20 6f 72 69 67 | 69 6e 61 6c 20 45 6e 69 |the orig|inal Eni|
|00000d20| 67 6d 61 2c 20 74 68 65 | 72 65 20 77 65 72 65 20 |gma, the|re were |
|00000d30| 6f 6e 6c 79 20 35 0a 6f | 72 20 36 20 64 69 66 66 |only 5.o|r 6 diff|
|00000d40| 65 72 65 6e 74 20 72 6f | 74 6f 72 73 20 69 6e 20 |erent ro|tors in |
|00000d50| 65 78 69 73 74 65 6e 63 | 65 2c 20 61 6e 64 20 74 |existenc|e, and t|
|00000d60| 68 65 79 20 77 65 72 65 | 20 61 70 70 6c 69 65 64 |hey were| applied|
|00000d70| 20 74 77 69 63 65 20 74 | 6f 20 65 61 63 68 0a 63 | twice t|o each.c|
|00000d80| 68 61 72 61 63 74 65 72 | 3b 20 74 68 65 20 63 69 |haracter|; the ci|
|00000d90| 70 68 65 72 20 6b 65 79 | 20 77 61 73 20 74 68 65 |pher key| was the|
|00000da0| 20 6f 72 64 65 72 20 69 | 6e 20 77 68 69 63 68 20 | order i|n which |
|00000db0| 74 68 65 79 20 77 65 72 | 65 20 70 6c 61 63 65 64 |they wer|e placed|
|00000dc0| 20 69 6e 20 74 68 65 0a | 6d 61 63 68 69 6e 65 2e | in the.|machine.|
|00000dd0| 20 20 54 68 65 20 50 79 | 74 68 6f 6e 20 72 6f 74 | The Py|thon rot|
|00000de0| 6f 72 20 6d 6f 64 75 6c | 65 20 75 73 65 73 20 74 |or modul|e uses t|
|00000df0| 68 65 20 73 75 70 70 6c | 69 65 64 20 6b 65 79 20 |he suppl|ied key |
|00000e00| 74 6f 20 69 6e 69 74 69 | 61 6c 69 7a 65 20 61 0a |to initi|alize a.|
|00000e10| 72 61 6e 64 6f 6d 20 6e | 75 6d 62 65 72 20 67 65 |random n|umber ge|
|00000e20| 6e 65 72 61 74 6f 72 3b | 20 74 68 65 20 72 6f 74 |nerator;| the rot|
|00000e30| 6f 72 20 70 65 72 6d 75 | 74 61 74 69 6f 6e 73 20 |or permu|tations |
|00000e40| 61 6e 64 20 74 68 65 69 | 72 20 69 6e 69 74 69 61 |and thei|r initia|
|00000e50| 6c 20 70 6f 73 69 74 69 | 6f 6e 73 0a 61 72 65 20 |l positi|ons.are |
|00000e60| 74 68 65 6e 20 72 61 6e | 64 6f 6d 6c 79 20 67 65 |then ran|domly ge|
|00000e70| 6e 65 72 61 74 65 64 2e | 20 20 54 68 65 20 6f 72 |nerated.| The or|
|00000e80| 69 67 69 6e 61 6c 20 64 | 65 76 69 63 65 20 6f 6e |iginal d|evice on|
|00000e90| 6c 79 20 65 6e 63 69 70 | 68 65 72 65 64 20 74 68 |ly encip|hered th|
|00000ea0| 65 0a 6c 65 74 74 65 72 | 73 20 6f 66 20 74 68 65 |e.letter|s of the|
|00000eb0| 20 61 6c 70 68 61 62 65 | 74 2c 20 77 68 69 6c 65 | alphabe|t, while|
|00000ec0| 20 74 68 69 73 20 6d 6f | 64 75 6c 65 20 63 61 6e | this mo|dule can|
|00000ed0| 20 68 61 6e 64 6c 65 20 | 61 6e 79 20 38 2d 62 69 | handle |any 8-bi|
|00000ee0| 74 20 62 69 6e 61 72 79 | 20 64 61 74 61 3b 0a 69 |t binary| data;.i|
|00000ef0| 74 20 61 6c 73 6f 20 70 | 72 6f 64 75 63 65 73 20 |t also p|roduces |
|00000f00| 62 69 6e 61 72 79 20 6f | 75 74 70 75 74 2e 20 20 |binary o|utput. |
|00000f10| 54 68 69 73 20 6d 6f 64 | 75 6c 65 20 63 61 6e 20 |This mod|ule can |
|00000f20| 61 6c 73 6f 20 6f 70 65 | 72 61 74 65 20 77 69 74 |also ope|rate wit|
|00000f30| 68 20 61 6e 0a 61 72 62 | 69 74 72 61 72 79 20 6e |h an.arb|itrary n|
|00000f40| 75 6d 62 65 72 20 6f 66 | 20 72 6f 74 6f 72 73 2e |umber of| rotors.|
|00000f50| 0a 0a 54 68 65 20 6f 72 | 69 67 69 6e 61 6c 20 45 |..The or|iginal E|
|00000f60| 6e 69 67 6d 61 20 63 69 | 70 68 65 72 20 77 61 73 |nigma ci|pher was|
|00000f70| 20 62 72 6f 6b 65 6e 20 | 69 6e 20 31 39 34 34 2e | broken |in 1944.|
|00000f80| 20 25 20 58 58 58 3a 20 | 49 73 20 74 68 69 73 20 | % XXX: |Is this |
|00000f90| 72 69 67 68 74 3f 0a 54 | 68 65 20 76 65 72 73 69 |right?.T|he versi|
|00000fa0| 6f 6e 20 69 6d 70 6c 65 | 6d 65 6e 74 65 64 20 68 |on imple|mented h|
|00000fb0| 65 72 65 20 69 73 20 70 | 72 6f 62 61 62 6c 79 20 |ere is p|robably |
|00000fc0| 61 20 67 6f 6f 64 20 64 | 65 61 6c 20 6d 6f 72 65 |a good d|eal more|
|00000fd0| 20 64 69 66 66 69 63 75 | 6c 74 20 74 6f 20 63 72 | difficu|lt to cr|
|00000fe0| 61 63 6b 0a 28 65 73 70 | 65 63 69 61 6c 6c 79 20 |ack.(esp|ecially |
|00000ff0| 69 66 20 79 6f 75 20 75 | 73 65 20 6d 61 6e 79 20 |if you u|se many |
|00001000| 72 6f 74 6f 72 73 29 2c | 20 62 75 74 20 69 74 20 |rotors),| but it |
|00001010| 77 6f 6e 27 74 20 62 65 | 20 69 6d 70 6f 73 73 69 |won't be| impossi|
|00001020| 62 6c 65 20 66 6f 72 0a | 61 20 74 72 75 6c 79 20 |ble for.|a truly |
|00001030| 73 6b 69 6c 66 75 6c 20 | 61 6e 64 20 64 65 74 65 |skilful |and dete|
|00001040| 72 6d 69 6e 65 64 20 61 | 74 74 61 63 6b 65 72 20 |rmined a|ttacker |
|00001050| 74 6f 20 62 72 65 61 6b | 20 74 68 65 20 63 69 70 |to break| the cip|
|00001060| 68 65 72 2e 20 20 53 6f | 20 69 66 20 79 6f 75 20 |her. So| if you |
|00001070| 77 61 6e 74 0a 74 6f 20 | 6b 65 65 70 20 74 68 65 |want.to |keep the|
|00001080| 20 4e 53 41 20 6f 75 74 | 20 6f 66 20 79 6f 75 72 | NSA out| of your|
|00001090| 20 66 69 6c 65 73 2c 20 | 74 68 69 73 20 72 6f 74 | files, |this rot|
|000010a0| 6f 72 20 63 69 70 68 65 | 72 20 6d 61 79 20 77 65 |or ciphe|r may we|
|000010b0| 6c 6c 20 62 65 20 75 6e | 73 61 66 65 2c 20 62 75 |ll be un|safe, bu|
|000010c0| 74 0a 66 6f 72 20 64 69 | 73 63 6f 75 72 61 67 69 |t.for di|scouragi|
|000010d0| 6e 67 20 63 61 73 75 61 | 6c 20 73 6e 6f 6f 70 69 |ng casua|l snoopi|
|000010e0| 6e 67 20 74 68 72 6f 75 | 67 68 20 79 6f 75 72 20 |ng throu|gh your |
|000010f0| 66 69 6c 65 73 2c 20 69 | 74 20 77 69 6c 6c 20 70 |files, i|t will p|
|00001100| 72 6f 62 61 62 6c 79 20 | 62 65 0a 6a 75 73 74 20 |robably |be.just |
|00001110| 66 69 6e 65 2c 20 61 6e | 64 20 6d 61 79 20 62 65 |fine, an|d may be|
|00001120| 20 73 6f 6d 65 77 68 61 | 74 20 73 61 66 65 72 20 | somewha|t safer |
|00001130| 74 68 61 6e 20 75 73 69 | 6e 67 20 74 68 65 20 55 |than usi|ng the U|
|00001140| 6e 69 78 20 5c 66 69 6c | 65 7b 63 72 79 70 74 7d |nix \fil|e{crypt}|
|00001150| 0a 63 6f 6d 6d 61 6e 64 | 2e 0a 5c 69 6e 64 65 78 |.command|..\index|
|00001160| 7b 4e 61 74 69 6f 6e 61 | 6c 20 53 65 63 75 72 69 |{Nationa|l Securi|
|00001170| 74 79 20 41 67 65 6e 63 | 79 7d 5c 69 6e 64 65 78 |ty Agenc|y}\index|
|00001180| 7b 63 72 79 70 74 28 31 | 29 7d 0a 25 20 58 58 58 |{crypt(1|)}.% XXX|
|00001190| 20 48 6f 77 20 77 65 72 | 65 20 55 6e 69 78 20 63 | How wer|e Unix c|
|000011a0| 6f 6d 6d 61 6e 64 73 20 | 72 65 70 72 65 73 65 6e |ommands |represen|
|000011b0| 74 65 64 20 69 6e 20 74 | 68 65 20 64 6f 63 73 3f |ted in t|he docs?|
|000011c0| 0a 0a | |.. | |
+--------+-------------------------+-------------------------+--------+--------+