Loading...
More Python Posts
import itertoolsimport stringimport timedef guess_password(real):chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuationattempts = 0for password_length in range(1, 9):for guess in itertools.product(chars, repeat=password_length):startTime = time.time()attempts += 1guess = ''.join(guess)if guess == real:return 'password is {}. found in {} guesses.'.format(guess, attempts)loopTime = (time.time() - startTime);print(guess, attempts, loopTime)print("\nIt will take A REALLY LONG TIME to crack a long password. Try this out with a 3 or 4 letter password and see how this program works.\n")val = input("Enter a password you want to crack that is 9 characters or below: ")print(guess_password(val.lower()))
from math import pidef rads_to_degrees(rad):return (rad * 180.0) / pirads_to_degrees(pi / 2) # 90.0
# Function to multiply two matricesdef multiply_matrices(matrix1, matrix2):# Check if the matrices can be multipliedif len(matrix1[0]) != len(matrix2):print("Error: The number of columns in the first matrix must be equal to the number of rows in the second matrix.")return None# Create the result matrix filled with zerosresult = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))]# Perform matrix multiplicationfor i in range(len(matrix1)):for j in range(len(matrix2[0])):for k in range(len(matrix2)):result[i][j] += matrix1[i][k] * matrix2[k][j]return result# Example matricesmatrix1 = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]matrix2 = [[10, 11],[12, 13],[14, 15]]# Multiply the matricesresult_matrix = multiply_matrices(matrix1, matrix2)# Display the resultif result_matrix is not None:print("Result:")for row in result_matrix:print(row)
import stringdef caesar(text, shift, alphabets):def shift_alphabet(alphabet):return alphabet[shift:] + alphabet[:shift]shifted_alphabets = tuple(map(shift_alphabet, alphabets))final_alphabet = "".join(alphabets)final_shifted_alphabet = "".join(shifted_alphabets)table = str.maketrans(final_alphabet, final_shifted_alphabet)return text.translate(table)plain_text = "Hey Skrome, welcome to CodeCatch"print(caesar(plain_text, 8, [string.ascii_lowercase, string.ascii_uppercase, string.punctuation]))
import itertoolsdef compute_permutations(string):# Generate all permutations of the stringpermutations = itertools.permutations(string)# Convert each permutation tuple to a stringpermutations = [''.join(permutation) for permutation in permutations]return permutations# Prompt the user for a stringstring = input("Enter a string: ")# Compute permutationspermutations = compute_permutations(string)# Display the permutationsprint("Permutations:")for permutation in permutations:print(permutation)
import osimport sysimport argparseimport jsonimport csvimport getpassimport stringimport randomimport refrom datetime import datetimeimport ldapimport requestsfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)from requests.auth import HTTPBasicAuthimport validatorsdef create_guac_connection(BASE_URL, auth_token, ldap_group, computer, guac_group_id):'''creates a guac connection'''json_header = {'Accept': 'application/json'}query_parm_payload = { 'token': auth_token }payload_data = {"parentIdentifier":guac_group_id,"name":computer,"protocol":"vnc","parameters":{"port":"5900","read-only":"","swap-red-blue":"","cursor":"","color-depth":"","clipboard-encoding":"","disable-copy":"","disable-paste":"","dest-port":"","recording-exclude-output":"","recording-exclude-mouse":"","recording-include-keys":"","create-recording-path":"","enable-sftp":"true","sftp-port":"","sftp-server-alive-interval":"","enable-audio":"","audio-servername":"","sftp-directory":"","sftp-root-directory":"","sftp-passphrase":"","sftp-private-key":"","sftp-username":"","sftp-password":"","sftp-host-key":"","sftp-hostname":"","recording-name":"","recording-path":"","dest-host":"","password":"asdasd","username":"asdasd","hostname":"nt72310.cvad.unt.edu"},"attributes":{"max-connections":"","max-connections-per-user":"1","weight":"","failover-only":"","guacd-port":"","guacd-encryption":"","guacd-hostname":""}}CREATE_CONNECTION_URL = BASE_URL + "/api/session/data/mysql/connections"create_connection_request = requests.post(CREATE_CONNECTION_URL, headers=json_header, params=query_parm_payload, data=payload_data, verify=False)create_connection_result = create_connection_request.status_codeif create_connection_result == "200":print("Successfully created computer: " + computer)else:print(create_connection_request.json())return create_connection_result