Replacing parts of a string simultaneously
I am trying to make an "encrypter" in python that changes everything in a
string by a "key" file.
Code:
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
alphabet = list(alphabet)
cryptkey = open("cryptkey", "r")
key = cryptkey.read(36)
text = list(key)
tocrypt = open("tocrypt.txt", "r")
tocryptvar = tocrypt.read()
tocryptvar = tocryptvar.lower()
################################################ Replacement
tocryptvar = tocryptvar.replace("a", key[0]).replace("b",
key[1]).replace("c", key[2]) #etc
The key is just the alphabet and the numbers shuffled and put in a file.
So, my problem is that when say, A gets replaced to say B its all good but
then it changes B to say, G, then A has become G. And thats it.
No comments:
Post a Comment