Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def move(word, shift):
- alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
- original = ""
- for letter in range(26, len(alphabet)):
- if alphabet[letter] == word: #this only works if len(word) is 0, I want to be able to iterate over the letters in word.
- original += alphabet[letter-shift]
- return original
- def move(word, shift):
- alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- return "".join([alphabet[alphabet.find(i)-shift] for i in word])
- alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- ...
- char_pos = alphabet.index(char)
- new_pos = (char_pos - shift) % len(alphabet)
- new_char = alphabet[new_pos]
- new_word = ""
- for char in word:
- # insert the above logic
- new_word += new_char
- def move(word, shift):
- alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- return ''.join([alphabet[(alphabet.find(char) - shift) % 26]
- if char in alphabet else char
- for char in word])
- print move("IBM", 1)
- print move("The 1812 OVERTURE is COOL!", 13)
- HAL
- Ghe 1812 BIREGHER is PBBY!
- A_VAL = ord('a')
- def move(word, shift):
- new_word = ""
- for letter in word:
- new_letter = ord(letter) - shift
- new_word += chr(new_letter) if (new_letter >= A_VAL) else (26 + new_letter)
- return new_word
- def code_vigenere(ch,cle):
- text = ch.lower()
- clef = cle.lower()
- L = len(cle)
- res = ''
- for i,l in enumerate(text):
- res += chr((ord(l) - 97 + ord(cle[i%L]) - 97)%26 +97)
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement