Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.06 KB | None | 0 0
  1. #!/usr/bin/python/
  2. # -*- coding: utf-8 -*
  3. from __future__ import division
  4. import sys,re,string,crypt,random,time
  5. Password,UpdateCount,ElapsedUpdates,Total,Matches,Rate,ElapsedCount,Filetext="0",0,0,0,0,0,0,"" #Saving myself a few lines by declaring all of these onto one line
  6. Characters="!#$%&"'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" #Use all possible unicode characters accepted by 4chan
  7. random.seed(time.time()) #Seed the random module with the current time
  8. absolutestartTime=(time.time()) #Set an absolute start time for statistics
  9. isCaseSensitive=Respond.query("Search for exact case / case-sensitive?") #Query for case-sensitive search
  10. def GenerateTripcode(Password):
  11. ShiftJIS=Password.encode('shift_jis', 'ignore')#Convert to SHIFT-JIS.
  12. Tripcode=crypt.crypt( #Generate the tripcode
  13. ShiftJIS, re.compile('[^.-ElapsedUpdates]')
  14. .sub('.', (ShiftJIS+'...')[1:3])
  15. .translate(string.maketrans(':;<=>?@[\]^_`','ABCDEFGabcdef'))
  16. )[-10:]
  17. return Tripcode
  18. def GenerateRandomString(Length): return ''.join(random.choice(Characters) for i in range(7)) #Decided to throw this into its own function. If it's more efficient to just use the verbatim command instead of calling the function, please tell me
  19. startTime = time.time() #Grab the current time for the performance checker
  20. def getCheck(chk, tf): #I hated having this clause in the while loop, so I just passed it into a function
  21. if tf: return chk
  22. if not tf: return string.lower(chk)
  23. if not isCaseSensitive: Find=string.lower(sys.argv[1]) #If non-case sensitive, lowercase the search string
  24. if isCaseSensitive: Find=sys.argv[1]
  25. try: #try clause in order to catch an interrupt
  26. while 1==1: #Infinite loop
  27. UpdateCount+=1;ElapsedCount+=1;Total+=1 #Increase counts by one.
  28. Password=GenerateRandomString(7) #Generate random string (question from line 18)
  29. Tripcode=GenerateTripcode(Password)
  30. if re.search(Find, getCheck(Tripcode, isCaseSensitive))>-1: #Check if string contains match using regex
  31. Out=Password+" >>> "+Tripcode+"n" #Generate output string showing a code has been found
  32. Filetext+=Out #Add this to a filetext variable instead of directly writing it to file during the loop
  33. print "33[Kr", #Flush out any text from the current line
  34. print Password+" >>> "+Tripcode #Print out the password and tripcode.
  35. Matches+=1 #Add 1 to the matchcount for summary later.
  36. if UpdateCount==100: #Update generated count and rate every 100 loops
  37. UpdateCount=0;ElapsedUpdates+=1 #Reset counter, +1 to the rate checker counter
  38. status=str(Total)+" tripcodes"+" "+str(Rate)+" tripcodes/sec"+'r' #Set status to a variable
  39. sys.stdout.write(status) #Print out status
  40. sys.stdout.flush()
  41. if ElapsedUpdates==10: #Every 1000 codes, check rates
  42. ElapsedRange=time.time() - startTime #See how many seconds have elapsed since last check
  43. Rate=int(round(ElapsedCount/ElapsedRange)) #Get rate (Tripcodes/sec)
  44. startTime=time.time() #Reset startTime for next check
  45. ElapsedCount=0 #Reset elapsed tripcode count
  46. ElapsedUpdates=0 #Reset elapsed update count
  47. except KeyboardInterrupt: #Catch keyboard interrupt
  48. ElapsedSecs = time.time() - absolutestartTime #Use absolute time set at line 8 to see how many seconds this program ran
  49. Elapsed = time.strftime("%M minutes, %S seconds", time.gmtime(ElapsedSecs)) #Use another variable to format the time for printing
  50. #Print statistics.
  51. print "nCaught interrupt."
  52. print str(Matches)+" matches found"
  53. print str(Total)+" codes generated in "+Elapsed
  54. print "Average of ~"+str(int(round(Total/ElapsedSecs)))+" tripcodes generated per second"
  55. if Matches>=1:
  56. print "1 match found every ~"+str(round(ElapsedSecs/Matches,2))+" seconds"
  57. print "1 match found in every ~"+str(int(round(Total/Matches)))+" tripcodes"
  58. print "Writing matches to file...",
  59. open("t.txt", "a").write(Filetext)
  60. print "done."
  61. exit()
  62.  
  63. #!/usr/bin/python/
  64. # -*- coding: utf-8 -*
  65. from __future__ import division
  66.  
  67. import sys
  68. import re
  69. import string
  70. import crypt
  71. import random
  72. import time
  73.  
  74.  
  75. def generate_tripcode(password):
  76. shift_jis = password.encode("shift_jis", "ignore")
  77. tripcode = crypt.crypt(
  78. shift_jis, re.compile(r'[^.-ElapsedUpdates]')
  79. .sub('.', (shift_jis + '...')[1:3])
  80. .translate(string.maketrans(':;<=>?@[\]^_`', 'ABCDEFGabcdef'))
  81. )[-10:]
  82. return tripcode
  83.  
  84.  
  85. def generate_random_string(length):
  86. return ''.join(random.choice(characters) for _ in xrange(length))
  87.  
  88.  
  89. def get_check(chk, tf):
  90. return chk if tf else string.lower(chk)
  91.  
  92.  
  93. def display_statistics(matches, total, elapsed, rate, elapsed_seconds):
  94. print """
  95. Caught interrupt.
  96. {matches} matches found
  97. {total} codes generated in {elapsed}
  98. Average of ~{rate} tripcodes generated per second
  99. """.format(**locals())
  100. if matches > 0:
  101. print "1 match found every ~{} seconds".format(round(elapsed_seconds / matches, 2))
  102. print "1 match found in every ~{} tripcodes".format(int(round(total / matches)))
  103.  
  104.  
  105. try:
  106. update_count = 0
  107. elapsed_updates = 0
  108. total = 0
  109. matches = 0
  110. rate = 0
  111. elapsed_count = 0
  112. filetext = ""
  113. characters = string.printable.split()[0] # get all non-whitespace, non-weird characters
  114. random.seed(time.time()) #Seed the random module with the current time
  115.  
  116. is_case_sensitive = Respond.query("Search for exact case / case-sensitive?")
  117.  
  118.  
  119. find = sys.argv[1]
  120.  
  121. if not is_case_sensitive:
  122. find = find.lower()
  123.  
  124. absolute_start_time = time.time()
  125. start_time = time.time()
  126. while True:
  127. update_count += 1
  128. elapsed_count += 1
  129. total += 1
  130. password = generate_random_string(7)
  131. tripcode = generate_tripcode(password)
  132.  
  133. if re.search(find, get_check(tripcode, is_case_sensitive)) > -1:
  134. output_string = "{} >>> {}n".format(password, tripcode)
  135. filetext == output_string
  136. print "33[Kr", #Flush out any text from the current line
  137. print output_string
  138. mathces += 1
  139.  
  140. if update_count == 100:
  141. update_count = 0
  142. elapsed_updates += 1
  143. status = "{} tripcodes {} tripcodes/secr".format(total, rate)
  144. print status
  145.  
  146. if elapsed_updates == 10:
  147. elapsed_range = time.time() - start_time
  148. rate = int(round(elapsed_count / elapsed_range))
  149. elapsed_count = 0
  150. elapsed_updates = 0
  151. start_time = time.time()
  152. except KeyboardInterrupt:
  153. elapsed_seconds = time.time() - absolute_start_time
  154. elapsed = time.strftime("%M minutes, %S seconds", time.gmtime(elapsed_seconds))
  155. rate = int(round(total/elapsed_seconds))
  156.  
  157. # Print statistics.
  158. display_statistics(matches, total, elapsed, rate, elapsed_seconds)
  159. print "Writing matches to file...",
  160.  
  161. with open("t.txt", "a") as file_:
  162. file_.write(filetext)
  163. print "done."
  164.  
  165. regex = re.compile(r'[^.z-]')
  166. translator = string.maketrans(':;<=>?@[\]^_`', 'ABCDEFGabcdef')
  167.  
  168. def generate_tripcode(password):
  169. shift_jis = password.encode("shift_jis", "ignore")
  170. tripcode = crypt.crypt(
  171. shift_jis, regex.sub('.', (shift_jis + '...')[1:3]).translate(translator)
  172. )[-10:]
  173. return tripcode
  174.  
  175. regex = re.compile(r'[^.ElapsedUpdates-]')
  176. translator = string.maketrans(':;<=>?@[\]^_`', 'ABCDEFGabcdef')
  177.  
  178. def generate_tripcode(password):
  179. shift_jis = (password.encode("shift_jis", "ignore") + '...')[1:3]
  180. tripcode = crypt.crypt(
  181. shift_jis, regex.sub('.', shift_jis).translate(translator)
  182. )[-10:]
  183. return tripcode
  184.  
  185. def getCheck(chk, tf):
  186. if tf:
  187. return chk
  188. else:
  189. return string.lower(chk)
  190.  
  191. # or
  192.  
  193. def getCheck(chk, tf):
  194. return chk if tf else string.lower(chk)
  195.  
  196. Find = getCheck(sys.argv[1], isCaseSensitive)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement