letters = 'abcdefghijklmnopqrstuvwxyz ' encryption = 'cfzbwhmpxnaqdosyeikugjtvrl ' message = 'this is the story about udacity challenging the established way of teaching students' translated = ''.join([encryption [letters.index(letter)] for letter in message]) print translated
A more efficient way is to make a translation table first so we can use string.translate(table) method.
from string import maketrans letters = 'abcdefghijklmnopqrstuvwxyz ' encryption = 'cfzbwhmpxnaqdosyeikugjtvrl ' message = 'this is the story about udacity challenging the established way of teaching students' translationtable = maketrans(letters, encryption) translated = message.translate(translationtable) print translated
upxk xk upw kusir cfsgu gbczxur zpcqqwomxom upw wkucfqxkpwb tcr sh uwczpxom kugbwouk
What will be more challenging is to de-encrypt his message as you evidently don't know the encryption used. Interesting topic for a next article ;-)
Just as a side note: Any clue how many permutations exist for 27 characters??
27! = 1.08888695 × 1028
No comments:
Post a Comment