Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import os
  2. print (os.getcwd())
  3. os.chdir("/storage/emulated/0/PY")
  4. print (os.getcwd())
  5.  
  6. def encrypt(key, text):
  7. result = ""
  8.  
  9. for c in text:
  10. if ord(c) == 32:
  11. result += " "
  12. else:
  13. result += chr(ord(c) + key)
  14. print (result)
  15. return result
  16.  
  17.  
  18.  
  19. def write(filename, text):
  20. f = open(filename, "w")
  21. c = f.write(text)
  22. print (c)
  23. f.close()
  24.  
  25.  
  26.  
  27. def read(filename):
  28. f = open(filename, "r")
  29. c = f.read()
  30. f.close()
  31. return c
  32.  
  33.  
  34.  
  35. def decrypt(key, text):
  36. result = ""
  37.  
  38. if key.isdigit():
  39. key = int(key)
  40.  
  41. else:
  42. print ("Key must be integer.")
  43. return None
  44.  
  45. for c in text:
  46. if ord(c) == 32:
  47. result += " "
  48. else:
  49. result += chr(int(ord(c) - key))
  50. print (result)
  51.  
  52.  
  53.  
  54. write(input("Input file name to encrypt. "), encrypt(5, read("h.txt"))
  55. #encrypt(5, read(input("Input file name to encrypt. ")))
  56. decrypt(input("Input key number. "), read("h.txt"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement