Advertisement
slatisfaction

Fibonacci Encryptor

Mar 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def main():
  2. startAlgorithm()
  3.  
  4. def fibonacciSeq(n):
  5. a = 0
  6. b = 1
  7. for i in range(0, n - 2):
  8. c = a + b
  9. a = b
  10. b = c
  11. return c
  12.  
  13. characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  14. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
  15.  
  16. def startAlgorithm():
  17. while True:
  18.  
  19. userInput = input("Enter the nth number Fibonacci sequence for the key then ; and then the word you want encoded: ")
  20.  
  21. output = ""
  22.  
  23. if userInput < 0:
  24. break
  25.  
  26. n = int(userInput[0:userInput.find(';')])
  27.  
  28. word = userInput[userInput.find(';') + 1:]
  29.  
  30. for i in range(0, len(word)):
  31. output += characters[(characters.index(word[i].upper())
  32. + fibonacciSeq(n + i)) % 26]
  33. print(output)
  34.  
  35. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement