dirist.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import msvcrt as m
  2. import os
  3. from os import system
  4. import glob
  5. import hashlib
  6. import sys
  7. from time import sleep
  8. phrase = "phrase.set"
  9. icfile = "key_check.set"
  10. setting = ".set"
  11. extension = ".dovah"
  12. pkey = "hahahaa"
  13. #colors
  14. def prRed(skk): print("\033[91m {}\033[00m" .format(skk))
  15. def prGreen(skk): print("\033[92m {}\033[00m" .format(skk))
  16. def prYellow(skk): print("\033[93m {}\033[00m" .format(skk))
  17. def prLightPurple(skk): print("\033[94m {}\033[00m" .format(skk))
  18. def prPurple(skk): print("\033[95m {}\033[00m" .format(skk))
  19. def prCyan(skk): print("\033[96m {}\033[00m" .format(skk))
  20. def prLightGray(skk): print("\033[97m {}\033[00m" .format(skk))
  21. def prBlack(skk): print("\033[98m {}\033[00m" .format(skk))
  22. def clear(): os.system('cls')
  23. def checkphrase(pkey,key):
  24. #line 178,172 and this for first run
  25. g = open(phrase,"r",encoding="utf-8")
  26. read = g.read()
  27. if encrypt(pkey,key)==read:return 1
  28. else: return 0
  29. g.close()
  30. def header():
  31. intro = """
  32. ______ _____ ___ ______ _____ _____ _____
  33. | _ \\|_ _| / _ \\ | ___ \\|_ _|/ ___||_ _|
  34. | | | | | | / /_\\ \\| |_/ / | | \\ `--. | |
  35. | | | | | | | _ || / | | `--. \\ | |
  36. | |/ / _| |_ | | | || |\\ \\ _| |_ /\\__/ / | |
  37. |___/ \\___/ \\_| |_/\\_| \\_| \\___/ \\____/ \\_/
  38. """
  39. prRed(intro)
  40. prYellow("-By Parewa".rjust(80,' '))
  41. def typewriter(x,time):
  42. for char in x:
  43. sleep(time)
  44. sys.stdout.write(char)
  45. sys.stdout.flush()
  46. def colour(x):
  47. lines = x.split("\n")
  48. for i in range(len(lines)):
  49. if i == 0: prRed(lines[i])
  50. elif i == 1: prYellow(lines[i])
  51. else: print(lines[i])
  52. def hasher(key):
  53. try:
  54. key = key.encode()
  55. x = hashlib.sha224(key).hexdigest()
  56. return(int(str(x),16))
  57. except:
  58. return -1
  59. def encrypt(key,text,dec=1):
  60. if __name__ == '__main__':
  61. encrypted = ""
  62. key = hasher(key)
  63. dupkey = key
  64. for i in range(len(text)):
  65. new = chr(ord(text[i])+ dec*(dupkey%10))
  66. encrypted = encrypted + new
  67. if dupkey==0: dupkey = key
  68. dupkey = int(dupkey/10)
  69. return encrypted
  70. def make(pkey):
  71. clear()
  72. done = 0
  73. prRed("Are you sure?? This can cause alot of damage!!!")
  74. print("> Enter the checkphrase")
  75. ch = input("> ")
  76. if checkphrase(pkey,ch)==1:
  77. for filename in glob.glob("*.txt"):
  78. with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
  79. content = f.read()
  80. rfname = ""
  81. for i in content:
  82. if i!="\n":rfname += i
  83. else: break
  84. rfname = rfname.replace("/","-")
  85. x = encrypt(pkey,content)
  86. g = open(rfname+extension,"w",encoding="utf-8")
  87. g.write(x)
  88. g.close()
  89. try:
  90. f.close() #need to close file to delete
  91. os.remove(filename)
  92. done = 1
  93. except OSError as e:
  94. print(filename,rfname)
  95. prRed("Error! Couldn't Shred: ")
  96. m.getch()
  97. return -1
  98. if done==1:
  99. prGreen("Make successful!!!")
  100. m.getch()
  101. else:
  102. prYellow("Nothing to Make")
  103. m.getch()
  104. else:
  105. prRed("Wrong Password")
  106. m.getch()
  107. def view(pkey):
  108. while True:
  109. clear()
  110. print("Which one?".center(30,'-'))
  111. files = []
  112. i = 0
  113. print((str(i)+". Back").center(5,' '))
  114. for filename in glob.glob("*"+extension):
  115. i += 1
  116. #filename = filename.replace(extension,"")
  117. print((str(i)+". "+filename).center(5,' '))
  118. files.append(filename)
  119. try:
  120. ch = int(input(">"))
  121. if ch==0: break
  122. f = open(files[ch-1],"r",encoding="utf-8")
  123. content = f.read()
  124. x = encrypt(pkey,content,-1)
  125. f.close()
  126. except:
  127. print("No jokes!!!")
  128. return 0
  129. clear()
  130. colour(x)
  131. m.getch()
  132. def keychange(pkey):
  133. success = 0
  134. clear()
  135. header()
  136. prRed("Are you sure?? This causes entire change. Dont foget the key!!!")
  137. print("> Enter Checkphrase")
  138. ch = input("> ")
  139. if checkphrase(pkey,ch)==1:
  140. print("!!!!!!!!!!!!!!")
  141. nkey1 = input("Enter New Key: ")
  142. nkey2 = input("Reenter the Key: ")
  143. nphrase = input("Enter a Checkphrase: ")
  144. if nkey1!=nkey2: return -1
  145. try:
  146. for filename in glob.glob("*"+extension):
  147. with open(os.path.join(os.getcwd(), filename), 'r',encoding="utf-8") as f: # open in readonly mode
  148. content = f.read()
  149. f.close()
  150. x = encrypt(pkey,content,-1)
  151. x = encrypt(nkey1,x)
  152. g = open(filename,"w",encoding="utf-8")
  153. g.write(x)
  154. g.close()
  155. m.getch()
  156. #making new check phrase
  157. g = open(phrase,"w",encoding="utf-8")
  158. g.write(encrypt(pkey,nphrase)) #comment on first run
  159. #g.write(nphrase) #comment on other runs
  160. g.close()
  161. #changing settings file
  162. for filename in glob.glob("*"+setting):
  163. with open(os.path.join(os.getcwd(), filename), 'r',encoding="utf-8") as f: # open in readonly mode
  164. content = f.read()
  165. f.close()
  166. #x = content #comment on later runs
  167. x = encrypt(pkey,content,-1) #comment when first run#
  168. print("Decrypted",x)
  169. x = encrypt(nkey1,x)
  170. print("Encrypted",x)
  171. g = open(filename,"w",encoding="utf-8")
  172. g.write(x)
  173. g.close()
  174. m.getch()
  175. prGreen("Key changed Successfully!!!")
  176. prYellow("Please Restart the app!!!")
  177. m.getch()
  178. return(nkey1)
  179. except:
  180. prRed("Something Went Wrong")
  181. return -1
  182. else:
  183. return -1
  184. def choice():
  185. header()
  186. prRed('Choices'.center(30,'-'))
  187. prYellow("1. Check Key".ljust(30,' '))
  188. prYellow("2. View All".ljust(30,' '))
  189. prYellow("3. Make Enc".ljust(30,' '))
  190. prYellow("4. Key Change".ljust(30,' '))
  191. prYellow("5. Quit".ljust(30,' '))
  192. try:
  193. ch = int(m.getch())
  194. return ch
  195. except:
  196. return -1
  197. def keychecker(key):
  198. f=open(icfile,"r",encoding="utf-8")
  199. pic = f.read()
  200. pic = encrypt(key,pic,-1)
  201. pic = pic.replace("\\","\\\\")
  202. f.close()
  203. print(pic)
  204. m.getch()
  205. def main():
  206. clear()
  207. header()
  208. print("KEYS")
  209. pkey = input()
  210. sleep(1)
  211. while True:
  212. clear()
  213. ch = choice()
  214. if ch==1:keychecker(pkey)
  215. elif ch==2:view(pkey)
  216. elif ch==3: make(pkey)
  217. elif ch==4:
  218. if keychange(pkey)!=-1:break
  219. elif ch==5:break
  220. else: continue
  221. #keychecker()
  222. main()
  223. #print(hasher("hahahaa"))
  224. #make()
  225. #view()
  226. #m.getch()