Note that there are some explanatory texts on larger screens.

plurals
  1. POCaeser cipher encryption from file in Python
    primarykey
    data
    text
    <p>My Caeser cipher works interactively in the shell with a string, but when I've tried to undertake separate programs to encrypt and decrypt I've run into problems, I don't know whether the input is not being split into a list or not, but the if statement in my encryption function is being bypassed and defaulting to the else statement that fills the list unencrypted. Any suggestions appreciated. I'm using FileUtilities.py from the Goldwasser book. That file is at <a href="http://prenhall.com/goldwasser/sourcecode.zip" rel="nofollow">http://prenhall.com/goldwasser/sourcecode.zip</a> in chapter 11, but I don't think the problem is with that, but who knows. Advance thanks.</p> <pre><code>#CaeserCipher.py class CaeserCipher: def __init__ (self, unencrypted="", encrypted=""): self._plain = unencrypted self._cipher = encrypted self._encoded = "" def encrypt (self, plaintext): self._plain = plaintext plain_list = list(self._plain) i = 0 final = [] while (i &lt;= len(plain_list)-1): if plain_list[i] in plainset: final.append(plainset[plain_list[i]]) else: final.append(plain_list[i]) i+=1 self._encoded = ''.join(final) return self._encoded def decrypt (self, ciphertext): self._cipher = ciphertext cipher_list = list(self._cipher) i = 0 final = [] while (i &lt;= len(cipher_list)-1): if cipher_list[i] in cipherset: final.append(cipherset[cipher_list[i]]) else: final.append(cipher_list[i]) i+=1 self._encoded = ''.join(final) return self._encoded def writeEncrypted(self, outfile): encoded_file = self._encoded outfile.write('%s' %(encoded_file)) #encrypt.py from FileUtilities import openFileReadRobust, openFileWriteRobust from CaeserCipher import CaeserCipher caeser = CaeserCipher() source = openFileReadRobust() destination = openFileWriteRobust('encrypted.txt') caeser.encrypt(source) caeser.writeEncrypted(destination) source.close() destination.close() print 'Encryption completed.' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload