I need to write a program that reads a cipher text. I'm confused on how to import the needed text. Is this right? What if I have more than one cipher text to import?
def MultiAlphaCipher():
import MyCipherText.txt
I need to write a program that reads a cipher text. I'm confused on how to import the needed text. Is this right? What if I have more than one cipher text to import?
def MultiAlphaCipher():
import MyCipherText.txt
If you are just reading the contents of a plain encrypted text file:
def read_file():
f=file('MyFile.txt', 'r') ## For files like ".txt"
content = f.read()
f.close()
return content
file_stuff = read_file() ## Will return the contents of "MyFile.txt" or whatever the filename is!
There are other conventions on reading a file like using "open" or "with", but that'll do untill you get better... Also, in my experience of cryptography, I suggest using a diffrrent read mode or possibly encoding.
f = file("MyFile.doc", "rb") ## For files like ".pdf", ".rtf" or any file that uses font, color, etc
That will open the file in "read binary" mode which is helpful if you're encrypting/deceypting files outside plain ASCII. Then when writting to a file, you'll use mode "w" or "wb" to "write binary"
Hope that helps!
Additonal Tips: If that is your actual code:
Try something like:
with open("MyCipherText.txt") as f:
cipher_text = f.read()