Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import string
  2. import random
  3. import time
  4.  
  5. possibleCharacters = string.ascii_lowercase + string.digits + string.ascii_uppercase + ' .,!?;:'
  6.  
  7. target = input("Enter your target text: ")
  8. attemptThis = ''.join(random.choice(possibleCharacters) for i in range(len(target)))
  9. attemptNext = ''
  10.  
  11. completed = False
  12.  
  13. generation = 0
  14.  
  15. while completed == False:
  16.     print(attemptThis)
  17.     attemptNext = ''
  18.     completed = True
  19.     for i in range(len(target)):
  20.         if attemptThis[i] != target[i]:
  21.             completed = False
  22.             attemptNext += random.choice(possibleCharacters)
  23.         else:
  24.             attemptNext += target[i]
  25.     generation += 1
  26.     attemptThis = attemptNext
  27.     time.sleep(0.1)
  28.  
  29. print("Target matched! That took " + str(generation) + " generation(s)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement