-
Notifications
You must be signed in to change notification settings - Fork 4
/
singleTransform.py
61 lines (52 loc) · 1.82 KB
/
singleTransform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
##############################################################
## This program takes a string as input (a password) and ##
## permutes the password. ##
##############################################################
# How to use: ./programName.py [password_string] ##
# Example: ./transform.py ABCabc123!!! ##
# Note: Ensure the #!/location/to/python is correct ##
# Note: Make sure to chmod a+x [filename] on your system ##
# Note: Some characters such as the ' and ; interact with ##
# the shell and don't permute properly. Passing it in as ##
# a file containing the password makes it perform better ##
##############################################################
import sys
import timeit
import re
# take in an argument from the command line
password = sys.argv[1]
# Create arrays to hold characters
lowerArray = []
upperArray = []
digitArray = []
symbolArray = []
# This is the heart of the script
## Runs through each character of a string and
## places it into an array
def charSwap(text):
upper = lower = digit = space = 0
for c in text:
if c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
upper += 1
upperArray.append(c)
elif c in "abcdefghijklmnopqrstuvwxyz":
lower += 1
lowerArray.append(c)
elif c in "0123456789":
digit += 1
digitArray.append(c)
else :
symbolArray.append(c)
return (upper, lower, digit, space)
# Call the primary function
charSwap(str(password))
# .join merges characters from an array into a string
tempUpperPass = ''.join(upperArray)
tempLowerPass = ''.join(lowerArray)
tempDigitPass = ''.join(digitArray)
tempSymbolPass = ''.join(symbolArray)
# Concatenate all the strings
newPass = tempUpperPass + tempLowerPass + tempDigitPass + tempSymbolPass
# print result
print newPass