Ingin menangid
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9 KiB

5 years ago
  1. #!/usr/bin/python2.7
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import random
  5. import base64
  6. def banner():
  7. return '''
  8. Welcome to our brand new crypto service
  9. ________ _______ __ __ ____________ ______ __________ _____ __________ _ __________________
  10. / ____/ //_/ ___// //_/ / ____/ __ \ \/ / __ \/_ __/ __ \ / ___// ____/ __ \ | / / _/ ____/ ____/
  11. / / __/ ,< \__ \/ ,< / / / /_/ /\ / /_/ / / / / / / / \__ \/ __/ / /_/ / | / // // / / __/
  12. / /_/ / /| |___/ / /| | / /___/ _, _/ / / ____/ / / / /_/ / ___/ / /___/ _, _/| |/ // // /___/ /___
  13. \____/_/ |_/____/_/ |_| \____/_/ |_| /_/_/ /_/ \____/ /____/_____/_/ |_| |___/___/\____/_____/
  14. version [v2.1.19]
  15. '''
  16. def print_usage(script_argv):
  17. print '[==USAGE==]\n'
  18. print 'Encrypt File \t: %s -e [plaintext_file] [key]' % script_argv
  19. print 'Decrypt File \t: %s -d [encrypted_file] [key]' % script_argv
  20. print 'Generate Key \t: %s -g' % script_argv
  21. print 'Help \t\t: %s -h\n' % script_argv
  22. def shift_key():
  23. key = random.randint(0x1, 0xff)
  24. return key
  25. def shuffle_secret():
  26. secret_out = ''
  27. secret_str = ''.join('gksk-secret-code'.split('-'))
  28. for count,loop in enumerate(secret_str):
  29. if count % 2 == 0:
  30. secret_out += ''.join([chr(ord(ch) + 0x3) for ch in loop])
  31. else:
  32. secret_out += loop
  33. return secret_out
  34. def encryption(plain, shift):
  35. try:
  36. ciphertext = ''
  37. length_msg = 50
  38. with open(plain, 'rb') as bin:
  39. data = bin.read()
  40. shift = int(shift)
  41. alphabet = shuffle_secret() * length_msg
  42. shifted_alphabet = alphabet[shift:] + alphabet[:shift]
  43. for a, b in zip(data, shifted_alphabet):
  44. ciphertext += chr(ord(a) + ord(b) ^ shift)
  45. with open(plain + '.enc', 'wb') as bin:
  46. bin.write(base64.b64encode(ciphertext))
  47. except ValueError:
  48. print "ValueError : Range key [0-255]"
  49. exit()
  50. def decryption(enc_file, key):
  51. with open(enc_file, 'rb') as bin:
  52. data = bin.read()
  53. '''NOT IMPLEMENTED YET'''
  54. with open(enc_file + '.trial', 'wb') as bin:
  55. bin.write(data)
  56. def main():
  57. print banner()
  58. script_argv = sys.argv[0]
  59. try:
  60. mode = sys.argv[1]
  61. if mode == '-e':
  62. plaintext_file = sys.argv[2]
  63. key = sys.argv[3]
  64. encryption(plaintext_file, key)
  65. print "\nSECRET KEY : ", shuffle_secret()
  66. print '\nThankyou for using our service :)\n'
  67. elif mode == '-d':
  68. encrypted_file = sys.argv[2]
  69. key = sys.argv[3]
  70. decryption(encrypted_file, key)
  71. print '\nNot implemented yet. Upgrade to premium, only $99999\n'
  72. elif mode == '-g':
  73. print 'Key : ', shift_key()
  74. elif mode == '-h':
  75. print_usage(script_argv)
  76. else:
  77. print_usage(script_argv)
  78. except IndexError:
  79. print_usage(script_argv)
  80. if __name__ == '__main__':
  81. main()