isefire

One Time Pad - Encryption

Mar 3rd, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #
  2. # -*- coding: utf-8 -*-
  3. #
  4. #  One Time Pad - Encryption
  5. #  
  6. #  Copyright 2014 [email protected]
  7. #  
  8. #  This program is free software; you can redistribute it and/or modify
  9. #  it under the terms of the GNU General Public License as published by
  10. #  the Free Software Foundation; either version 2 of the License, or
  11. #  (at your option) any later version.
  12. #  
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #  
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software
  20. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. #  MA 02110-1301, USA.
  22. #  
  23. #  
  24. from random import randint
  25. message = list(raw_input("message---> ").lower())
  26. alphabet = list("abcdefghijklmnopqrstuvqxyz")
  27. keylist = []
  28. cy = []
  29. for i in message:
  30.     if i in alphabet:
  31.         i = alphabet.index(i)
  32.         key = randint(1,26)
  33.         keylist.append(key)
  34.         i = (i + key)%26
  35.         cy.append(alphabet[i])
  36.     else:
  37.         cy.append(i)
  38.  
  39. cy = ''.join(cy)
  40.        
  41. print "Here is your Key-List---> ",keylist
  42. print "Here is your One-Time Pad Cypher---> ", cy
Advertisement
Add Comment
Please, Sign In to add comment