Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. from blowfish import blowfish
  2.  
  3. def enkripsi(key, word):
  4. T = blowfish(word.encode())
  5. x = T.encrypt(word.encode())
  6. return x
  7.  
  8.  
  9. def dekripsi(key, word):
  10. T = blowfish(str.encode(key))
  11. y = T.decrypt(word).decode()
  12. return y
  13.  
  14.  
  15. def readtext(path):
  16. file = open(path, 'r')
  17. text = file.read()
  18. return text
  19.  
  20.  
  21. def readbin(path):
  22. file = open(path, 'rb')
  23. text = file.read()
  24. return text
  25.  
  26. def main():
  27. while (1):
  28. choice = int(input("\n 1.Encryption \n 2.Decryption: \n 3.EXIT \n Choice : "))
  29. if choice == 1:
  30. source = int(input("\n 1.From file \n 2.From text input \n Choice : "))
  31. if source == 1:
  32. path = input("Input file name (must contain 16 char): ")
  33. word = readtext(path)
  34. key = input("Input key : ")
  35. encrpyted = enkripsi(key, word)
  36. print("Encrypted : "+str(encrpyted))
  37. else:
  38. word = input("Input text (must contain 16 char): ")
  39. key = input("Input key : ")
  40. encrpyted = enkripsi(key, word)
  41. print("Encrypted : "+str(encrpyted))
  42. elif choice == 2:
  43. word = input("Input encrypted text: ")
  44. print(word)
  45. key = input("Input key : ")
  46. decrypted = dekripsi(key, word)
  47. print("Decrypted : "+decrypted)
  48. elif choice == 3:
  49. exit()
  50. else:
  51. print("Choose correct choice ")
  52.  
  53.  
  54. if __name__ == "__main__":
  55. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement