Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. def move(word, shift):
  2. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3. original = ""
  4. for letter in range(26, len(alphabet)):
  5. if alphabet[letter] == word: #this only works if len(word) is 0, I want to be able to iterate over the letters in word.
  6. original += alphabet[letter-shift]
  7. return original
  8.  
  9. def move(word, shift):
  10. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  11. return "".join([alphabet[alphabet.find(i)-shift] for i in word])
  12.  
  13. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  14. ...
  15. char_pos = alphabet.index(char)
  16. new_pos = (char_pos - shift) % len(alphabet)
  17. new_char = alphabet[new_pos]
  18.  
  19. new_word = ""
  20. for char in word:
  21. # insert the above logic
  22. new_word += new_char
  23.  
  24. def move(word, shift):
  25. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  26. return ''.join([alphabet[(alphabet.find(char) - shift) % 26]
  27. if char in alphabet else char
  28. for char in word])
  29.  
  30. print move("IBM", 1)
  31. print move("The 1812 OVERTURE is COOL!", 13)
  32.  
  33. HAL
  34. Ghe 1812 BIREGHER is PBBY!
  35.  
  36. A_VAL = ord('a')
  37.  
  38. def move(word, shift):
  39. new_word = ""
  40. for letter in word:
  41. new_letter = ord(letter) - shift
  42. new_word += chr(new_letter) if (new_letter >= A_VAL) else (26 + new_letter)
  43. return new_word
  44.  
  45. def code_vigenere(ch,cle):
  46. text = ch.lower()
  47. clef = cle.lower()
  48. L = len(cle)
  49. res = ''
  50.  
  51. for i,l in enumerate(text):
  52. res += chr((ord(l) - 97 + ord(cle[i%L]) - 97)%26 +97)
  53.  
  54. return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement