def test_raise_exception_if_object_is_not_a_string(self): with self.assertRaises(TypeError) as raised: # noinspection PyTypeChecker shuffle(None) self.assertEqual(str(raised.exception), 'Expected "str", received "NoneType"') with self.assertRaises(TypeError) as raised: # noinspection PyTypeChecker shuffle(False) self.assertEqual(str(raised.exception), 'Expected "str", received "bool"') with self.assertRaises(TypeError) as raised: # noinspection PyTypeChecker shuffle(0) self.assertEqual(str(raised.exception), 'Expected "str", received "int"') with self.assertRaises(TypeError) as raised: # noinspection PyTypeChecker shuffle([]) self.assertEqual(str(raised.exception), 'Expected "str", received "list"') with self.assertRaises(TypeError) as raised: # noinspection PyTypeChecker shuffle({'a': 1}) self.assertEqual(str(raised.exception), 'Expected "str", received "dict"')
def render_response(): if request.method == 'POST': name = request.form['color'] password = string_utils.shuffle(name) + "3000" #The request object stores information about the request sent to the server. #args is an ImmutableMultiDict (like a dictionary but can have mutliple values for the same key and can't be changed) #The information in args is visible in the url for the page being requested. ex. .../response?color=blue return render_template('response.html',response = password)
def encrypt_sha256(hash_string): sha_signature = hashlib.sha256(hash_string.encode()).hexdigest() # print ("Original>>>>:", hash_string) # print ("SH256>>>>>>>:", sha_signature) sha_signature = string_utils.shuffle(sha_signature) # print ("Suffled>>>>>:", sha_signature) return sha_signature
def gen_password(): lower_case_pass = ''.join(random.choice(lower_case) for i in range(length)) upper_case_pass = ''.join(random.choice(upper_case) for i in range(length)) numbers = ''.join(map(str, random.sample(range(1, 9), length))) characters = ''.join(random.choice(symbols) for i in range(length)) auto_password = lower_case_pass + upper_case_pass + numbers + characters password = string_utils.shuffle(auto_password) print(f"\nYour auto generated password is: {password}") return password
def createFirstGeneration(self, n=POPULATION_SIZE): self.populationSize = n firstGeneration = set() i = 0 while (i != n): newChromosome = string_utils.shuffle(self.chars) if (newChromosome not in firstGeneration): i += 1 firstGeneration.add(newChromosome) self.population = list(firstGeneration) self.allGenerations = [firstGeneration]
def gen_password(): lower_case = string.ascii_lowercase upper_case = string.ascii_uppercase symbols = string.punctuation length = 4 lower_case_pass = ''.join(random.choice(lower_case) for i in range(length)) upper_case_pass = ''.join(random.choice(upper_case) for i in range(length)) numbers = ''.join(map(str, random.sample(range(1, 9), length))) characters = ''.join(random.choice(symbols) for i in range(length)) auto_password = lower_case_pass + upper_case_pass + numbers + characters password = string_utils.shuffle(auto_password) return password
def student_exam_card(request): context = {} try: profile_attr = StudentProfileAttribute.objects.get(profile_id = request.user.studentprofile.id) units = Unit.objects.filter(program = profile_attr.program) programs = Program.objects.get(id = profile_attr.program) studentUnit_qs = StudentUnit.objects.filter(student_id = request.user.studentprofile.id) context['programs'] = programs exam_card_number = string_utils.shuffle(request.user.studentprofile.adm_number) try: obj = ExamCardNumber.objects.get( profile_id = request.user.studentprofile.id, semester = profile_attr.student_session, accademic_year = profile_attr.accademic_year ) context['exam_card_number'] = obj.number except ExamCardNumber.DoesNotExist: new_values = {} new_values.update( profile_id = request.user.studentprofile.id, number = exam_card_number, semester = profile_attr.student_session, accademic_year = profile_attr.accademic_year ) obj = ExamCardNumber(**new_values) obj.save() context['exam_card_number'] = exam_card_number fullname = f'{request.user.studentprofile.first_name} {request.user.studentprofile.surname} {request.user.studentprofile.last_name}' qr_metadata = f'{exam_card_number} {fullname} {request.user.studentprofile.adm_number}' context['profile_attr'] = profile_attr context['units'] = units context['studentUnit_qs'] = studentUnit_qs context['my_options'] = qr_metadata except ObjectDoesNotExist: messages.warning(request, f'Register Your Department {request.user.username}') return redirect('student:student_profile_attribute') return render(request, 'pages/examcard.html', context)
def generate_string(self, amount_of_lower, amount_of_upper=0, amount_of_digits=0, amount_of_special=0): letters_to_use = [ ''.join( random.choice(self.upper_letters_list) for x in range(amount_of_upper)), ''.join( random.choice(self.lower_letters_list) for x in range(amount_of_lower)), ''.join( random.choice(self.digits_list) for x in range(amount_of_digits)), ''.join( random.choice(self.special_characters_list) for x in range(amount_of_special)) ] letters_to_use_str = "".join(letters_to_use) return string_utils.shuffle(letters_to_use_str)
def generate_password(): string_small="abcdefghijklmnopqrstuvwxyz" string_upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ" string_number="1234567890" string_character="!@#$%^&*()_" app_data=str(input("for which app do you need the password for")) password="" for len in range(4): password=password+random.choice(string_small) for len in range(4): password=password+random.choice(string_upper) for len in range(4): password=password+random.choice(string_number) for len in range(4): password=password+random.choice(string_character) password=string_utils.shuffle(password) print("your password is "+ password + " for the app " + app_data) insert_db=("INSERT INTO passwordapp(app,password)" "VALUES(%s, %s)" ) dt=(app_data,password) try: mycursor.execute(insert_db,dt) mydb.commit() except: mydb.rollback() print("data inserted") mydb.close()
def otp_send(request, number): check_login = login(request) response_data = {} if check_login == True: len_number = len(str(number)) if len_number == 10: setting_obj = settings[0] email = check_account(request, setting_obj.salt) otp = string_utils.shuffle("54789") get_user = student_user.objects.get(email=email) get_user.otp = otp get_user.phone_no = number get_user.save() msg = "You OTP for phone verification is " + otp send = send_sms(msg, number, "RJITAC") if send: response_data['status'] = True response_data['ntt'] = "success" response_data['msg'] = "OTP Sent to " + str(number) else: response_data['status'] = False response_data['ntt'] = "warning" response_data[ 'msg'] = "Please enter a valid phone number without +91" else: response_data['status'] = False response_data['ntt'] = "error" response_data['msg'] = "Invalid action" return HttpResponse(json.dumps(response_data), content_type="application/json")
# Password Generater import string_utils # this module is for shuffling the passwords userChars = input("Enter the characters you want in your password : "******"How many passwords do you want to generate : ")) passwordLength = input("Enter the length of your passwords : ") if passwordLength == "" or int(passwordLength) > len(userChars): passwordLength = len(userChars) else: passwordLength = int(passwordLength) # Generate the password for x in range(0,userPasswords): password = "" password = string_utils.shuffle(userChars) # this shuffles userChar passwordList = [] passwordList[:0] = password # print(passwordList) optional password = "" number = 0 for i in passwordList: if number >= passwordLength: break password += i number += 1 print(password) # this prints the password
words = lines.split() digits = str(random.randint(10, 99)) #Generate random 2 digit number word = random.choice( words) #Randomly chooses word from list of over 5000 6 letter words password = (word + digits) #Concatenates word and numbers else: halfChar = int(randChar / 2) word = "".join( (random.choices(letters, k=halfChar) )) #Chooses random letters in the amount of half the password length num = "".join( (random.choices(numbers, k=halfChar) )) #Chooses random numbers in the amount of half the password length str(num) passJoin = word + num #Concatenates letters and numbers to one string password = string_utils.shuffle( passJoin) #Shuffles new string to create password #Output credentials to passwords.txt file f = open("passwords.txt", "a+") f.write("Site: ") f.write(site + "\n") f.write("Username: "******"\n") f.write("Password: "******"\n") f.write("\n\n") f.close() #Copy password to clipboard pyperclip.copy(password)
def test_original_string_is_not_modified(self): shuffle(self.original_string) self.assertEqual(self.original_string, 'Hello World!')
def test_shuffle_generates_new_string_for_each_call(self): self.assertNotEqual(shuffle(self.original_string), shuffle(self.original_string))
def test_shuffled_string_should_be_different_from_original_one(self): self.assertNotEqual(self.original_string, shuffle(self.original_string))
''' 47-Randomly shuffle string Steve Shambles Jan 2019 https://stevepython.wordpress.com You may need to: "pip install python-string-utils" ''' import string_utils OUT_COME = "12345" # Randomly shuffle "OUT_COME" string. SHUFF = (string_utils.shuffle(OUT_COME)) # Display shuffled up string, note that original # string still intact in "OUT_COME". print(SHUFF)
if args.match: # Process provided match file qMatch, rMatch = read(args.match, match=True) # Perform Needleman-Wunsch algorithm (anchored) alignQ, alignR, score = anchored_nw(q, r, qMatch, rMatch) # No match file provided else: # Perform random permutation experiment if args.permute: # List of scores for all experiment runs scoreList = [] # Execute experiment 10,000 times for i in range(10001): # Generate random permutation of amino acids in provided sequences qRand = string.shuffle(q) rRand = string.shuffle(r) # Create similarity matrix based on random permutation V = create_matrix(qRand, rRand) # Perform Needleman-Wunsch alignment on random permutation alignQ, alignR, score = needleman_wunsch(V, qRand, rRand) # Add score to list for histogram scoreList.append(score) # Generate histogram of scores plt.title('Score Histogram (Random Permutations)') plt.hist(scoreList, 10,
def get_random_car_number(): number = "ABCDEFGHIJKLMNOPRSTUVWXYZ0123456789" number = string_utils.shuffle(number) return number[:5]
def signup(request): #email = EmailMessage('Subject', 'Body', to=['*****@*****.**']) #email.send() if request.method == 'POST': first_name = request.POST['first_name'] last_name = request.POST['last_name'] email = request.POST['email'] phone_no = request.POST['phone_no'] password = request.POST['password'] confirm = request.POST['confirm'] if first_name != '' and last_name != '' and email != '' and phone_no != '' and password != '' and confirm != '': if password == confirm: #sms = send_sms("test", "9685925522", "RJITAC") #print(sms) signer = Signer(settings[0].salt) sign_pwd = signer.sign(password) check_email = student_user.objects.filter(email=email).count() check_phone = student_user.objects.filter( phone_no=phone_no).count() email_hash = string_utils.shuffle( "IHAGFDGJHfhjdfj7863pcdrkjoopkphjkhdsafjhdsfg78367365874") otp = string_utils.shuffle("54789") if check_email == 0 and check_phone == 0: obj, insert_user = student_user.objects.get_or_create( first_name=first_name, last_name=last_name, email=email, phone_no=phone_no, password=sign_pwd, account_status='Active', email_hash=email_hash, otp=otp, phone_status='Not Verified', email_status='Not Verified') insert = student_academic.objects.create( student_email=email, student_id_id=obj.id, branch='', semester='0', batch='', profile='/media/avatar.png', subject_preference='', goal='') insert = student_dashboard_metrices.objects.create( student_id_id=obj.id, college_level_rank="0", class_level_rank="0", student_email=email) if insert: msg = "You otp for phone verifiaction is " + otp body = "here is your link to verify you email is <a href='http://" + request.get_host( ) + "/student/verify_email/" + obj.email_hash + "'> " + request.get_host( ) + "/student/activate/" + obj.email_hash + " </a>" email = EmailMessage( subject='Verify email - Top Academy', body=body, from_email=settings[0].smtp_email, to=[email], connection=email_connect) email.content_subtype = "html" email.send() send = send_sms(msg, phone_no, "RJITAC") #print(send) messages.success( request, "Your account has been succesfully created please login and verify you email and phone number." ) else: messages.warning( request, "Email or Phone No. is already exist in our record, Please Login" ) #insert = student_user.objects.create() else: messages.warning(request, "Password doe not match") return render(request, "student_html/signup.html")
def test_shuffled_string_should_have_same_len_of_original_one(self): shuffled = shuffle(self.original_string) self.assertTrue(len(self.original_string), len(shuffled))
def test_sorted_strings_should_match(self): shuffled = shuffle(self.original_string) self.assertEqual(sorted(self.original_string), sorted(shuffled))