;ς ΆΩπ>c@smdZdklZlZdklZdklZdklZlZl Z l Z deefd„ƒYZ e djoρe ƒZ e idƒpt‚e id ƒ pt‚e id ƒ pt‚d e _e id jpt‚e id ƒd jpt‚e id ƒd jpt‚d e _e idƒdjpt‚e idƒdjpt‚ndS(s(This module contains the Vigenere class.(saddssub(sCharacterCipher(s KeyedCipher(s LEN_ALPHABETsapply_caselesssoffsets from_offsetsVigenerecBsbtZdZdZdZd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z RS( sfThis is a Rot-like cipher that uses a private key. Basically, each letter is rotated by an amount that is a function of both its position in the file as well as the private key. The following attributes are used: key - This is the private key. keyDescription - This is a description of what constitutes a valid key. defaultKey - This is the default key. The following private variables are used: _keyIndex - This is a value in the range 0..len(key) that gets incremented module len(key) for every ASCII character as that character is encrypted or decrypted. sone or more lowercase letterssacCs|i|_dS(sSet key to defaultKey.N(sselfs defaultKeyskey(sself((s./cipher/Vigenere.pys__init__"scCsd|_ti||ƒSdS(s=Extend the base class's encrypt method to set _keyIndex to 0.iN(sselfs _keyIndexsCharacterCiphersencryptss(sselfss((s./cipher/Vigenere.pysencrypt&s cCsd|_ti||ƒSdS(s=Extend the base class's decrypt method to set _keyIndex to 0.iN(sselfs _keyIndexsCharacterCiphersdecryptss(sselfss((s./cipher/Vigenere.pysdecrypt+s cCs|i|tƒSdS(sEncrypt and return c.N(sselfs_cryptCharacterscsadd(sselfsc((s./cipher/Vigenere.pysencryptCharacter0scCs|i|tƒSdS(sDecrypt and return c.N(sselfs_cryptCharacterscssub(sselfsc((s./cipher/Vigenere.pysdecryptCharacter4scCsP|iƒ o|Snt|i||ƒ}|idt|i ƒ|_|SdS(s2Take care of non-letters as well as the _keyIndex.iN( scsisalphasapply_caselesssselfs_cryptCharacterBackendsfsrets _keyIndexslenskey(sselfscsfsret((s./cipher/Vigenere.pys_cryptCharacter8s cCsCt|ƒ}t|i|iƒ}|||ƒt}t |ƒSdS(s)Actually do the encryption or decryption.N( soffsetscs inputPartsselfskeys _keyIndexskeyPartsfs LEN_ALPHABETs desiredOffsets from_offset(sselfscsfs inputPartskeyParts desiredOffset((s./cipher/Vigenere.pys_cryptCharacterBackend@s  cCs|iƒo |iƒSdS(s*Is key a a valid key? See keyDescription.N(skeysisalphasislower(sselfskey((s./cipher/Vigenere.pys isValidKeyGs( s__name__s __module__s__doc__skeyDescriptions defaultKeys__init__sencryptsdecryptsencryptCharactersdecryptCharacters_cryptCharacters_cryptCharacterBackends isValidKey(((s./cipher/Vigenere.pysVigenere s        s__main__sabzsABCs sbadscagsxyzsbcasyazN(s__doc__soperatorsaddssubsCharacterCiphers KeyedCiphersToolss LEN_ALPHABETsapply_caselesssoffsets from_offsetsVigeneres__name__sciphers isValidKeysAssertionErrorskeysencryptsdecrypt( ssubsapply_caselesssVigeneres KeyedCiphersaddsciphers LEN_ALPHABETsoffsetsCharacterCiphers from_offset((s./cipher/Vigenere.pys?s"  C