Advertisement
Guest User

Untitled

a guest
Oct 17th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. #Description:
  2. #Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently they can be #guessed due to common cultural references. You can get your passphrases stronger by different means. One is the following:
  3. #choose a text in capital letters including or not digits and non alphabetic characters,
  4. #shift each letter by a given number but the transformed letter must be a letter (circular shift),
  5. #replace each digit by its complement to 9,
  6. #keep such as non alphabetic and non digit characters,
  7. #downcase each letter in odd position, upcase each letter in even position (the first character is in position 0),
  8. #reverse the whole result.
  9. #Example:
  10. #your text: "BORN IN 2015!", shift 1
  11. #1 + 2 + 3 -> "CPSO JO 7984!"
  12. #4 "CpSo jO 7984!"
  13. #5 "!4897 Oj oSpC"
  14. #With longer passphrases it's better to have a small and easy program. Would you write it?
  15. #https://en.wikipedia.org/wiki/Passphrase
  16.  
  17. def play_pass(s, n):
  18.     x = 'abcdefghijklmnopqrstuvwxyz'
  19.     index_ = 0
  20.     total = ''
  21.     for i in range(len(s)):
  22.         if s[i].isalpha():
  23.             index_ = x.index(s[i].lower()) + n
  24.             while index_ > 25 or index_ < 0:
  25.                 index_ = abs(26 - abs(index_))
  26.             if i % 2 == 0:
  27.                 total += x[index_].upper()
  28.                
  29.             else:
  30.                 total += x[index_].lower()
  31.                
  32.         elif s[i].isdigit():
  33.             index_ = abs(9 - int(s[i]))
  34.             total += str(index_)
  35.         else:
  36.             total += s[i]
  37.     return total[::-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement